2009-01-11 14:49:03 +01:00
|
|
|
'''
|
|
|
|
Tests for capabilities and the capabilities cache
|
|
|
|
'''
|
2008-06-12 05:56:47 +02:00
|
|
|
import unittest
|
|
|
|
|
2008-08-09 02:24:08 +02:00
|
|
|
import lib
|
|
|
|
lib.setup_env()
|
2008-06-12 05:56:47 +02:00
|
|
|
|
|
|
|
from common import gajim
|
|
|
|
from common import xmpp
|
2008-08-27 09:49:11 +02:00
|
|
|
from common import helpers
|
2008-06-12 05:56:47 +02:00
|
|
|
|
|
|
|
from common.caps import CapsCache
|
|
|
|
|
|
|
|
from mock import Mock
|
|
|
|
|
|
|
|
class MockLogger(Mock):
|
|
|
|
def __init__(self, *args):
|
|
|
|
Mock.__init__(self, *args)
|
|
|
|
|
|
|
|
class TestCapsCache(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.logger = MockLogger()
|
|
|
|
self.cc = CapsCache(self.logger)
|
|
|
|
|
2008-08-27 09:49:11 +02:00
|
|
|
self.caps_method = 'sha-1'
|
|
|
|
self.caps_hash = 'zaQfb22o0UCwYDIk8KZOnoZTnrs='
|
|
|
|
self.caps = (self.caps_method, self.caps_hash)
|
|
|
|
self.identity = {'category': 'client', 'type': 'pc'}
|
2008-06-12 05:56:47 +02:00
|
|
|
|
2008-08-27 09:49:11 +02:00
|
|
|
self.muc = 'http://jabber.org/protocol/muc'
|
|
|
|
self.chatstates = 'http://jabber.org/protocol/chatstates'
|
2008-06-12 05:56:47 +02:00
|
|
|
|
2008-08-27 09:49:11 +02:00
|
|
|
self.identities = [self.identity]
|
|
|
|
self.features = [self.muc]
|
2008-06-12 05:56:47 +02:00
|
|
|
|
2008-08-27 09:49:11 +02:00
|
|
|
def test_examples(self):
|
|
|
|
'''tests the examples given in common/caps.py'''
|
2008-06-12 05:56:47 +02:00
|
|
|
|
2008-08-27 09:49:11 +02:00
|
|
|
self.cc[self.caps].identities = self.identities
|
|
|
|
self.cc[self.caps].features = self.features
|
2008-06-12 05:56:47 +02:00
|
|
|
|
2008-08-27 09:49:11 +02:00
|
|
|
self.assert_(self.muc in self.cc[self.caps].features)
|
|
|
|
self.assert_(self.chatstates not in self.cc[self.caps].features)
|
|
|
|
|
|
|
|
id = self.cc[self.caps].identities
|
2008-06-12 05:56:47 +02:00
|
|
|
|
|
|
|
self.assertEqual(1, len(id))
|
|
|
|
|
|
|
|
id = id[0]
|
|
|
|
self.assertEqual('client', id['category'])
|
|
|
|
self.assertEqual('pc', id['type'])
|
|
|
|
|
2008-08-27 09:49:11 +02:00
|
|
|
def test_hash(self):
|
|
|
|
'''tests the hash computation'''
|
|
|
|
computed_hash = helpers.compute_caps_hash(self.identities, self.features)
|
|
|
|
|
|
|
|
self.assertEqual(self.caps_hash, computed_hash)
|
|
|
|
|
2008-06-12 05:56:47 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
2008-07-29 21:49:31 +02:00
|
|
|
|
2008-08-09 02:24:08 +02:00
|
|
|
# vim: se ts=3:
|