Changeset 160:33ef849a77d8 for wokkel/test/test_muc.py
- Timestamp:
- Jan 8, 2012, 9:26:02 AM (11 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/test/test_muc.py
r157 r160 43 43 44 44 45 class StatusCodeTest(unittest.TestCase): 46 """ 47 Tests for L{muc.STATUS_CODE}. 48 """ 49 50 def test_lookupByValue(self): 51 """ 52 The registered MUC status codes map to STATUS_CODE value constants. 53 54 Note: the identifiers used in the dictionary of status codes are 55 borrowed from U{XEP-0306<http://xmpp.org/extensions/xep-0306.html>} 56 that defines Extensible Status Conditions for Multi-User Chat. If this 57 specification is implemented itself, the dictionary could move there. 58 """ 59 codes = { 60 100: 'realjid-public', 61 101: 'affiliation-changed', 62 102: 'unavailable-shown', 63 103: 'unavailable-not-shown', 64 104: 'configuration-changed', 65 110: 'self-presence', 66 170: 'logging-enabled', 67 171: 'logging-disabled', 68 172: 'non-anonymous', 69 173: 'semi-anonymous', 70 174: 'fully-anonymous', 71 201: 'room-created', 72 210: 'nick-assigned', 73 301: 'banned', 74 303: 'new-nick', 75 307: 'kicked', 76 321: 'removed-affiliation', 77 322: 'removed-membership', 78 332: 'removed-shutdown', 79 } 80 81 for code, condition in codes.iteritems(): 82 constantName = condition.replace('-', '_').upper() 83 self.assertEqual(getattr(muc.STATUS_CODE, constantName), 84 muc.STATUS_CODE.lookupByValue(code)) 85 86 87 88 class StatusesTest(unittest.TestCase): 89 """ 90 Tests for L{muc.Statuses}. 91 """ 92 93 def setUp(self): 94 self.mucStatuses = muc.Statuses() 95 self.mucStatuses.add(muc.STATUS_CODE.SELF_PRESENCE) 96 self.mucStatuses.add(muc.STATUS_CODE.ROOM_CREATED) 97 98 99 def test_interface(self): 100 """ 101 Instances of L{Statuses} provide L{iwokkel.IMUCStatuses}. 102 """ 103 verify.verifyObject(iwokkel.IMUCStatuses, self.mucStatuses) 104 105 106 def test_contains(self): 107 """ 108 The status contained are 'in' the container. 109 """ 110 self.assertIn(muc.STATUS_CODE.SELF_PRESENCE, self.mucStatuses) 111 self.assertIn(muc.STATUS_CODE.ROOM_CREATED, self.mucStatuses) 112 self.assertNotIn(muc.STATUS_CODE.NON_ANONYMOUS, self.mucStatuses) 113 114 115 def test_iter(self): 116 """ 117 All statuses can be iterated over. 118 """ 119 statuses = set() 120 for status in self.mucStatuses: 121 statuses.add(status) 122 123 self.assertEqual(set([muc.STATUS_CODE.SELF_PRESENCE, 124 muc.STATUS_CODE.ROOM_CREATED]), statuses) 125 126 127 def test_len(self): 128 """ 129 The number of items in this container is returned by C{__len__}. 130 """ 131 self.assertEqual(2, len(self.mucStatuses)) 132 133 134 45 135 class GroupChatTest(unittest.TestCase): 46 136 """ 47 Tests for {muc.GroupChat}.137 Tests for L{muc.GroupChat}. 48 138 """ 49 139 … … 121 211 122 212 213 123 214 class UserPresenceTest(unittest.TestCase): 124 215 """ … … 126 217 """ 127 218 128 129 def test_toElementUnknownChild(self): 219 def test_fromElementNoUserElement(self): 220 """ 221 Without user element, all associated attributes are None. 222 """ 223 xml = """ 224 <presence from='coven@chat.shakespeare.lit/thirdwitch' 225 id='026B3509-2CCE-4D69-96D6-25F41FFDC408' 226 to='hag66@shakespeare.lit/pda'> 227 </presence> 228 """ 229 230 element = parseXml(xml) 231 presence = muc.UserPresence.fromElement(element) 232 233 self.assertIdentical(None, presence.affiliation) 234 self.assertIdentical(None, presence.role) 235 self.assertIdentical(None, presence.entity) 236 self.assertIdentical(None, presence.nick) 237 self.assertEqual(0, len(presence.mucStatuses)) 238 239 240 def test_fromElementUnknownChild(self): 130 241 """ 131 242 Unknown child elements are ignored. … … 144 255 presence = muc.UserPresence.fromElement(element) 145 256 146 self.assert Identical(None, presence.statusCodes)147 148 149 def test_ toElementStatusOne(self):257 self.assertEqual(0, len(presence.mucStatuses)) 258 259 260 def test_fromElementStatusOne(self): 150 261 """ 151 262 Status codes are extracted. … … 165 276 presence = muc.UserPresence.fromElement(element) 166 277 167 self.assertIn( 110, presence.statusCodes)168 169 170 def test_ toElementStatusMultiple(self):278 self.assertIn(muc.STATUS_CODE.SELF_PRESENCE, presence.mucStatuses) 279 280 281 def test_fromElementStatusMultiple(self): 171 282 """ 172 283 Multiple status codes are all extracted. … … 187 298 presence = muc.UserPresence.fromElement(element) 188 299 189 self.assertIn( 110, presence.statusCodes)190 self.assertIn( 100, presence.statusCodes)191 192 193 def test_ toElementStatusEmpty(self):300 self.assertIn(muc.STATUS_CODE.SELF_PRESENCE, presence.mucStatuses) 301 self.assertIn(muc.STATUS_CODE.REALJID_PUBLIC, presence.mucStatuses) 302 303 304 def test_fromElementStatusEmpty(self): 194 305 """ 195 306 Empty status elements are ignored. … … 209 320 presence = muc.UserPresence.fromElement(element) 210 321 211 self.assert Identical(None, presence.statusCodes)212 213 214 def test_ toElementStatusBad(self):322 self.assertEqual(0, len(presence.mucStatuses)) 323 324 325 def test_fromElementStatusBad(self): 215 326 """ 216 327 Bad status codes are ignored. … … 230 341 presence = muc.UserPresence.fromElement(element) 231 342 232 self.assert Identical(None, presence.statusCodes)233 234 235 def test_ toElementStatusUnknown(self):236 """ 237 Unknown status codes are still recorded in C{statusCodes}.343 self.assertEqual(0, len(presence.mucStatuses)) 344 345 346 def test_fromElementStatusUnknown(self): 347 """ 348 Unknown status codes are not recorded in C{mucStatuses}. 238 349 """ 239 350 xml = """ … … 251 362 presence = muc.UserPresence.fromElement(element) 252 363 253 self.assert In(999, presence.statusCodes)254 255 256 def test_ toElementItem(self):364 self.assertEqual(0, len(presence.mucStatuses)) 365 366 367 def test_fromElementItem(self): 257 368 """ 258 369 Item attributes are parsed properly.
Note: See TracChangeset
for help on using the changeset viewer.