[Telepathy-commits] [telepathy-gabble/master] use gabbletest.make_presence instead of our own version of it
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Fri Mar 6 07:29:14 PST 2009
---
tests/twisted/jingle/jingletest.py | 18 +-----------
tests/twisted/test-capabilities.py | 24 +++-------------
tests/twisted/test-caps-cache.py | 24 +++-------------
tests/twisted/test-caps-hash.py | 34 +++++++-----------------
tests/twisted/test-caps-tubes.py | 30 +++++---------------
tests/twisted/text/test-chat-state.py | 18 +-----------
tests/twisted/tubes/offer-private-dbus-tube.py | 18 +-----------
7 files changed, 34 insertions(+), 132 deletions(-)
diff --git a/tests/twisted/jingle/jingletest.py b/tests/twisted/jingle/jingletest.py
index e6ad3ef..72dcd91 100644
--- a/tests/twisted/jingle/jingletest.py
+++ b/tests/twisted/jingle/jingletest.py
@@ -3,25 +3,11 @@ Jingle (XEP-0166) testing support.
"""
import random
-from gabbletest import make_result_iq
+from gabbletest import make_result_iq, make_presence
from twisted.words.xish import domish
from twisted.words.protocols.jabber.client import IQ
import dbus
-def make_presence(fromjid, tojid, caps=None):
- el = domish.Element(('jabber:client', 'presence',))
- el['from'] = fromjid
- el['to'] = tojid
-
- if caps:
- cel = domish.Element(('http://jabber.org/protocol/caps', 'c'))
- for key,value in caps.items():
- cel[key] = value
- el.addChild(cel)
-
- return el
-
-
def make_caps_disco_reply(stream, req, features):
iq = make_result_iq(stream, req)
query = iq.firstChildElement()
@@ -129,7 +115,7 @@ class JingleTest:
def send_remote_presence(self):
presence = make_presence(self.remote_jid, self.local_jid,
- self.remote_caps)
+ caps=self.remote_caps)
self.stream.send(presence.toXml())
diff --git a/tests/twisted/test-capabilities.py b/tests/twisted/test-capabilities.py
index bb7170e..1540833 100644
--- a/tests/twisted/test-capabilities.py
+++ b/tests/twisted/test-capabilities.py
@@ -8,7 +8,7 @@ import dbus
from twisted.words.xish import domish
from servicetest import EventPattern
-from gabbletest import exec_test, make_result_iq
+from gabbletest import exec_test, make_result_iq, make_presence
text = 'org.freedesktop.Telepathy.Channel.Type.Text'
sm = 'org.freedesktop.Telepathy.Channel.Type.StreamedMedia'
@@ -16,25 +16,11 @@ icaps = 'org.freedesktop.Telepathy.Connection.Interface.Capabilities'
icaps_attr = icaps + "/caps"
basic_caps = [(2, text, 3, 0)]
-def make_presence(from_jid, type, status):
- presence = domish.Element((None, 'presence'))
-
- if from_jid is not None:
- presence['from'] = from_jid
-
- if type is not None:
- presence['type'] = type
-
- if status is not None:
- presence.addElement('status', content=status)
-
- return presence
-
def test(q, bus, conn, stream):
conn.Connect()
q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
- presence = make_presence('bob at foo.com/Foo', None, 'hello')
+ presence = make_presence('bob at foo.com/Foo', status='hello')
stream.send(presence)
q.expect_many(
@@ -53,7 +39,7 @@ 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', None, 'hello')
+ 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'
@@ -101,7 +87,7 @@ def test(q, bus, conn, stream):
assert (2, sm, 3, 3) in caps[2L][icaps_attr]
# send updated presence without video support
- presence = make_presence('bob at foo.com/Foo', None, 'hello')
+ 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'
@@ -119,7 +105,7 @@ def test(q, bus, conn, stream):
assert (2, sm, 3, 1) in caps[2L][icaps_attr]
# go offline
- presence = make_presence('bob at foo.com/Foo', 'unavailable', None)
+ presence = make_presence('bob at foo.com/Foo', type='unavailable')
stream.send(presence)
# can't do audio calls any more
diff --git a/tests/twisted/test-caps-cache.py b/tests/twisted/test-caps-cache.py
index 07d13f5..98ef5e6 100644
--- a/tests/twisted/test-caps-cache.py
+++ b/tests/twisted/test-caps-cache.py
@@ -10,26 +10,12 @@ import sys
from twisted.words.xish import domish, xpath
from servicetest import EventPattern
-from gabbletest import exec_test, make_result_iq
+from gabbletest import exec_test, make_result_iq, make_presence
text = 'org.freedesktop.Telepathy.Channel.Type.Text'
sm = 'org.freedesktop.Telepathy.Channel.Type.StreamedMedia'
caps_iface = 'org.freedesktop.Telepathy.Connection.Interface.Capabilities'
-def make_presence(from_jid, type, status):
- presence = domish.Element((None, 'presence'))
-
- if from_jid is not None:
- presence['from'] = from_jid
-
- if type is not None:
- presence['type'] = type
-
- if status is not None:
- presence.addElement('status', content=status)
-
- return presence
-
def presence_add_caps(presence, ver, client, hash=None):
c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
c['node'] = client
@@ -40,7 +26,7 @@ def presence_add_caps(presence, ver, client, hash=None):
def _test_without_hash(q, bus, conn, stream, contact, contact_handle, client, disco):
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
stream.send(presence)
q.expect_many(
@@ -57,7 +43,7 @@ def _test_without_hash(q, bus, conn, stream, contact, contact_handle, client, di
assert conn.Capabilities.GetCapabilities([contact_handle]) == basic_caps
# send updated presence with Jingle caps info
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
presence = presence_add_caps(presence, '0.1', client)
stream.send(presence)
@@ -85,7 +71,7 @@ def _test_without_hash(q, bus, conn, stream, contact, contact_handle, client, di
def _test_with_hash(q, bus, conn, stream, contact, contact_handle, client, disco):
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
stream.send(presence)
q.expect_many(
@@ -101,7 +87,7 @@ def _test_with_hash(q, bus, conn, stream, contact, contact_handle, client, disco
assert conn.Capabilities.GetCapabilities([contact_handle]) == basic_caps
# send updated presence with Jingle caps info
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
c['node'] = client
c['ver'] = 'CzO+nkbflbxu1pgzOQSIi8gOyDc=' # good hash
diff --git a/tests/twisted/test-caps-hash.py b/tests/twisted/test-caps-hash.py
index 17280f4..8548dd9 100644
--- a/tests/twisted/test-caps-hash.py
+++ b/tests/twisted/test-caps-hash.py
@@ -25,7 +25,7 @@ import sys
from twisted.words.xish import domish, xpath
-from gabbletest import exec_test, make_result_iq
+from gabbletest import exec_test, make_result_iq, make_presence
from servicetest import sync_dbus, EventPattern
gabble_service = 'org.freedesktop.Telepathy.ConnectionManager.gabble'
@@ -42,20 +42,6 @@ def caps_changed_cb(dummy):
global caps_changed_flag
caps_changed_flag = True
-def make_presence(from_jid, type, status):
- presence = domish.Element((None, 'presence'))
-
- if from_jid is not None:
- presence['from'] = from_jid
-
- if type is not None:
- presence['type'] = type
-
- if status is not None:
- presence.addElement('status', content=status)
-
- return presence
-
def presence_add_caps(presence, ver, client, hash=None):
c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
c['node'] = client
@@ -67,7 +53,7 @@ def presence_add_caps(presence, ver, client, hash=None):
def test_hash(q, bus, conn, stream, contact, contact_handle, client):
global caps_changed_flag
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
stream.send(presence)
q.expect_many(
@@ -83,7 +69,7 @@ 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, None, 'hello')
+ presence = make_presence(contact, status='hello')
presence = presence_add_caps(presence, '0.1', client)
stream.send(presence)
@@ -110,7 +96,7 @@ def test_hash(q, bus, conn, stream, contact, contact_handle, client):
caps_changed_flag = False
# send bogus presence
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
c['node'] = client
c['ver'] = 'KyuUmfhC34jP1sDjs489RjkJfsg=' # good hash
@@ -137,7 +123,7 @@ def test_hash(q, bus, conn, stream, contact, contact_handle, client):
assert caps_changed_flag == False
# send presence with empty caps
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
presence = presence_add_caps(presence, '0.0', client)
stream.send(presence)
@@ -163,7 +149,7 @@ def test_hash(q, bus, conn, stream, contact, contact_handle, client):
caps_changed_flag = False
# send correct presence
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
c = presence.addElement(('http://jabber.org/protocol/caps', 'c'))
c['node'] = client
c['ver'] = 'CzO+nkbflbxu1pgzOQSIi8gOyDc=' # good hash
@@ -222,7 +208,7 @@ def test_two_clients(q, bus, conn, stream, contact1, contact2,
contact_handle1, contact_handle2, client, broken_hash):
global caps_changed_flag
- presence = make_presence(contact1, None, 'hello')
+ presence = make_presence(contact1, status='hello')
stream.send(presence)
event = q.expect_many(
@@ -233,7 +219,7 @@ def test_two_clients(q, bus, conn, stream, contact1, contact2,
args=[{contact_handle1:
(2, u'available', 'hello')}]))
- presence = make_presence(contact2, None, 'hello')
+ presence = make_presence(contact2, status='hello')
stream.send(presence)
event = q.expect_many(
@@ -251,12 +237,12 @@ 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, None, 'hello')
+ presence = make_presence(contact1, status='hello')
ver = 'JpaYgiKL0y4fUOCTwN3WLGpaftM='
presence = presence_add_caps(presence, ver, client,
hash='sha-1')
stream.send(presence)
- presence = make_presence(contact2, None, 'hello')
+ presence = make_presence(contact2, status='hello')
presence = presence_add_caps(presence, ver, client,
hash='sha-1')
stream.send(presence)
diff --git a/tests/twisted/test-caps-tubes.py b/tests/twisted/test-caps-tubes.py
index 908e9ec..f408d86 100644
--- a/tests/twisted/test-caps-tubes.py
+++ b/tests/twisted/test-caps-tubes.py
@@ -37,7 +37,7 @@ import sys
from twisted.words.xish import domish, xpath
from servicetest import EventPattern
-from gabbletest import exec_test, make_result_iq, sync_stream
+from gabbletest import exec_test, make_result_iq, sync_stream, make_presence
from constants import *
from caps_helper import compute_caps_hash
@@ -90,20 +90,6 @@ go_fixed_properties = dbus.Dictionary({
DBUS_TUBE_SERVICE_NAME: 'com.example.Go'
})
-def make_presence(from_jid, type, status):
- presence = domish.Element((None, 'presence'))
-
- if from_jid is not None:
- presence['from'] = from_jid
-
- if type is not None:
- presence['type'] = type
-
- if status is not None:
- presence.addElement('status', content=status)
-
- return presence
-
def presence_add_caps(presence, ver, client, hash=None):
c = presence.addElement((ns.CAPS, 'c'))
c['node'] = client
@@ -173,7 +159,7 @@ def test_tube_caps_from_contact(q, bus, conn, stream, contact, contact_handle, c
conn_contacts_iface = dbus.Interface(conn, CONN_IFACE_CONTACTS)
# send presence with no tube cap
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
c = presence.addElement((ns.CAPS, 'c'))
c['node'] = client
c['ver'] = compute_caps_hash([], [], [])
@@ -211,7 +197,7 @@ def test_tube_caps_from_contact(q, bus, conn, stream, contact, contact_handle, c
caps_via_contacts_iface
# send presence with generic tubes caps
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
c = presence.addElement((ns.CAPS, 'c'))
c['node'] = client
c['ver'] = compute_caps_hash([], [ns.TUBES], [])
@@ -255,7 +241,7 @@ def test_tube_caps_from_contact(q, bus, conn, stream, contact, contact_handle, c
# send presence with 1 stream tube cap
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
c = presence.addElement((ns.CAPS, 'c'))
c['node'] = client
c['ver'] = compute_caps_hash([], [ns.TUBES + '/stream#daap'], [])
@@ -299,7 +285,7 @@ def test_tube_caps_from_contact(q, bus, conn, stream, contact, contact_handle, c
caps_via_contacts_iface
# send presence with 1 D-Bus tube cap
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
c = presence.addElement((ns.CAPS, 'c'))
c['node'] = client
c['ver'] = compute_caps_hash([], [ns.TUBES + '/dbus#com.example.Xiangqi'], [])
@@ -343,7 +329,7 @@ def test_tube_caps_from_contact(q, bus, conn, stream, contact, contact_handle, c
caps_via_contacts_iface
# send presence with both D-Bus and stream tube caps
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
c = presence.addElement((ns.CAPS, 'c'))
c['node'] = client
c['ver'] = compute_caps_hash([], [ns.TUBES + '/dbus#com.example.Xiangqi',
@@ -391,7 +377,7 @@ def test_tube_caps_from_contact(q, bus, conn, stream, contact, contact_handle, c
caps_via_contacts_iface
# send presence with 4 tube caps
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
c = presence.addElement((ns.CAPS, 'c'))
c['node'] = client
c['ver'] = compute_caps_hash([], [ns.TUBES + '/dbus#com.example.Xiangqi',
@@ -446,7 +432,7 @@ def test_tube_caps_from_contact(q, bus, conn, stream, contact, contact_handle, c
caps_via_contacts_iface
# send presence with both D-Bus and stream tube caps
- presence = make_presence(contact, None, 'hello')
+ presence = make_presence(contact, status='hello')
c = presence.addElement((ns.CAPS, 'c'))
c['node'] = client
c['ver'] = compute_caps_hash([], [ns.TUBES + '/dbus#com.example.Xiangqi',
diff --git a/tests/twisted/text/test-chat-state.py b/tests/twisted/text/test-chat-state.py
index 5d4f9de..1526ee8 100644
--- a/tests/twisted/text/test-chat-state.py
+++ b/tests/twisted/text/test-chat-state.py
@@ -9,27 +9,13 @@ import dbus
from twisted.words.xish import domish
from servicetest import call_async, make_channel_proxy
-from gabbletest import exec_test, make_result_iq, sync_stream
+from gabbletest import exec_test, make_result_iq, sync_stream, make_presence
import ns
CHAT_STATE_ACTIVE = 2
CHAT_STATE_COMPOSING = 4
-def make_presence(from_jid, type, status):
- presence = domish.Element((None, 'presence'))
-
- if from_jid is not None:
- presence['from'] = from_jid
-
- if type is not None:
- presence['type'] = type
-
- if status is not None:
- presence.addElement('status', content=status)
-
- return presence
-
def test(q, bus, conn, stream):
conn.Connect()
q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
@@ -55,7 +41,7 @@ def test(q, bus, conn, stream):
chat_state_iface = make_channel_proxy(conn, path,
'Channel.Interface.ChatState')
- presence = make_presence('foo at bar.com/Foo', None, 'hello')
+ 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'
diff --git a/tests/twisted/tubes/offer-private-dbus-tube.py b/tests/twisted/tubes/offer-private-dbus-tube.py
index 7c67527..93928e0 100644
--- a/tests/twisted/tubes/offer-private-dbus-tube.py
+++ b/tests/twisted/tubes/offer-private-dbus-tube.py
@@ -5,7 +5,7 @@ from dbus.connection import Connection
from dbus.lowlevel import SignalMessage
from servicetest import call_async, EventPattern, unwrap, watch_tube_signals
-from gabbletest import make_result_iq, sync_stream
+from gabbletest import make_result_iq, sync_stream, make_presence
import constants as cs
import tubetestutil as t
@@ -20,20 +20,6 @@ sample_parameters = dbus.Dictionary({
'i': dbus.Int32(-123),
}, signature='sv')
-# FIXME: stolen from jingletest.py. Should be shared by all tests
-def make_presence(fromjid, tojid, caps=None):
- el = domish.Element(('jabber:client', 'presence',))
- el['from'] = fromjid
- el['to'] = tojid
-
- if caps:
- cel = domish.Element(('http://jabber.org/protocol/caps', 'c'))
- for key,value in caps.items():
- cel[key] = value
- el.addChild(cel)
-
- return el
-
def make_caps_disco_reply(stream, req, features):
iq = make_result_iq(stream, req)
query = iq.firstChildElement()
@@ -303,7 +289,7 @@ def test(q, bus, conn, stream, bytestream_cls):
# send Alice's presence
caps = { 'ext': '', 'ver': '0.0.0',
'node': 'http://example.com/fake-client0' }
- presence = make_presence('alice at localhost/Test', 'test at localhost', caps)
+ presence = make_presence('alice at localhost/Test', caps=caps)
stream.send(presence)
_, disco_event = q.expect_many(
--
1.5.6.5
More information about the telepathy-commits
mailing list