Skip to content
Snippets Groups Projects
Commit 396a2c60 authored by steve-e's avatar steve-e
Browse files

Implement and test a supports_feature() method to directly test for supported...

Implement and test a supports_feature() method to directly test for supported featues on EntityCapabilites
parent ca03f88f
No related branches found
No related tags found
No related merge requests found
......@@ -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):
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment