[telepathy-gabble/master] Stop reimplementing make_presence quite so frequently

Will Thompson will.thompson at collabora.co.uk
Thu Sep 10 07:07:12 PDT 2009


The tubes and FT tests still reimplement it, but when I tried to fix
them they broke, and I ran away.
---
 tests/twisted/caps/caps-cache.py      |   28 ++++++---------
 tests/twisted/caps/hashed-caps.py     |   60 ++++++++++++++++----------------
 tests/twisted/caps/receive-jingle.py  |   20 ++++++-----
 tests/twisted/text/test-chat-state.py |    9 +++--
 4 files changed, 58 insertions(+), 59 deletions(-)

diff --git a/tests/twisted/caps/caps-cache.py b/tests/twisted/caps/caps-cache.py
index b78d6ab..b7393af 100644
--- a/tests/twisted/caps/caps-cache.py
+++ b/tests/twisted/caps/caps-cache.py
@@ -13,14 +13,6 @@ from caps_helper import (
     compute_caps_hash, make_caps_disco_reply, fake_client_dataforms,
     )
 
-def presence_add_caps(presence, ver, client, hash=None):
-    c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
-    c['node'] = client
-    c['ver'] = ver
-    if hash is not None:
-        c['hash'] = hash
-    return presence
-
 def _test_without_hash(q, bus, conn, stream, contact, client, disco):
     contact_handle = conn.RequestHandles(cs.HT_CONTACT, [contact])[0]
     presence = make_presence(contact, status='hello')
@@ -40,8 +32,10 @@ def _test_without_hash(q, bus, conn, stream, contact, client, disco):
     assert conn.Capabilities.GetCapabilities([contact_handle]) == basic_caps
 
     # send updated presence with Jingle caps info
-    presence = make_presence(contact, status='hello')
-    presence = presence_add_caps(presence, '0.1', client)
+    presence = make_presence(contact, status='hello',
+        caps={ 'node': client,
+               'ver':  '0.1',
+             })
     stream.send(presence)
 
     if disco:
@@ -87,11 +81,13 @@ def _test_with_hash(q, bus, conn, stream, contact, client, disco):
         ]
 
     # send updated presence with Jingle caps info
-    presence = make_presence(contact, status='hello')
-    c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
-    c['node'] = client
-    c['ver'] = compute_caps_hash([], features, fake_client_dataforms)
-    c['hash'] = 'sha-1'
+    ver = compute_caps_hash([], features, fake_client_dataforms)
+    caps = {
+        'node': client,
+        'ver':  ver,
+        'hash': 'sha-1',
+        }
+    presence = make_presence(contact, status='hello', caps=caps)
     stream.send(presence)
 
     if disco:
@@ -100,7 +96,7 @@ def _test_with_hash(q, bus, conn, stream, contact, client, disco):
             query_ns='http://jabber.org/protocol/disco#info')
         query_node = xpath.queryForNodes('/iq/query', event.stanza)[0]
         assert query_node.attributes['node'] == \
-            client + '#' + c['ver']
+            client + '#' + ver
 
         # send good reply
         result = make_caps_disco_reply(stream, event.stanza, features,
diff --git a/tests/twisted/caps/hashed-caps.py b/tests/twisted/caps/hashed-caps.py
index 15267a2..206acdd 100644
--- a/tests/twisted/caps/hashed-caps.py
+++ b/tests/twisted/caps/hashed-caps.py
@@ -40,14 +40,6 @@ def caps_changed_cb(dummy):
     global caps_changed_flag
     caps_changed_flag = True
 
-def presence_add_caps(presence, ver, client, hash=None):
-    c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
-    c['node'] = client
-    c['ver'] = ver
-    if hash is not None:
-        c['hash'] = hash
-    return presence
-
 def test_hash(q, bus, conn, stream, contact, contact_handle, client):
     global caps_changed_flag
 
@@ -67,8 +59,10 @@ def test_hash(q, bus, conn, stream, contact, contact_handle, client):
     assert conn.Capabilities.GetCapabilities([contact_handle]) == basic_caps
 
     # send updated presence with Jingle caps info
-    presence = make_presence(contact, status='hello')
-    presence = presence_add_caps(presence, '0.1', client)
+    presence = make_presence(contact, status='hello',
+        caps={'node': client,
+              'ver':  '0.1',
+             })
     stream.send(presence)
 
     # Gabble looks up our capabilities
@@ -90,11 +84,12 @@ def test_hash(q, bus, conn, stream, contact, contact_handle, client):
     caps_changed_flag = False
 
     # send bogus presence
-    presence = make_presence(contact, status='hello')
-    c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
-    c['node'] = client
-    c['ver'] = 'ceci=nest=pas=un=hash'
-    c['hash'] = 'sha-1'
+    caps = {
+        'node': client,
+        'ver':  'ceci=nest=pas=un=hash',
+        'hash': 'sha-1',
+        }
+    presence = make_presence(contact, status='hello', caps=caps)
     stream.send(presence)
 
     # Gabble looks up our capabilities
@@ -102,7 +97,7 @@ def test_hash(q, bus, conn, stream, contact, contact_handle, client):
         query_ns='http://jabber.org/protocol/disco#info')
     query_node = xpath.queryForNodes('/iq/query', event.stanza)[0]
     assert query_node.attributes['node'] == \
