diff options
author | lovetox <philipp@hoerist.com> | 2020-04-18 12:28:13 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2020-04-18 12:45:32 +0300 |
commit | 488bcbd73936dbf9e9576e172980d7ec61d5a7c3 (patch) | |
tree | 52494a47f186d976f1b8332e26a6385d4a84b8ff /test | |
parent | bdf630ce9c2e425d0812fdc0f41455c9158972d6 (diff) |
Rewrite CapsCache
- Simplify implementation
- Add cached entrys from the CapsCache to the DiscoInfo cache when
receiving presence. This allows us to use get_last_disco_info() for all
contacts (Group Chats and Roster Contacts)
- Remove old/broken tests
Diffstat (limited to 'test')
-rw-r--r-- | test/broken/no_gui/test_protocol_caps.py | 55 | ||||
-rw-r--r-- | test/gtk/htmltextview.py | 2 | ||||
-rw-r--r-- | test/no_gui/unit/test_account.py | 19 | ||||
-rw-r--r-- | test/no_gui/unit/test_caps_cache.py | 149 | ||||
-rw-r--r-- | test/no_gui/unit/test_contacts.py | 117 |
5 files changed, 0 insertions, 342 deletions
diff --git a/test/broken/no_gui/test_protocol_caps.py b/test/broken/no_gui/test_protocol_caps.py deleted file mode 100644 index eef096a43..000000000 --- a/test/broken/no_gui/test_protocol_caps.py +++ /dev/null @@ -1,55 +0,0 @@ -''' -Tests for caps network coding -''' - -import unittest -from unittest.mock import MagicMock - -import nbxmpp - -from gajim.common import app -from gajim.common import nec -from gajim.common import ged -from gajim.common import caps_cache -from gajim.common.modules.caps import Caps - - -class TestConnectionCaps(unittest.TestCase): - - def setUp(self): - app.contacts.add_account('account') - contact = app.contacts.create_contact( - 'user@server.com', 'account', resource='a') - app.contacts.add_contact('account', contact) - - app.nec = nec.NetworkEventsController() - app.ged.register_event_handler( - 'caps-presence-received', ged.GUI2, - self._nec_caps_presence_received) - - self.module = Caps(MagicMock()) - self.module._account = 'account' - self.module._capscache = MagicMock() - - def tearDown(self): - app.contacts.remove_account('account') - - def _nec_caps_presence_received(self, obj): - self.assertTrue( - isinstance(obj.client_caps, caps_cache.ClientCaps), - msg="On receive of valid caps, ClientCaps should be returned") - - def test_capsPresenceCB(self): - fjid = "user@server.com/a" - - xml = """<presence from='user@server.com/a' to='%s' id='123'> - <c node='http://gajim.org' ver='pRCD6cgQ4SDqNMCjdhRV6TECx5o=' - hash='sha-1' xmlns='http://jabber.org/protocol/caps'/> - </presence> - """ % (fjid) - msg = nbxmpp.protocol.Presence(node=nbxmpp.simplexml.XML2Node(xml)) - self.module._presence_received(None, msg) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/gtk/htmltextview.py b/test/gtk/htmltextview.py index a10692542..cdc28fa51 100644 --- a/test/gtk/htmltextview.py +++ b/test/gtk/htmltextview.py @@ -7,13 +7,11 @@ from gi.repository import Gtk from gajim.common import app from gajim.common import configpaths configpaths.init() -from gajim.common import caps_cache from gajim.common.helpers import AdditionalDataDict from gajim.conversation_textview import ConversationTextview from gajim.gui_interface import Interface -caps_cache.capscache = MagicMock() app.plugin_manager = MagicMock() app.logger = MagicMock() app.cert_store = MagicMock() diff --git a/test/no_gui/unit/test_account.py b/test/no_gui/unit/test_account.py deleted file mode 100644 index 75d94542e..000000000 --- a/test/no_gui/unit/test_account.py +++ /dev/null @@ -1,19 +0,0 @@ -''' -Tests for Account classes -''' -import unittest - -from gajim.common.account import Account - - -class Test(unittest.TestCase): - - def testInstantiate(self): - account = Account(name='MyAcc', contacts=None, gc_contacts=None) - - self.assertEqual('MyAcc', account.name) - self.assertTrue(account.gc_contacts is None) - self.assertTrue(account.contacts is None) - -if __name__ == "__main__": - unittest.main() diff --git a/test/no_gui/unit/test_caps_cache.py b/test/no_gui/unit/test_caps_cache.py deleted file mode 100644 index bf086761a..000000000 --- a/test/no_gui/unit/test_caps_cache.py +++ /dev/null @@ -1,149 +0,0 @@ -''' -Tests for capabilities and the capabilities cache -''' -import unittest -from unittest.mock import MagicMock, Mock - -from nbxmpp import NS_MUC, NS_PING, NS_XHTML_IM, NS_JINGLE_FILE_TRANSFER_5 -from nbxmpp.structs import DiscoIdentity -from nbxmpp.structs import DiscoInfo -from gajim.common import caps_cache as caps -from gajim.common.structs import CapsData - - -class CommonCapsTest(unittest.TestCase): - - def setUp(self): - self.caps_method = 'sha-1' - self.caps_hash = 'm3P2WeXPMGVH2tZPe7yITnfY0Dw=' - self.client_caps = (self.caps_method, self.caps_hash) - - self.node = "http://gajim.org" - self.identity = DiscoIdentity(category='client', - type='pc', - name='Gajim') - - self.identities = [self.identity] - self.features = [NS_MUC, NS_XHTML_IM, NS_JINGLE_FILE_TRANSFER_5] - - # Simulate a filled db - db_caps_cache = { - (self.caps_method, self.caps_hash): CapsData(self.identities, self.features, []), - ('old', self.node + '#' + self.caps_hash): CapsData(self.identities, self.features, []) - } - - self.logger = Mock() - self.logger.load_caps_data = Mock(return_value=db_caps_cache) - - self.cc = caps.CapsCache(self.logger) - caps.capscache = self.cc - - -class TestCapsCache(CommonCapsTest): - - def test_set_retrieve(self): - ''' Test basic set / retrieve cycle ''' - - self.cc[self.client_caps].identities = self.identities - self.cc[self.client_caps].features = self.features - - self.assertTrue(NS_MUC in self.cc[self.client_caps].features) - self.assertTrue(NS_PING not in self.cc[self.client_caps].features) - - identities = self.cc[self.client_caps].identities - - self.assertEqual(1, len(identities)) - - identity = identities[0] - self.assertEqual('client', identity.category) - self.assertEqual('pc', identity.type) - - def test_set_and_store(self): - ''' Test client_caps update gets logged into db ''' - - disco_info = DiscoInfo(None, self.identities, self.features, []) - - item = self.cc[self.client_caps] - item.set_and_store(disco_info) - - self.logger.add_caps_entry.assert_called_once_with(self.caps_method, - self.caps_hash, - disco_info) - - def test_initialize_from_db(self): - ''' Read cashed dummy data from db ''' - self.assertEqual(self.cc[self.client_caps].status, caps.NEW) - self.cc.initialize_from_db() - self.assertEqual(self.cc[self.client_caps].status, caps.CACHED) - - def test_preload_triggering_query(self): - ''' Make sure that preload issues a disco ''' - connection = MagicMock() - client_caps = caps.ClientCaps(self.caps_hash, self.node, self.caps_method) - - self.cc.query_client_of_jid_if_unknown( - connection, "test@gajim.org", client_caps) - - self.assertEqual(1, connection.get_module('Discovery').disco_contact.call_count) - - def test_no_preload_query_if_cashed(self): - ''' Preload must not send a query if the data is already cached ''' - connection = MagicMock() - client_caps = caps.ClientCaps(self.caps_hash, self.node, self.caps_method) - - self.cc.initialize_from_db() - self.cc.query_client_of_jid_if_unknown( - connection, "test@gajim.org", client_caps) - - self.assertEqual(0, connection.get_module('Discovery').disco_contact.call_count) - - -class TestClientCaps(CommonCapsTest): - - def setUp(self): - CommonCapsTest.setUp(self) - self.client_caps = caps.ClientCaps(self.caps_hash, self.node, self.caps_method) - - def test_query_by_get_discover_strategy(self): - ''' Client must be queried if the data is unkown ''' - connection = MagicMock() - discover = self.client_caps.get_discover_strategy() - discover(connection, "test@gajim.org") - connection.get_module('Discovery').disco_contact.assert_called_once_with( - 'test@gajim.org', 'http://gajim.org#m3P2WeXPMGVH2tZPe7yITnfY0Dw=') - - def test_client_supports(self): - self.assertTrue(caps.client_supports(self.client_caps, NS_PING), - msg="Assume supported, if we don't have caps") - - self.assertFalse(caps.client_supports(self.client_caps, NS_JINGLE_FILE_TRANSFER_5), - msg="Must not assume blacklisted feature is supported on default") - - self.cc.initialize_from_db() - - self.assertFalse(caps.client_supports(self.client_caps, NS_PING), - msg="Must return false on unsupported feature") - - self.assertTrue(caps.client_supports(self.client_caps, NS_XHTML_IM), - msg="Must return True on supported feature") - - self.assertTrue(caps.client_supports(self.client_caps, NS_MUC), - msg="Must return True on supported feature") - - -class TestOldClientCaps(TestClientCaps): - - def setUp(self): - TestClientCaps.setUp(self) - self.client_caps = caps.OldClientCaps(self.caps_hash, self.node) - - def test_query_by_get_discover_strategy(self): - ''' Client must be queried if the data is unknown ''' - connection = MagicMock() - discover = self.client_caps.get_discover_strategy() - discover(connection, "test@gajim.org") - - connection.get_module('Discovery').disco_contact.assert_called_once_with('test@gajim.org') - -if __name__ == '__main__': - unittest.main() diff --git a/test/no_gui/unit/test_contacts.py b/test/no_gui/unit/test_contacts.py deleted file mode 100644 index b3233a422..000000000 --- a/test/no_gui/unit/test_contacts.py +++ /dev/null @@ -1,117 +0,0 @@ -''' -Test for Contact, GC_Contact and Contacts -''' -import unittest -from nbxmpp import NS_MUC - -from gajim.common.contacts import CommonContact, Contact, GC_Contact, LegacyContactsAPI - -from gajim.common import caps_cache - -class TestCommonContact(unittest.TestCase): - - def setUp(self): - self.contact = CommonContact( - jid='', account="", resource='', show='', presence=None, - status='', name='', chatstate=None, client_caps=None) - - def test_default_client_supports(self): - ''' - Test the caps support method of contacts. - See test_caps for more enhanced tests. - ''' - caps_cache.capscache = caps_cache.CapsCache() - self.assertTrue(self.contact.supports(NS_MUC), - msg="Must not backtrace on simple check for supported feature") - - self.contact.client_caps = caps_cache.NullClientCaps() - - self.assertTrue(self.contact.supports(NS_MUC), - msg="Must not backtrace on simple check for supported feature") - - -class TestContact(TestCommonContact): - - def setUp(self): - TestCommonContact.setUp(self) - self.contact = Contact(jid="test@gajim.org", account="account") - - def test_attributes_available(self): - '''This test supports the migration from the old to the new contact - domain model by smoke testing that no attribute values are lost''' - - attributes = ["jid", "resource", "show", "status", "name", - "chatstate", "client_caps", "priority", "sub"] - for attr in attributes: - self.assertTrue(hasattr(self.contact, attr), msg="expected: " + attr) - - -class TestGC_Contact(TestCommonContact): - - def setUp(self): - TestCommonContact.setUp(self) - self.contact = GC_Contact(room_jid="confernce@gajim.org", account="account") - - def test_attributes_available(self): - '''This test supports the migration from the old to the new contact - domain model by asserting no attributes have been lost''' - - attributes = ["jid", "resource", "show", "status", "name", - "chatstate", "client_caps", "role", "room_jid"] - for attr in attributes: - self.assertTrue(hasattr(self.contact, attr), msg="expected: " + attr) - - -class TestContacts(unittest.TestCase): - - def setUp(self): - self.contacts = LegacyContactsAPI() - - def test_create_add_get_contact(self): - jid = 'test@gajim.org' - account = "account" - - contact = self.contacts.create_contact(jid=jid, account=account) - self.contacts.add_contact(account, contact) - - retrieved_contact = self.contacts.get_contact(account, jid) - self.assertEqual(contact, retrieved_contact, "Contact must be known") - - self.contacts.remove_contact(account, contact) - - retrieved_contact = self.contacts.get_contact(account, jid) - self.assertNotEqual(contact, retrieved_contact, - msg="Contact must not be known any longer") - - - def test_copy_contact(self): - jid = 'test@gajim.org' - account = "account" - - contact = self.contacts.create_contact(jid=jid, account=account) - copy = self.contacts.copy_contact(contact) - self.assertFalse(contact is copy, msg="Must not be the same") - - # Not yet implemented to remain backwart compatible - # self.assertEqual(contact, copy, msg="Must be equal") - - def test_legacy_contacts_from_groups(self): - jid1 = "test1@gajim.org" - jid2 = "test2@gajim.org" - account = "account" - group = "GroupA" - - contact1 = self.contacts.create_contact(jid=jid1, account=account, - groups=[group]) - self.contacts.add_contact(account, contact1) - - contact2 = self.contacts.create_contact(jid=jid2, account=account, - groups=[group]) - self.contacts.add_contact(account, contact2) - - self.assertEqual(2, len(self.contacts.get_contacts_from_group(account, group))) - self.assertEqual(0, len(self.contacts.get_contacts_from_group(account, ''))) - - -if __name__ == "__main__": - unittest.main() |