| 1 | # tests for capabilities and the capabilities cache |
|---|
| 2 | import unittest |
|---|
| 3 | |
|---|
| 4 | import lib |
|---|
| 5 | lib.setup_env() |
|---|
| 6 | |
|---|
| 7 | from common import gajim |
|---|
| 8 | from common import xmpp |
|---|
| 9 | from common import helpers |
|---|
| 10 | |
|---|
| 11 | from common.caps import CapsCache |
|---|
| 12 | |
|---|
| 13 | from mock import Mock |
|---|
| 14 | |
|---|
| 15 | class MockLogger(Mock): |
|---|
| 16 | def __init__(self, *args): |
|---|
| 17 | Mock.__init__(self, *args) |
|---|
| 18 | |
|---|
| 19 | class TestCapsCache(unittest.TestCase): |
|---|
| 20 | def setUp(self): |
|---|
| 21 | self.logger = MockLogger() |
|---|
| 22 | self.cc = CapsCache(self.logger) |
|---|
| 23 | |
|---|
| 24 | self.caps_method = 'sha-1' |
|---|
| 25 | self.caps_hash = 'zaQfb22o0UCwYDIk8KZOnoZTnrs=' |
|---|
| 26 | self.caps = (self.caps_method, self.caps_hash) |
|---|
| 27 | self.identity = {'category': 'client', 'type': 'pc'} |
|---|
| 28 | |
|---|
| 29 | self.muc = 'http://jabber.org/protocol/muc' |
|---|
| 30 | self.chatstates = 'http://jabber.org/protocol/chatstates' |
|---|
| 31 | |
|---|
| 32 | self.identities = [self.identity] |
|---|
| 33 | self.features = [self.muc] |
|---|
| 34 | |
|---|
| 35 | def test_examples(self): |
|---|
| 36 | '''tests the examples given in common/caps.py''' |
|---|
| 37 | |
|---|
| 38 | self.cc[self.caps].identities = self.identities |
|---|
| 39 | self.cc[self.caps].features = self.features |
|---|
| 40 | |
|---|
| 41 | self.assert_(self.muc in self.cc[self.caps].features) |
|---|
| 42 | self.assert_(self.chatstates not in self.cc[self.caps].features) |
|---|
| 43 | |
|---|
| 44 | id = self.cc[self.caps].identities |
|---|
| 45 | |
|---|
| 46 | self.assertEqual(1, len(id)) |
|---|
| 47 | |
|---|
| 48 | id = id[0] |
|---|
| 49 | self.assertEqual('client', id['category']) |
|---|
| 50 | self.assertEqual('pc', id['type']) |
|---|
| 51 | |
|---|
| 52 | def test_hash(self): |
|---|
| 53 | '''tests the hash computation''' |
|---|
| 54 | computed_hash = helpers.compute_caps_hash(self.identities, self.features) |
|---|
| 55 | |
|---|
| 56 | self.assertEqual(self.caps_hash, computed_hash) |
|---|
| 57 | |
|---|
| 58 | if __name__ == '__main__': |
|---|
| 59 | unittest.main() |
|---|
| 60 | |
|---|
| 61 | # vim: se ts=3: |
|---|