diff options
author | Stephan Erb <steve-e@h3c.de> | 2009-10-26 00:32:18 +0300 |
---|---|---|
committer | Stephan Erb <steve-e@h3c.de> | 2009-10-26 00:32:18 +0300 |
commit | ca03f88fc3ec9e28c873784626f3fe54df82c603 (patch) | |
tree | 7cb9cbb998308f6327dd0ec642b89dac62fbe006 /test/test_caps.py | |
parent | 499f3dff615e3a3a581412a4db2cc0c860d8f0a5 (diff) |
Write tests and fix the caps preload alternative on the EntityCapabilities.
Diffstat (limited to 'test/test_caps.py')
-rw-r--r-- | test/test_caps.py | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/test/test_caps.py b/test/test_caps.py index 03fa9d9ca..ecf430314 100644 --- a/test/test_caps.py +++ b/test/test_caps.py @@ -8,7 +8,7 @@ lib.setup_env() from common import helpers from common.contacts import Contact -from common.caps import CapsCache +from common.caps import CapsCache, EntityCapabilities, OldEntityCapabilities from mock import Mock @@ -28,21 +28,18 @@ class CommonCapsTest(unittest.TestCase): self.identities = [self.identity] self.features = [self.muc] - - -class TestCapsCache(CommonCapsTest): - - def setUp(self): - CommonCapsTest.setUp(self) - + # Simulate a filled db db_caps_cache = [ (self.caps_method, self.caps_hash, self.identities, self.features), - (self.caps_method, self.caps_hash, self.identities, self.features)] + ('old', self.node + '#' + self.caps_hash, self.identities, self.features)] self.logger = Mock(returnValues={"iter_caps_data":db_caps_cache}) self.cc = CapsCache(self.logger) - + + +class TestCapsCache(CommonCapsTest): + def test_set_retrieve(self): ''' Test basic set / retrieve cycle ''' @@ -117,6 +114,51 @@ class TestCapsCache(CommonCapsTest): self.assertEqual(self.caps_hash, computed_hash) +class TestEntityCapabilities(CommonCapsTest): + + def setUp(self): + CommonCapsTest.setUp(self) + self.entity = EntityCapabilities(self.cc, self.caps_hash, self.node, + self.caps_method) + + def test_no_query_client_of_jid(self): + ''' Client must not be queried if the data is already cached ''' + connection = Mock() + self.cc.initialize_from_db() + self.entity.query_client_of_jid_if_unknown(connection, "test@gajim.org") + + self.assertEqual(0, len(connection.mockGetAllCalls())) + + def test_query_client_of_jid_if_unknown(self): + ''' Client must be queried if the data is unkown ''' + connection = Mock() + self.entity.query_client_of_jid_if_unknown(connection, "test@gajim.org") + + connection.mockCheckCall(0, "discoverInfo", 'test@gajim.org', + 'http://gajim.org#RNzJvJnTWqczirzu+YF4V8am9ro=') + + +class TestOldEntityCapabilities(TestEntityCapabilities): + + def setUp(self): + TestEntityCapabilities.setUp(self) + self.entity = OldEntityCapabilities(self.cc, self.caps_hash, self.node) + + def test_no_query_client_of_jid(self): + ''' Client must not be queried if the data is already cached ''' + connection = Mock() + self.cc.initialize_from_db() + self.entity.query_client_of_jid_if_unknown(connection, "test@gajim.org") + + self.assertEqual(0, len(connection.mockGetAllCalls())) + + def test_query_client_of_jid_if_unknown(self): + ''' Client must be queried if the data is unkown ''' + connection = Mock() + self.entity.query_client_of_jid_if_unknown(connection, "test@gajim.org") + + connection.mockCheckCall(0, "discoverInfo", "test@gajim.org") + if __name__ == '__main__': |