Implement and test a supports_feature() method to directly test for supported featues on EntityCapabilites

This commit is contained in:
Stephan Erb 2009-10-25 22:46:45 +01:00
parent ca03f88fc3
commit 396a2c603d
2 changed files with 28 additions and 5 deletions

View File

@ -58,10 +58,18 @@ class AbstractEntityCapabilities(object):
Query will only be sent if the data is not already cached.
'''
q = self._lookup_in_cache()
if q and q.queried == 0:
if q.queried == 0:
self._discover(connection, jid)
q.queried = 1
def supports_feature(self, feature):
''' Returns true if these capabilities contain the given feature '''
features = self._lookup_in_cache().features
if feature in features or features == []:
return True
else:
return False
def _discover(self, connection, jid):
''' To be implemented by subclassess '''
@ -108,8 +116,11 @@ class NullEntityCapabilities(AbstractEntityCapabilities):
Assumes everything is supported.
'''
def _lookup_in_cache(self):
return None
def query_client_of_jid_if_unknown(self, connection, jid):
pass
def supports_feature(self, feature):
return True
class CapsCache(object):

View File

@ -136,9 +136,21 @@ class TestEntityCapabilities(CommonCapsTest):
connection.mockCheckCall(0, "discoverInfo", 'test@gajim.org',
'http://gajim.org#RNzJvJnTWqczirzu+YF4V8am9ro=')
def test_is_supported(self):
self.assertTrue(self.entity.supports_feature(self.chatstates),
msg="Assume everything is supported, if we don't have caps")
self.cc.initialize_from_db()
self.assertFalse(self.entity.supports_feature(self.chatstates),
msg="Must return false on unsupported feature")
self.assertTrue(self.entity.supports_feature(self.muc),
msg="Must return True on supported feature")
class TestOldEntityCapabilities(TestEntityCapabilities):
class TestOldEntityCapabilities(TestEntityCapabilities):
def setUp(self):
TestEntityCapabilities.setUp(self)