Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added stream tests for rosters.

  • Loading branch information...
commit d5288847234110cc9116aaf91a26c5a1fc395202 1 parent d9aff3d
Lance Stout legastero authored

Showing 1 changed file with 86 additions and 0 deletions. Show diff stats Hide diff stats

  1. +86 0 tests/test_stream_roster.py
86 tests/test_stream_roster.py
... ... @@ -0,0 +1,86 @@
  1 +from sleekxmpp.test import *
  2 +import time
  3 +import threading
  4 +
  5 +
  6 +class TestStreamRoster(SleekTest):
  7 + """
  8 + Test handling roster updates.
  9 + """
  10 +
  11 + def tearDown(self):
  12 + self.stream_close()
  13 +
  14 + def testGetRoster(self):
  15 + """Test handling roster requests."""
  16 + self.stream_start(mode='client')
  17 + self.failUnless(self.xmpp.roster == {}, "Initial roster not empty.")
  18 +
  19 + # Since get_roster blocks, we need to run it in a thread.
  20 + t = threading.Thread(name='get_roster', target=self.xmpp.get_roster)
  21 + t.start()
  22 +
  23 + self.stream_send_iq("""
  24 + <iq type="get" id="1">
  25 + <query xmlns="jabber:iq:roster" />
  26 + </iq>
  27 + """)
  28 + self.stream_recv("""
  29 + <iq type="result" id="1">
  30 + <query xmlns="jabber:iq:roster">
  31 + <item jid="user@localhost"
  32 + name="User"
  33 + subscription="both">
  34 + <group>Friends</group>
  35 + <group>Examples</group>
  36 + </item>
  37 + </query>
  38 + </iq>
  39 + """)
  40 +
  41 + # Wait for get_roster to return.
  42 + t.join()
  43 +
  44 + roster = {'user@localhost': {'name': 'User',
  45 + 'subscription': 'both',
  46 + 'groups': ['Friends', 'Examples'],
  47 + 'presence': {},
  48 + 'in_roster': True}}
  49 + self.failUnless(self.xmpp.roster == roster,
  50 + "Unexpected roster values: %s" % self.xmpp.roster)
  51 +
  52 + def testRosterSet(self):
  53 + """Test handling pushed roster updates."""
  54 + self.stream_start(mode='client')
  55 + self.failUnless(self.xmpp.roster == {}, "Initial roster not empty.")
  56 +
  57 + self.stream_recv("""
  58 + <iq type="set" id="1">
  59 + <query xmlns="jabber:iq:roster">
  60 + <item jid="user@localhost"
  61 + name="User"
  62 + subscription="both">
  63 + <group>Friends</group>
  64 + <group>Examples</group>
  65 + </item>
  66 + </query>
  67 + </iq>
  68 + """)
  69 + self.stream_send_iq("""
  70 + <iq type="result" id="1">
  71 + <query xmlns="jabber:iq:roster" />
  72 + </iq>
  73 + """)
  74 +
  75 + roster = {'user@localhost': {'name': 'User',
  76 + 'subscription': 'both',
  77 + 'groups': ['Friends', 'Examples'],
  78 + 'presence': {},
  79 + 'in_roster': True}}
  80 + self.failUnless(self.xmpp.roster == roster,
  81 + "Unexpected roster values: %s" % self.xmpp.roster)
  82 +
  83 +
  84 +
  85 +
  86 +suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamRoster)

0 comments on commit d528884

Please sign in to comment.
Something went wrong with that request. Please try again.