Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: third_party/twisted_8_1/twisted/words/test/test_jabberjid.py

Issue 12261012: Remove third_party/twisted_8_1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (c) 2001-2008 Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 Tests for L{twisted.words.protocols.jabber.jid}.
6 """
7
8 from twisted.trial import unittest
9
10 from twisted.words.protocols.jabber import jid
11
12 class JIDParsingTest(unittest.TestCase):
13 def test_parse(self):
14 """
15 Test different forms of JIDs.
16 """
17 # Basic forms
18 self.assertEquals(jid.parse("user@host/resource"),
19 ("user", "host", "resource"))
20 self.assertEquals(jid.parse("user@host"),
21 ("user", "host", None))
22 self.assertEquals(jid.parse("host"),
23 (None, "host", None))
24 self.assertEquals(jid.parse("host/resource"),
25 (None, "host", "resource"))
26
27 # More interesting forms
28 self.assertEquals(jid.parse("foo/bar@baz"),
29 (None, "foo", "bar@baz"))
30 self.assertEquals(jid.parse("boo@foo/bar@baz"),
31 ("boo", "foo", "bar@baz"))
32 self.assertEquals(jid.parse("boo@foo/bar/baz"),
33 ("boo", "foo", "bar/baz"))
34 self.assertEquals(jid.parse("boo/foo@bar@baz"),
35 (None, "boo", "foo@bar@baz"))
36 self.assertEquals(jid.parse("boo/foo/bar"),
37 (None, "boo", "foo/bar"))
38 self.assertEquals(jid.parse("boo//foo"),
39 (None, "boo", "/foo"))
40
41 def test_noHost(self):
42 """
43 Test for failure on no host part.
44 """
45 self.assertRaises(jid.InvalidFormat, jid.parse, "user@")
46
47 def test_doubleAt(self):
48 """
49 Test for failure on double @ signs.
50
51 This should fail because @ is not a valid character for the host
52 part of the JID.
53 """
54 self.assertRaises(jid.InvalidFormat, jid.parse, "user@@host")
55
56 def test_multipleAt(self):
57 """
58 Test for failure on two @ signs.
59
60 This should fail because @ is not a valid character for the host
61 part of the JID.
62 """
63 self.assertRaises(jid.InvalidFormat, jid.parse, "user@host@host")
64
65 # Basic tests for case mapping. These are fallback tests for the
66 # prepping done in twisted.words.protocols.jabber.xmpp_stringprep
67
68 def test_prepCaseMapUser(self):
69 """
70 Test case mapping of the user part of the JID.
71 """
72 self.assertEquals(jid.prep("UsEr", "host", "resource"),
73 ("user", "host", "resource"))
74
75 def test_prepCaseMapHost(self):
76 """
77 Test case mapping of the host part of the JID.
78 """
79 self.assertEquals(jid.prep("user", "hoST", "resource"),
80 ("user", "host", "resource"))
81
82 def test_prepNoCaseMapResource(self):
83 """
84 Test no case mapping of the resourcce part of the JID.
85 """
86 self.assertEquals(jid.prep("user", "hoST", "resource"),
87 ("user", "host", "resource"))
88 self.assertNotEquals(jid.prep("user", "host", "Resource"),
89 ("user", "host", "resource"))
90
91 class JIDTest(unittest.TestCase):
92
93 def test_noneArguments(self):
94 """
95 Test that using no arguments raises an exception.
96 """
97 self.assertRaises(RuntimeError, jid.JID)
98
99 def test_attributes(self):
100 """
101 Test that the attributes correspond with the JID parts.
102 """
103 j = jid.JID("user@host/resource")
104 self.assertEquals(j.user, "user")
105 self.assertEquals(j.host, "host")
106 self.assertEquals(j.resource, "resource")
107
108 def test_userhost(self):
109 """
110 Test the extraction of the bare JID.
111 """
112 j = jid.JID("user@host/resource")
113 self.assertEquals("user@host", j.userhost())
114
115 def test_userhostOnlyHost(self):
116 """
117 Test the extraction of the bare JID of the full form host/resource.
118 """
119 j = jid.JID("host/resource")
120 self.assertEquals("host", j.userhost())
121
122 def test_userhostJID(self):
123 """
124 Test getting a JID object of the bare JID.
125 """
126 j1 = jid.JID("user@host/resource")
127 j2 = jid.internJID("user@host")
128 self.assertIdentical(j2, j1.userhostJID())
129
130 def test_userhostJIDNoResource(self):
131 """
132 Test getting a JID object of the bare JID when there was no resource.
133 """
134 j = jid.JID("user@host")
135 self.assertIdentical(j, j.userhostJID())
136
137 def test_fullHost(self):
138 """
139 Test giving a string representation of the JID with only a host part.
140 """
141 j = jid.JID(tuple=(None, 'host', None))
142 self.assertEqual('host', j.full())
143
144 def test_fullHostResource(self):
145 """
146 Test giving a string representation of the JID with host, resource.
147 """
148 j = jid.JID(tuple=(None, 'host', 'resource'))
149 self.assertEqual('host/resource', j.full())
150
151 def test_fullUserHost(self):
152 """
153 Test giving a string representation of the JID with user, host.
154 """
155 j = jid.JID(tuple=('user', 'host', None))
156 self.assertEqual('user@host', j.full())
157
158 def test_fullAll(self):
159 """
160 Test giving a string representation of the JID.
161 """
162 j = jid.JID(tuple=('user', 'host', 'resource'))
163 self.assertEqual('user@host/resource', j.full())
164
165 def test_equality(self):
166 """
167 Test JID equality.
168 """
169 j1 = jid.JID("user@host/resource")
170 j2 = jid.JID("user@host/resource")
171 self.assertNotIdentical(j1, j2)
172 self.assertEqual(j1, j2)
173
174 def test_equalityWithNonJIDs(self):
175 """
176 Test JID equality.
177 """
178 j = jid.JID("user@host/resource")
179 self.assertFalse(j == 'user@host/resource')
180
181 def test_inequality(self):
182 """
183 Test JID inequality.
184 """
185 j1 = jid.JID("user1@host/resource")
186 j2 = jid.JID("user2@host/resource")
187 self.assertNotEqual(j1, j2)
188
189 def test_inequalityWithNonJIDs(self):
190 """
191 Test JID equality.
192 """
193 j = jid.JID("user@host/resource")
194 self.assertNotEqual(j, 'user@host/resource')
195
196 def test_hashable(self):
197 """
198 Test JID hashability.
199 """
200 j1 = jid.JID("user@host/resource")
201 j2 = jid.JID("user@host/resource")
202 self.assertEqual(hash(j1), hash(j2))
203
204 def test_unicode(self):
205 """
206 Test unicode representation of JIDs.
207 """
208 j = jid.JID(tuple=('user', 'host', 'resource'))
209 self.assertEquals("user@host/resource", unicode(j))
210
211 def test_repr(self):
212 """
213 Test representation of JID objects.
214 """
215 j = jid.JID(tuple=('user', 'host', 'resource'))
216 self.assertEquals("JID(u'user@host/resource')", repr(j))
217
218 class InternJIDTest(unittest.TestCase):
219 def test_identity(self):
220 """
221 Test that two interned JIDs yield the same object.
222 """
223 j1 = jid.internJID("user@host")
224 j2 = jid.internJID("user@host")
225 self.assertIdentical(j1, j2)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698