[telepathy-gabble/master] Add a regression test for the gateways plugin
Simon McVittie
simon.mcvittie at collabora.co.uk
Mon Jan 4 10:53:56 PST 2010
In particular, check that the errors mentioned in XEP-0077 are handled.
---
tests/twisted/Makefile.am | 1 +
tests/twisted/constants.py | 1 +
tests/twisted/gateways.py | 94 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 96 insertions(+), 0 deletions(-)
create mode 100644 tests/twisted/gateways.py
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 34d7079..0f9ec3b 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -13,6 +13,7 @@ TWISTED_TESTS = \
caps/receive-jingle.py \
caps/trust-thyself.py \
caps/tube-caps.py \
+ gateways.py \
muc/name-conflict.py \
muc/renamed.py \
muc/roomlist.py \
diff --git a/tests/twisted/constants.py b/tests/twisted/constants.py
index bf8f324..1e935ec 100644
--- a/tests/twisted/constants.py
+++ b/tests/twisted/constants.py
@@ -115,6 +115,7 @@ CONNECTION_FAILED = ERROR + '.ConnectionFailed'
CONNECTION_LOST = ERROR + '.ConnectionLost'
CANCELLED = ERROR + '.Cancelled'
DISCONNECTED = ERROR + '.Disconnected'
+REGISTRATION_EXISTS = ERROR + '.RegistrationExists'
UNKNOWN_METHOD = 'org.freedesktop.DBus.Error.UnknownMethod'
diff --git a/tests/twisted/gateways.py b/tests/twisted/gateways.py
new file mode 100644
index 0000000..bce152e
--- /dev/null
+++ b/tests/twisted/gateways.py
@@ -0,0 +1,94 @@
+"""
+Test the gateways plugin
+"""
+
+import dbus
+from twisted.words.xish import domish, xpath
+
+from servicetest import (
+ sync_dbus, call_async, EventPattern, assertEquals, assertContains,
+ )
+from gabbletest import exec_test, send_error_reply, acknowledge_iq, sync_stream
+import constants as cs
+import ns
+from config import PLUGINS_ENABLED
+
+PLUGIN_IFACE = "org.freedesktop.Telepathy.Gabble.Plugin.Gateways"
+
+if not PLUGINS_ENABLED:
+ print "NOTE: built without --enable-plugins, not testing plugins"
+ raise SystemExit(77)
+
+def test_success(q, gateways_iface, stream):
+ call_async(q, gateways_iface, 'Register',
+ 'talkd.example.com', '1970', 's3kr1t')
+ e = q.expect('stream-iq', iq_type='set', query_name='query',
+ query_ns=ns.REGISTER, to='talkd.example.com')
+ assertEquals('1970', xpath.queryForString('/query/username', e.query))
+ assertEquals('s3kr1t', xpath.queryForString('/query/password', e.query))
+ acknowledge_iq(stream, e.stanza)
+ q.expect('dbus-return', method='Register')
+
+def test_conflict(q, gateways_iface, stream):
+ call_async(q, gateways_iface, 'Register',
+ 'sip.example.com', '8675309', 'jenny')
+ e = q.expect('stream-iq', iq_type='set', query_name='query',
+ query_ns=ns.REGISTER, to='sip.example.com')
+ assertEquals('8675309', xpath.queryForString('/query/username', e.query))
+ assertEquals('jenny', xpath.queryForString('/query/password', e.query))
+ error = domish.Element((None, 'error'))
+ error['type'] = 'cancel'
+ error['code'] = '409'
+ error.addElement((ns.STANZA, 'conflict'))
+ send_error_reply(stream, e.stanza, error)
+ q.expect('dbus-error', method='Register', name=cs.REGISTRATION_EXISTS)
+
+def test_not_acceptable(q, gateways_iface, stream):
+ call_async(q, gateways_iface, 'Register',
+ 'fully-captcha-enabled.example.com', 'lalala', 'stoats')
+ e = q.expect('stream-iq', iq_type='set', query_name='query',
+ query_ns=ns.REGISTER, to='fully-captcha-enabled.example.com')
+ assertEquals('lalala', xpath.queryForString('/query/username', e.query))
+ assertEquals('stoats', xpath.queryForString('/query/password', e.query))
+ error = domish.Element((None, 'error'))
+ error['type'] = 'modify'
+ error['code'] = '406'
+ error.addElement((ns.STANZA, 'not-acceptable'))
+ send_error_reply(stream, e.stanza, error)
+ q.expect('dbus-error', method='Register', name=cs.NOT_AVAILABLE)
+
+def test(q, bus, conn, stream):
+ # Request a sidecar thate we support before we're connected; it should just
+ # wait around until we're connected.
+ call_async(q, conn.Future, 'EnsureSidecar', PLUGIN_IFACE)
+
+ conn.Connect()
+ q.expect('dbus-signal', signal='StatusChanged',
+ args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])
+
+ # Now we're connected, the call we made earlier should return.
+ path, props = q.expect('dbus-return', method='EnsureSidecar').value
+ # This sidecar doesn't even implement get_immutable_properties; it
+ # should just get the empty dict filled in for it.
+ assertEquals({}, props)
+
+ gateways_iface = dbus.Interface(bus.get_object(conn.bus_name, path),
+ PLUGIN_IFACE)
+
+ test_success(q, gateways_iface, stream)
+ test_conflict(q, gateways_iface, stream)
+ test_not_acceptable(q, gateways_iface, stream)
+
+ call_async(q, conn, 'Disconnect')
+
+ q.expect_many(
+ EventPattern('dbus-signal', signal='StatusChanged',
+ args=[cs.CONN_STATUS_DISCONNECTED, cs.CSR_REQUESTED]),
+ EventPattern('stream-closed'),
+ )
+
+ stream.sendFooter()
+ q.expect('dbus-return', method='Disconnect')
+
+if __name__ == '__main__':
+ exec_test(test)
--
1.5.6.5
More information about the telepathy-commits
mailing list