Write tests and fix the caps preload alternative on the EntityCapabilities.
This commit is contained in:
parent
499f3dff61
commit
ca03f88fc3
|
@ -58,9 +58,10 @@ class AbstractEntityCapabilities(object):
|
|||
Query will only be sent if the data is not already cached.
|
||||
'''
|
||||
q = self._lookup_in_cache()
|
||||
if q and q.query_status == q.NOT_QUERIED:
|
||||
q.query_status = q.QUERIED
|
||||
q._discover(connection, jid)
|
||||
if q and q.queried == 0:
|
||||
self._discover(connection, jid)
|
||||
q.queried = 1
|
||||
|
||||
|
||||
def _discover(self, connection, jid):
|
||||
''' To be implemented by subclassess '''
|
||||
|
@ -92,8 +93,8 @@ class OldEntityCapabilities(AbstractEntityCapabilities):
|
|||
def __init__(self, caps_cache, caps_hash, node):
|
||||
AbstractEntityCapabilities.__init__(self, caps_cache, caps_hash, node)
|
||||
|
||||
def _lookup_in_cache(self, caps_cache):
|
||||
return caps_cache[('old', self._node + '#' + self._hash)]
|
||||
def _lookup_in_cache(self):
|
||||
return self._caps_cache[('old', self._node + '#' + self._hash)]
|
||||
|
||||
def _discover(self, connection, jid):
|
||||
connection.discoverInfo(jid)
|
||||
|
|
|
@ -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]
|
||||
|
||||
# Simulate a filled db
|
||||
db_caps_cache = [
|
||||
(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 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)]
|
||||
self.logger = Mock(returnValues={"iter_caps_data":db_caps_cache})
|
||||
|
||||
self.cc = CapsCache(self.logger)
|
||||
|
||||
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__':
|
||||
|
|
Loading…
Reference in New Issue