[telepathy-gabble/telepathy-gabble-0.8] test-avatar-async.py: new test cases to prevent recursive conflict resolution
Alban Crequy
alban.crequy at collabora.co.uk
Thu Oct 1 04:11:03 PDT 2009
---
tests/twisted/gabbletest.py | 8 +++++-
tests/twisted/vcard/test-avatar-async.py | 44 +++++++++++++++++++++++++++++-
2 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/tests/twisted/gabbletest.py b/tests/twisted/gabbletest.py
index 10ae742..13fa8ff 100644
--- a/tests/twisted/gabbletest.py
+++ b/tests/twisted/gabbletest.py
@@ -485,7 +485,7 @@ def elem_iq(server, type, **kw):
return iq
def make_presence(_from, to='test at localhost', type=None, show=None,
- status=None, caps=None):
+ status=None, caps=None, photo=None):
presence = domish.Element((None, 'presence'))
presence['from'] = _from
presence['to'] = to
@@ -504,6 +504,12 @@ def make_presence(_from, to='test at localhost', type=None, show=None,
for key,value in caps.items():
cel[key] = value
+ # <x xmlns="vcard-temp:x:update"><photo>4a1...</photo></x>
+ if photo is not None:
+ x = presence.addElement(('vcard-temp:x:update', 'x'))
+ if photo != "":
+ x.addElement('photo').addContent(photo)
+
return presence
def expect_list_channel(q, bus, conn, name, contacts, lp_contacts=[],
diff --git a/tests/twisted/vcard/test-avatar-async.py b/tests/twisted/vcard/test-avatar-async.py
index 05c3a88..8d30acc 100644
--- a/tests/twisted/vcard/test-avatar-async.py
+++ b/tests/twisted/vcard/test-avatar-async.py
@@ -9,7 +9,7 @@ import hashlib
from twisted.words.xish import domish
from servicetest import EventPattern, sync_dbus, assertEquals
from gabbletest import (exec_test, acknowledge_iq, make_result_iq,
- sync_stream, send_error_reply)
+ sync_stream, send_error_reply, make_presence)
import constants as cs
import ns
@@ -112,5 +112,47 @@ def test(q, bus, conn, stream):
assertEquals('hello', event.args[2])
assertEquals('image/png', event.args[3])
+ # Test with our own avatar test at localhost/Resource2
+ self_handle = conn.GetSelfHandle()
+ presence_stanza = make_presence('test at localhost/Resource2',
+ to='test at localhost/Resource',
+ show='away', status='At the pub',
+ photo=hashlib.sha1(':-D').hexdigest())
+ stream.send(presence_stanza)
+ iq_event = q.expect('stream-iq', to=None, query_ns='vcard-temp',
+ query_name='vCard')
+ iq = make_result_iq(stream, iq_event.stanza)
+ vcard = iq.firstChildElement()
+ photo = vcard.addElement('PHOTO')
+ photo.addElement('TYPE', content='image/png')
+ photo.addElement('BINVAL', content=base64.b64encode(':-D'))
+
+ # do not send the vCard reply now. First, send another presence.
+ q.forbid_events([avatar_request_event])
+ stream.send(presence_stanza)
+ sync_stream(q, stream)
+
+ # Now send the reply.
+ stream.send(iq)
+ # So Gabble has the right hash, and no need to ask the vCard again
+ stream.send(presence_stanza)
+ sync_stream(q, stream)
+ q.unforbid_events([avatar_request_event])
+
+ # But if the hash is different, the vCard is asked again
+ presence_stanza = make_presence('test at localhost/Resource2',
+ to='test at localhost/Resource',
+ show='away', status='At the pub',
+ photo=hashlib.sha1('\o/').hexdigest())
+ stream.send(presence_stanza)
+ iq_event = q.expect('stream-iq', to=None, query_ns='vcard-temp',
+ query_name='vCard')
+ iq = make_result_iq(stream, iq_event.stanza)
+ vcard = iq.firstChildElement()
+ photo = vcard.addElement('PHOTO')
+ photo.addElement('TYPE', content='image/png')
+ photo.addElement('BINVAL', content=base64.b64encode('\o/'))
+ stream.send(iq)
+
if __name__ == '__main__':
exec_test(test)
--
1.5.6.5
More information about the telepathy-commits
mailing list