diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_stanza_presence.py | 3 | ||||
-rw-r--r-- | tests/test_stanza_roster.py | 4 | ||||
-rw-r--r-- | tests/test_stream_presence.py | 34 | ||||
-rw-r--r-- | tests/test_stream_roster.py | 99 |
4 files changed, 90 insertions, 50 deletions
diff --git a/tests/test_stanza_presence.py b/tests/test_stanza_presence.py index f9305a31..2ec43b65 100644 --- a/tests/test_stanza_presence.py +++ b/tests/test_stanza_presence.py @@ -49,7 +49,8 @@ class TestPresenceStanzas(SleekTest): self.failUnless(happened == [], "changed_status event triggered for extra unavailable presence") - self.failUnless(c.roster == {}, + roster = c.roster['crap@wherever'] + self.failUnless(roster['bill@chadmore.com'].resources == {}, "Roster updated for superfulous unavailable presence") def testNickPlugin(self): diff --git a/tests/test_stanza_roster.py b/tests/test_stanza_roster.py index cd3e607c..8ec2d32b 100644 --- a/tests/test_stanza_roster.py +++ b/tests/test_stanza_roster.py @@ -48,10 +48,14 @@ class TestRosterStanzas(SleekTest): 'user@example.com': { 'name': 'User', 'subscription': 'both', + 'ask': '', + 'approved': '', 'groups': ['Friends', 'Coworkers']}, 'otheruser@example.com': { 'name': 'Other User', 'subscription': 'both', + 'ask': '', + 'approved': '', 'groups': []}} debug = "Roster items don't match after retrieval." debug += "\nReturned: %s" % str(iq['roster']['items']) diff --git a/tests/test_stream_presence.py b/tests/test_stream_presence.py index 0b086266..21535dce 100644 --- a/tests/test_stream_presence.py +++ b/tests/test_stream_presence.py @@ -30,7 +30,9 @@ class TestStreamPresence(SleekTest): self.xmpp.add_event_handler('presence_unavailable', unavailable) self.recv(""" - <presence type="unavailable" from="otheruser@localhost" /> + <presence type="unavailable" + from="otheruser@localhost" + to="tester@localhost"/> """) # Give event queue time to process. @@ -68,12 +70,14 @@ class TestStreamPresence(SleekTest): # Contact comes online. self.recv(""" - <presence from="otheruser@localhost/foobar" /> + <presence from="otheruser@localhost/foobar" + to="tester@localhost" /> """) # Contact goes offline, should trigger got_offline. self.recv(""" <presence from="otheruser@localhost/foobar" + to="tester@localhost" type="unavailable" /> """) @@ -99,7 +103,8 @@ class TestStreamPresence(SleekTest): self.xmpp.add_event_handler('got_online', got_online) self.recv(""" - <presence from="user@localhost" /> + <presence from="user@localhost" + to="tester@localhost" /> """) # Give event queue time to process. @@ -136,15 +141,23 @@ class TestStreamPresence(SleekTest): self.xmpp.auto_subscribe = True self.recv(""" - <presence from="user@localhost" type="subscribe" /> + <presence from="user@localhost" + to="tester@localhost" + type="subscribe" /> + """) + + self.send(""" + <presence to="user@localhost" + type="subscribed" /> """) self.send(""" - <presence to="user@localhost" type="subscribed" /> + <presence to="user@localhost" /> """) self.send(""" - <presence to="user@localhost" type="subscribe" /> + <presence to="user@localhost" + type="subscribe" /> """) expected = set(('presence_subscribe', 'changed_subscription')) @@ -170,14 +183,17 @@ class TestStreamPresence(SleekTest): presence_subscribe) # With this setting we should reject all subscriptions. - self.xmpp.auto_authorize = False + self.xmpp.roster['tester@localhost'].auto_authorize = False self.recv(""" - <presence from="user@localhost" type="subscribe" /> + <presence from="user@localhost" + to="tester@localhost" + type="subscribe" /> """) self.send(""" - <presence to="user@localhost" type="unsubscribed" /> + <presence to="user@localhost" + type="unsubscribed" /> """) expected = set(('presence_subscribe', 'changed_subscription')) diff --git a/tests/test_stream_roster.py b/tests/test_stream_roster.py index 95163744..1f83f0ec 100644 --- a/tests/test_stream_roster.py +++ b/tests/test_stream_roster.py @@ -17,8 +17,7 @@ class TestStreamRoster(SleekTest): def testGetRoster(self): """Test handling roster requests.""" - self.stream_start(mode='client') - self.failUnless(self.xmpp.roster == {}, "Initial roster not empty.") + self.stream_start(mode='client', jid='tester@localhost') events = [] @@ -37,11 +36,12 @@ class TestStreamRoster(SleekTest): </iq> """) self.recv(""" - <iq type="result" id="1"> + <iq to='tester@localhost' type="result" id="1"> <query xmlns="jabber:iq:roster"> <item jid="user@localhost" name="User" - subscription="both"> + subscription="from" + ask="subscribe"> <group>Friends</group> <group>Examples</group> </item> @@ -52,23 +52,22 @@ class TestStreamRoster(SleekTest): # Wait for get_roster to return. t.join() + self.check_roster('tester@localhost', 'user@localhost', + name='User', + subscription='from', + afrom=True, + pending_out=True, + groups=['Friends', 'Examples']) + # Give the event queue time to process. time.sleep(.1) - roster = {'user@localhost': {'name': 'User', - 'subscription': 'both', - 'groups': ['Friends', 'Examples'], - 'presence': {}, - 'in_roster': True}} - self.failUnless(self.xmpp.roster == roster, - "Unexpected roster values: %s" % self.xmpp.roster) self.failUnless('roster_received' in events, "Roster received event not triggered: %s" % events) def testRosterSet(self): """Test handling pushed roster updates.""" self.stream_start(mode='client') - self.failUnless(self.xmpp.roster == {}, "Initial roster not empty.") events = [] def roster_update(e): @@ -76,9 +75,8 @@ class TestStreamRoster(SleekTest): self.xmpp.add_event_handler('roster_update', roster_update) - self.recv(""" - <iq type="set" id="1"> + <iq to='tester@localhost' type="set" id="1"> <query xmlns="jabber:iq:roster"> <item jid="user@localhost" name="User" @@ -95,16 +93,14 @@ class TestStreamRoster(SleekTest): </iq> """) + self.check_roster('tester@localhost', 'user@localhost', + name='User', + subscription='both', + groups=['Friends', 'Examples']) + # Give the event queue time to process. time.sleep(.1) - roster = {'user@localhost': {'name': 'User', - 'subscription': 'both', - 'groups': ['Friends', 'Examples'], - 'presence': {}, - 'in_roster': True}} - self.failUnless(self.xmpp.roster == roster, - "Unexpected roster values: %s" % self.xmpp.roster) self.failUnless('roster_update' in events, "Roster updated event not triggered: %s" % events) @@ -175,14 +171,13 @@ class TestStreamRoster(SleekTest): # Give the event queue time to process. time.sleep(.1) - roster = {'andré@foo': { - 'name': '', - 'subscription': 'both', - 'groups': ['Unicode'], - 'presence': {}, - 'in_roster': True}} - self.failUnless(self.xmpp.roster == roster, - "Unexpected roster values: %s" % self.xmpp.roster) + self.check_roster('tester@localhost', 'andré@foo', + subscription='both', + groups=['Unicode']) + + jids = list(self.xmpp.client_roster.keys()) + self.failUnless(jids == ['andré@foo'], + "Too many roster entries found: %s" % jids) self.recv(""" <presence to="tester@localhost" from="andré@foo/bar"> @@ -194,18 +189,42 @@ class TestStreamRoster(SleekTest): # Give the event queue time to process. time.sleep(.1) - roster = {'andré@foo': { - 'name': '', - 'subscription': 'both', - 'groups': ['Unicode'], - 'presence': { - 'bar':{'priority':0, - 'status':'Testing', - 'show':'away'}}, - 'in_roster': True}} - self.failUnless(self.xmpp.roster == roster, - "Unexpected roster values: %s" % self.xmpp.roster) + result = self.xmpp.client_roster['andré@foo'].resources + expected = {'bar': {'status':'Testing', + 'show':'away', + 'priority':0}} + self.failUnless(result == expected, + "Unexpected roster values: %s" % result) + + def testSendLastPresence(self): + """Test that sending the last presence works.""" + self.stream_start() + self.xmpp.send_presence(pshow='dnd') + self.xmpp.auto_authorize = True + self.xmpp.auto_subscribe = True + + self.send(""" + <presence> + <show>dnd</show> + </presence> + """) + + self.recv(""" + <presence from="user@localhost" + to="tester@localhost" + type="subscribe" /> + """) + self.send(""" + <presence to="user@localhost" + type="subscribed" /> + """) + + self.send(""" + <presence to="user@localhost"> + <show>dnd</show> + </presence> + """) suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamRoster) |