[Telepathy-commits] [telepathy-gabble/master] Test a conflicting nick not actually being in the MUC.

Will Thompson will.thompson at collabora.co.uk
Sun Feb 1 07:41:28 PST 2009


(You try to join as test and get a conflict. You try to join as test_ and
succeed, but in the meantime test has left.)
---
 tests/twisted/muc/name-conflict.py |   54 ++++++++++++++++++++++++------------
 1 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/tests/twisted/muc/name-conflict.py b/tests/twisted/muc/name-conflict.py
index 3c8e807..8b8cd0c 100644
--- a/tests/twisted/muc/name-conflict.py
+++ b/tests/twisted/muc/name-conflict.py
@@ -22,11 +22,26 @@ def test(q, bus, conn, stream):
     conn.Connect()
     q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
 
+    test_join(q, bus, conn, stream, 'chat at conf.localhost', False)
+    test_join(q, bus, conn, stream, 'chien at conf.localhost', True)
+
+    conn.Disconnect()
+
+    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+
+def test_join(q, bus, conn, stream, room_jid, transient_conflict):
+    """
+    Tells Gabble to join a MUC, but make the first nick it tries conflict with
+    an existing member of the MUC.  If transient_conflict is True, then when
+    Gabble successfully joins with a different nick the originally conflicting
+    user turns out not actually to be in the room (they left while we were
+    retrying).
+    """
+
     self_handle = conn.GetSelfHandle()
 
     requests = dbus.Interface(conn, CONN_IFACE_REQUESTS)
 
-    room_jid = 'chat at conf.localhost'
     room_handle = request_muc_handle(q, conn, stream, room_jid)
     # Implementation detail: Gabble uses the first part of your jid (if you
     # don't have an alias) as your room nickname, and appends an underscore a
@@ -42,7 +57,7 @@ def test(q, bus, conn, stream):
     # Gabble first tries to join as test
     q.expect('stream-presence', to=member)
 
-    # MUC says no: there's already someone called test in chat at conf.localhost
+    # MUC says no: there's already someone called test in room_jid
     presence = domish.Element((None, 'presence'))
     presence['from'] = member
     presence['type'] = 'error'
@@ -57,10 +72,10 @@ def test(q, bus, conn, stream):
 
     # MUC says yes!
 
-    # Send the other member of the room's presence. This is the nick we
-    # originally wanted.
-    stream.send(make_muc_presence(
-        'owner', 'moderator', 'chat at conf.localhost', 'test'))
+    if not transient_conflict:
+        # Send the other member of the room's presence. This is the nick we
+        # originally wanted.
+        stream.send(make_muc_presence('owner', 'moderator', room_jid, 'test'))
 
     # If gabble erroneously thinks the other user's presence is our own, it'll
     # think that it's got the whole userlist now. If so, syncing here will make
@@ -69,8 +84,7 @@ def test(q, bus, conn, stream):
     sync_dbus(stream, q, conn)
 
     # Send presence for own membership of room.
-    stream.send(make_muc_presence(
-        'none', 'participant', 'chat at conf.localhost', 'test_'))
+    stream.send(make_muc_presence('none', 'participant', room_jid, 'test_'))
 
     # Only now should we have finished joining the room.
     event = q.expect('dbus-return', method='CreateChannel')
@@ -85,24 +99,28 @@ def test(q, bus, conn, stream):
     muc_self_handle = group_props['SelfHandle']
     assert muc_self_handle == t_, (muc_self_handle, t_, t)
 
-    # Check there are exactly two members (test and test_) and that there are
-    # no pending members
     members = group_props['Members']
-    assert sorted(members) == sorted([t, t_]), (members, [t, t_])
+
+    if transient_conflict:
+        # The user we originally conflicted with isn't actually here; check
+        # there's exactly one member (test_).
+        assert members == [t_], (members, t_, t)
+    else:
+        # Check there are exactly two members (test and test_)
+        assert sorted(members) == sorted([t, t_]), (members, [t, t_])
+
+    # In either case, there should be no pending members.
     assert len(group_props['LocalPendingMembers']) == 0, group_props
     assert len(group_props['RemotePendingMembers']) == 0, group_props
 
-    # Check that test_'s handle owner is us, and that test has no owner.
+    # Check that test_'s handle owner is us, and that test (if it's there) has
+    # no owner.
     handle_owners = group_props['HandleOwners']
     assert handle_owners[t_] == self_handle, \
         (handle_owners, t_, handle_owners[t_], self_handle)
-    assert handle_owners[t] == 0, (handle_owners, t)
-
-    conn.Disconnect()
-
-    q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+    if not transient_conflict:
+        assert handle_owners[t] == 0, (handle_owners, t)
 
-    return True
 
 if __name__ == '__main__':
     exec_test(test)
-- 
1.5.6.5




More information about the Telepathy-commits mailing list