-        client + '#' + c['ver']
+        client + '#' + caps['ver']
 
     # send bogus reply
     stream.send(make_caps_disco_reply(stream, event.stanza,
@@ -115,8 +110,10 @@ def test_hash(q, bus, conn, stream, contact, contact_handle, client):
 
 
     # send presence with empty caps
-    presence = make_presence(contact, status='hello')
-    presence = presence_add_caps(presence, '0.0', client)
+    presence = make_presence(contact, status='hello',
+        caps={'node': client,
+              'ver':  '0.0',
+             })
     stream.send(presence)
 
     # Gabble looks up our capabilities
@@ -148,11 +145,13 @@ def test_hash(q, bus, conn, stream, contact, contact_handle, client):
         'http://www.google.com/transport/p2p',
         ]
 
-    presence = make_presence(contact, status='hello')
-    c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
-    c['node'] = client
-    c['ver'] = compute_caps_hash([], features, fake_client_dataforms)
-    c['hash'] = 'sha-1'
+    ver = compute_caps_hash([], features, fake_client_dataforms)
+    caps = {
+        'node': client,
+        'ver':  ver,
+        'hash': 'sha-1',
+        }
+    presence = make_presence(contact, status='hello', caps=caps)
     stream.send(presence)
 
     # Gabble looks up our capabilities
@@ -160,7 +159,7 @@ def test_hash(q, bus, conn, stream, contact, contact_handle, client):
         query_ns='http://jabber.org/protocol/disco#info')
     query_node = xpath.queryForNodes('/iq/query', event.stanza)[0]
     assert query_node.attributes['node'] == \
-        client + '#' + c['ver']
+        client + '#' + caps['ver']
 
     # don't receive any D-Bus signal
     sync_dbus(bus, q, conn)
@@ -210,19 +209,20 @@ def test_two_clients(q, bus, conn, stream, contact1, contact2,
     assert conn.Capabilities.GetCapabilities([contact_handle2]) == basic_caps
 
     # send updated presence with Jingle caps info
-    presence = make_presence(contact1, status='hello')
     features = [
         'http://jabber.org/protocol/jingle',
         'http://jabber.org/protocol/jingle/description/audio',
         'http://www.google.com/transport/p2p',
         ]
     ver = compute_caps_hash([], features, {})
-    presence = presence_add_caps(presence, ver, client,
-            hash='sha-1')
+    caps = {
+        'node': client,
+        'ver': ver,
+        'hash': 'sha-1',
+        }
+    presence = make_presence(contact1, status='hello', caps=caps)
     stream.send(presence)
-    presence = make_presence(contact2, status='hello')
-    presence = presence_add_caps(presence, ver, client,
-            hash='sha-1')
+    presence = make_presence(contact2, status='hello', caps=caps)
     stream.send(presence)
 
     # Gabble looks up our capabilities
diff --git a/tests/twisted/caps/receive-jingle.py b/tests/twisted/caps/receive-jingle.py
index c1e2fe0..498ccd2 100644
--- a/tests/twisted/caps/receive-jingle.py
+++ b/tests/twisted/caps/receive-jingle.py
@@ -35,11 +35,12 @@ def test(q, bus, conn, stream):
     # send updated presence with Jingle audio/video caps info. we turn on both
     # audio and video at the same time to test that all of the capabilities are
     # discovered before any capabilities change signal is emitted
-    presence = make_presence('bob at foo.com/Foo', status='hello')
-    c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
-    c['node'] = 'http://telepathy.freedesktop.org/fake-client'
-    c['ver'] = '0.1'
-    c['ext'] = 'video'
+    presence = make_presence('bob at foo.com/Foo', status='hello',
+        caps={
+            'node': 'http://telepathy.freedesktop.org/fake-client',
+            'ver' : '0.1',
+            'ext' : 'video',
+        })
     stream.send(presence)
 
     # Gabble looks up both the version and the video bundles, in any order
@@ -83,10 +84,11 @@ def test(q, bus, conn, stream):
     assert (2, cs.CHANNEL_TYPE_STREAMED_MEDIA, 3, 3) in caps[2L][icaps_attr]
 
     # send updated presence without video support
-    presence = make_presence('bob at foo.com/Foo', status='hello')
-    c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
-    c['node'] = 'http://telepathy.freedesktop.org/fake-client'
-    c['ver'] = '0.1'
+    presence = make_presence('bob at foo.com/Foo', status='hello',
+        caps={
+            'node': 'http://telepathy.freedesktop.org/fake-client',
+            'ver' : '0.1',
+        })
     stream.send(presence)
 
     # we can now do only audio calls
diff --git a/tests/twisted/text/test-chat-state.py b/tests/twisted/text/test-chat-state.py
index 8f690a9..d1acd6d 100644
--- a/tests/twisted/text/test-chat-state.py
+++ b/tests/twisted/text/test-chat-state.py
@@ -40,10 +40,11 @@ def test(q, bus, conn, stream):
     chan = wrap_channel(bus.get_object(conn.bus_name, path), 'Text',
         ['ChatState', 'Destroyable'])
 
-    presence = make_presence('foo at bar.com/Foo', status='hello')
-    c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
-    c['node'] = 'http://telepathy.freedesktop.org/homeopathy'
-    c['ver'] = '0.1'
+    presence = make_presence('foo at bar.com/Foo', status='hello',
+        caps={
+            'node': 'http://telepathy.freedesktop.org/homeopathy',
+            'ver' : '0.1',
+        })
     stream.send(presence)
 
     version_event = q.expect('stream-iq', to='foo at bar.com/Foo',
-- 
1.5.6.5




More information about the telepathy-commits mailing list