[telepathy-gabble/telepathy-gabble-0.8] muc/subject.py: new test for the current behaviour of the 'subject' MUC property

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Nov 12 06:13:26 PST 2009


---
 tests/twisted/Makefile.am    |    1 +
 tests/twisted/muc/subject.py |  128 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 129 insertions(+), 0 deletions(-)
 create mode 100644 tests/twisted/muc/subject.py

diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 4ef1d25..2091e7a 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -17,6 +17,7 @@ TWISTED_TESTS = \
 	muc/renamed.py \
 	muc/roomlist.py \
 	muc/send-error.py \
+	muc/subject.py \
 	muc/test-ensure.py \
 	muc/test-muc-alias.py \
 	muc/test-muc-invitation.py \
diff --git a/tests/twisted/muc/subject.py b/tests/twisted/muc/subject.py
new file mode 100644
index 0000000..327d739
--- /dev/null
+++ b/tests/twisted/muc/subject.py
@@ -0,0 +1,128 @@
+
+"""
+Test MUC support.
+"""
+
+import dbus
+
+from twisted.words.xish import domish
+
+from gabbletest import exec_test, make_result_iq
+from servicetest import (EventPattern, assertEquals, assertLength,
+        assertContains)
+import constants as cs
+import ns
+
+from mucutil import join_muc
+
+def test(q, bus, conn, stream):
+    conn.Connect()
+    q.expect('dbus-signal', signal='StatusChanged',
+            args=[cs.CONN_STATUS_CONNECTED, cs.CSR_REQUESTED])
+
+    # 3x2x2 possible combinations of change_subject, send_first, moderator:
+    # unrolling the loop here so we'll get better Python tracebacks on failure
+    test_subject(q, bus, conn, stream, None, False, False)
+    test_subject(q, bus, conn, stream, None, False, True)
+    test_subject(q, bus, conn, stream, None, True, False)
+    test_subject(q, bus, conn, stream, None, False, True)
+    test_subject(q, bus, conn, stream, True, False, False)
+    test_subject(q, bus, conn, stream, True, False, True)
+    test_subject(q, bus, conn, stream, True, True, False)
+    test_subject(q, bus, conn, stream, True, False, True)
+    test_subject(q, bus, conn, stream, False, False, False)
+    test_subject(q, bus, conn, stream, False, False, True)
+    test_subject(q, bus, conn, stream, False, True, False)
+    test_subject(q, bus, conn, stream, False, False, True)
+
+counter = 0
+
+def test_subject(q, bus, conn, stream, change_subject, send_first,
+        moderator):
+    global counter
+    room = 'test%d at conf.localhost' % counter
+    counter += 1
+
+    room_handle, chan, path, props, disco = join_muc(q, bus, conn, stream,
+            room,
+            also_capture=[EventPattern('stream-iq', iq_type='get',
+                query_name='query', query_ns=ns.DISCO_INFO, to=room)],
+            role=(moderator and 'moderator' or 'participant'))
+
+    # Until the disco returns, we appear to have no properties except subject.
+
+    prop_list = chan.TpProperties.ListProperties()
+    props = dict([(name, id) for id, name, sig, flags in prop_list])
+    prop_flags = dict([(name, flags) for id, name, sig, flags in prop_list])
+
+    for name in props:
+        if name == 'subject':
+            # subject can always be changed, until fd.o#13157 is fixed
+            assertEquals(cs.PROPERTY_FLAG_WRITE, prop_flags[name])
+        else:
+            assertEquals(0, prop_flags[name])
+
+    if send_first:
+        # Someone sets a subject.
+        message = domish.Element((None, 'message'))
+        message['from'] = room + '/bob'
+        message['type'] = 'groupchat'
+        message.addElement('subject', content='Testing')
+        stream.send(message)
+
+        q.expect('dbus-signal', signal='PropertiesChanged',
+                predicate=lambda e: (props['subject'], 'Testing') in e.args[0])
+        e = q.expect('dbus-signal', signal='PropertyFlagsChanged',
+                predicate=lambda e:
+                    (props['subject'], cs.PROPERTY_FLAGS_RW) in e.args[0])
+        assertContains((props['subject-contact'], cs.PROPERTY_FLAG_READ),
+                e.args[0])
+        assertContains((props['subject-timestamp'], cs.PROPERTY_FLAG_READ),
+                e.args[0])
+
+    # Reply to the disco
+    iq = make_result_iq(stream, disco.stanza)
+    query = iq.firstChildElement()
+    x = query.addElement((ns.X_DATA, 'x'))
+    x['type'] = 'result'
+
+    feat = x.addElement('feature')
+    feat['var'] = 'muc_public'
+
+    if change_subject is not None:
+        # When fd.o #13157 has been fixed, this will actually do something.
+        field = x.addElement('field')
+        field['var'] = 'muc#roomconfig_changesubject'
+        field.addElement('value',
+                content=(change_subject and 'true' or 'false'))
+
+    stream.send(iq)
+
+    # Someone sets a subject.
+    message = domish.Element((None, 'message'))
+    message['from'] = room + '/bob'
+    message['type'] = 'groupchat'
+    message.addElement('subject', content='lalala')
+    stream.send(message)
+
+    q.expect('dbus-signal', signal='PropertiesChanged',
+            predicate=lambda e: (props['subject'], 'lalala') in e.args[0])
+
+    # if send_first was true, then we already got this
+    if not send_first:
+        e = q.expect('dbus-signal', signal='PropertyFlagsChanged',
+                predicate=lambda e:
+                    (props['subject'], cs.PROPERTY_FLAGS_RW) in e.args[0])
+        assertContains((props['subject-contact'], cs.PROPERTY_FLAG_READ),
+                e.args[0])
+        assertContains((props['subject-timestamp'], cs.PROPERTY_FLAG_READ),
+                e.args[0])
+
+    chan.Close()
+
+    event = q.expect('stream-presence', to=room + '/test')
+    elem = event.stanza
+    assertEquals('unavailable', elem['type'])
+
+if __name__ == '__main__':
+    exec_test(test)
-- 
1.5.6.5




More information about the telepathy-commits mailing list