Permalink
Browse files

Fixed resource bug in JIDs.

JIDs without resources will return '' instead of the bare JID.

Cleaned up JID tests, and added check_JID to SleekTest.
  • Loading branch information...
1 parent 2f3ff37 commit 9e3d506651e446992a31f66f11b64831f42fddbf @legastero legastero committed Oct 24, 2010
Showing with 75 additions and 14 deletions.
  1. +35 −0 sleekxmpp/test/sleektest.py
  2. +1 −1 sleekxmpp/xmlstream/jid.py
  3. +39 −13 tests/test_jid.py
@@ -103,6 +103,41 @@ def Presence(self, *args, **kwargs):
"""
return Presence(None, *args, **kwargs)
+
+
+ def check_JID(self, jid, user=None, domain=None, resource=None,
+ bare=None, full=None, string=None):
+ """
+ Verify the components of a JID.
+
+ Arguments:
+ jid -- The JID object to test.
+ user -- Optional. The user name portion of the JID.
+ domain -- Optional. The domain name portion of the JID.
+ resource -- Optional. The resource portion of the JID.
+ bare -- Optional. The bare JID.
+ full -- Optional. The full JID.
+ string -- Optional. The string version of the JID.
+ """
+ if user is not None:
+ self.assertEqual(jid.user, user,
+ "User does not match: %s" % jid.user)
+ if domain is not None:
+ self.assertEqual(jid.domain, domain,
+ "Domain does not match: %s" % jid.domain)
+ if resource is not None:
+ self.assertEqual(jid.resource, resource,
+ "Resource does not match: %s" % jid.resource)
+ if bare is not None:
+ self.assertEqual(jid.bare, bare,
+ "Bare JID does not match: %s" % jid.bare)
+ if full is not None:
+ self.assertEqual(jid.full, full,
+ "Full JID does not match: %s" % jid.full)
+ if string is not None:
+ self.assertEqual(str(jid), string,
+ "String does not match: %s" % str(jid))
+
# ------------------------------------------------------------------
# Methods for comparing stanza objects to XML strings
@@ -57,7 +57,7 @@ def __getattr__(self, name):
full, or bare.
"""
if name == 'resource':
- if self._resource is None:
+ if self._resource is None and '/' in self._jid:
self._resource = self._jid.split('/', 1)[-1]
return self._resource or ""
elif name == 'user':
View
@@ -3,26 +3,52 @@
class TestJIDClass(SleekTest):
+
+ """Verify that the JID class can parse and manipulate JIDs."""
+
def testJIDfromfull(self):
- j = JID('user@someserver/some/resource')
- self.assertEqual(j.user, 'user', "User does not match")
- self.assertEqual(j.domain, 'someserver', "Domain does not match")
- self.assertEqual(j.resource, 'some/resource', "Resource does not match")
- self.assertEqual(j.bare, 'user@someserver', "Bare does not match")
- self.assertEqual(j.full, 'user@someserver/some/resource', "Full does not match")
- self.assertEqual(str(j), 'user@someserver/some/resource', "String does not match")
+ """Test using JID of the form 'user@server/resource/with/slashes'."""
+ self.check_JID(JID('user@someserver/some/resource'),
+ 'user',
+ 'someserver',
+ 'some/resource',
+ 'user@someserver',
+ 'user@someserver/some/resource',
+ 'user@someserver/some/resource')
def testJIDchange(self):
+ """Test changing JID of the form 'user@server/resource/with/slashes'"""
j = JID('user1@someserver1/some1/resource1')
j.user = 'user'
j.domain = 'someserver'
j.resource = 'some/resource'
- self.assertEqual(j.user, 'user', "User does not match")
- self.assertEqual(j.domain, 'someserver', "Domain does not match")
- self.assertEqual(j.resource, 'some/resource', "Resource does not match")
- self.assertEqual(j.bare, 'user@someserver', "Bare does not match")
- self.assertEqual(j.full, 'user@someserver/some/resource', "Full does not match")
- self.assertEqual(str(j), 'user@someserver/some/resource', "String does not match")
+ self.check_JID(j,
+ 'user',
+ 'someserver',
+ 'some/resource',
+ 'user@someserver',
+ 'user@someserver/some/resource',
+ 'user@someserver/some/resource')
+
+ def testJIDnoresource(self):
+ """Test using JID of the form 'user@domain'."""
+ self.check_JID(JID('user@someserver'),
+ 'user',
+ 'someserver',
+ '',
+ 'user@someserver',
+ 'user@someserver',
+ 'user@someserver')
+
+ def testJIDnouser(self):
+ """Test JID of the form 'component.domain.tld'."""
+ self.check_JID(JID('component.someserver'),
+ '',
+ 'component.someserver',
+ '',
+ 'component.someserver',
+ 'component.someserver',
+ 'component.someserver')
suite = unittest.TestLoader().loadTestsFromTestCase(TestJIDClass)

0 comments on commit 9e3d506

Please sign in to comment.