summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2011-09-02 16:31:41 +0100
committerJonny Lamb <jonny.lamb@collabora.co.uk>2011-09-02 16:40:15 +0100
commit6dfe751e17618a5f29f6611b649e7a1bbe0969d3 (patch)
treec815133a5606c7fa6c771c121c0336160d34126c
parent587da15932d178ad289e81b039dcabb4e90984c5 (diff)
caps_helper: split out code to read disco replies
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--tests/twisted/caps_helper.py53
1 files changed, 29 insertions, 24 deletions
diff --git a/tests/twisted/caps_helper.py b/tests/twisted/caps_helper.py
index 65fa291d..85013850 100644
--- a/tests/twisted/caps_helper.py
+++ b/tests/twisted/caps_helper.py
@@ -205,27 +205,8 @@ def receive_presence_and_ask_caps(q, stream, expect_dbus=True):
return disco_caps(q, stream, presence) + (signaled_caps,)
-def disco_caps(q, stream, presence):
- c_nodes = xpath.queryForNodes('/presence/c', presence.stanza)
- assert c_nodes is not None
- assertLength(1, c_nodes)
- hash = c_nodes[0].attributes['hash']
- ver = c_nodes[0].attributes['ver']
- node = c_nodes[0].attributes['node']
- assertEquals('sha-1', hash)
-
- # ask caps
- request = \
- elem_iq(stream, 'get', from_='fake_contact@jabber.org/resource')(
- elem(ns.DISCO_INFO, 'query', node=(node + '#' + ver))
- )
- stream.send(request)
-
- # receive caps
- event = q.expect('stream-iq', query_ns=ns.DISCO_INFO, iq_id=request['id'])
-
- # Check that Gabble's announcing the identity we think it should be.
- identity_nodes = xpath.queryForNodes('/iq/query/identity', event.stanza)
+def extract_disco_parts(stanza):
+ identity_nodes = xpath.queryForNodes('/iq/query/identity', stanza)
assertLength(1, identity_nodes)
identity_node = identity_nodes[0]
@@ -237,11 +218,11 @@ def disco_caps(q, stream, presence):
identity = 'client/%s//%s' % (config.CLIENT_TYPE, config.PACKAGE_STRING)
features = []
- for feature in xpath.queryForNodes('/iq/query/feature', event.stanza):
+ for feature in xpath.queryForNodes('/iq/query/feature', stanza):
features.append(feature['var'])
# a quick and ugly data form extractor
- x_nodes = xpath.queryForNodes('/iq/query/x', event.stanza) or []
+ x_nodes = xpath.queryForNodes('/iq/query/x', stanza) or []
dataforms = {}
for form in x_nodes:
name = None
@@ -257,8 +238,32 @@ def disco_caps(q, stream, presence):
if name is not None:
dataforms[name] = fields
+ return ([identity], features, dataforms)
+
+def disco_caps(q, stream, presence):
+ c_nodes = xpath.queryForNodes('/presence/c', presence.stanza)
+ assert c_nodes is not None
+ assertLength(1, c_nodes)
+ hash = c_nodes[0].attributes['hash']
+ ver = c_nodes[0].attributes['ver']
+ node = c_nodes[0].attributes['node']
+ assertEquals('sha-1', hash)
+
+ # ask caps
+ request = \
+ elem_iq(stream, 'get', from_='fake_contact@jabber.org/resource')(
+ elem(ns.DISCO_INFO, 'query', node=(node + '#' + ver))
+ )
+ stream.send(request)
+
+ # receive caps
+ event = q.expect('stream-iq', query_ns=ns.DISCO_INFO, iq_id=request['id'])
+
+ # Check that Gabble's announcing the identity we think it should be.
+ (identities, features, dataforms) = extract_disco_parts(event.stanza)
+
# Check if the hash matches the announced capabilities
- assertEquals(compute_caps_hash([identity], features, dataforms), ver)
+ assertEquals(compute_caps_hash(identities, features, dataforms), ver)
return (event, features)