Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Apitzsch <git@apitzsch.eu>2018-11-11 03:31:50 +0300
committerPhilipp Hörist <philipp@hoerist.com>2018-11-11 18:50:59 +0300
commit989926a680e7802e1b632846caa8e536bc813a29 (patch)
treed4907cd2057b2ee639626d3f7c3aaef19602815c /test/integration
parent522eec007dc1a2680b2fc3919f37028244ba57df (diff)
Restructure test
Diffstat (limited to 'test/integration')
-rw-r--r--test/integration/test_gui_event_integration.py221
-rw-r--r--test/integration/test_resolver.py13
-rw-r--r--test/integration/test_roster.py211
3 files changed, 6 insertions, 439 deletions
diff --git a/test/integration/test_gui_event_integration.py b/test/integration/test_gui_event_integration.py
deleted file mode 100644
index 150f2102a..000000000
--- a/test/integration/test_gui_event_integration.py
+++ /dev/null
@@ -1,221 +0,0 @@
-'''
-Tests for the miscellaneous functions scattered throughout gajim/gajim.py
-'''
-import unittest
-
-import lib
-lib.setup_env()
-
-import nbxmpp
-
-from gajim.common import gajim
-from gajim.common import contacts as contacts_module
-from gajim.common import caps_cache
-from gajim.gajim import Interface
-
-from gajim_mocks import *
-gajim.logger = MockLogger()
-
-Interface()
-
-import time
-from data import *
-
-from gajim import roster_window
-from gajim import plugins
-from gajim import notify
-
-class TestStatusChange(unittest.TestCase):
- '''tests gajim.py's incredibly complex presence handling'''
-
- def setUp(self):
-
- gajim.connections = {}
- gajim.contacts = contacts_module.LegacyContactsAPI()
- gajim.interface.roster = roster_window.RosterWindow()
- gajim.plugin_manager = plugins.PluginManager()
- gajim.logger = MockLogger()
- caps_cache.initialize(gajim.logger)
-
- for acc in contacts:
- gajim.connections[acc] = MockConnection(acc)
-
- gajim.interface.roster.fill_contacts_and_groups_dicts(contacts[acc],
- acc)
- gajim.interface.roster.add_account(acc)
- gajim.interface.roster.add_account_contacts(acc)
-
- self.assertEqual(0, len(notify.notifications))
-
- def tearDown(self):
- notify.notifications = []
- for acc in contacts:
- gajim.connections[acc].cleanup()
-
- def contact_comes_online(self, account, jid, resource, prio,
- should_popup=True):
- '''a remote contact comes online'''
- xml = """<presence from='%s/%s' id='123'><priority>%s</priority>
- <c node='http://gajim.org' ver='pRCD6cgQ4SDqNMCjdhRV6TECx5o='
- hash='sha-1' xmlns='http://jabber.org/protocol/caps'/>
- <status>I'm back!</status>
- </presence>
- """ % (jid, resource, prio)
- msg = nbxmpp.protocol.Presence(node=nbxmpp.simplexml.XML2Node(xml))
- gajim.connections[account]._presenceCB(None, msg)
-
- contact = None
- for c in gajim.contacts.get_contacts(account, jid):
- if c.resource == resource:
- contact = c
- break
-
- self.assertEqual('online', contact.show)
- self.assertEqual("I'm back!", contact.status)
- self.assertEqual(prio, contact.priority)
-
- # the most recent notification is that the contact connected
- if should_popup:
- self.assertEqual('Contact Signed In',
- notify.notifications[-1].popup_event_type)
- else:
- self.assertEqual('', notify.notifications[-1].popup_event_type)
-
- def contact_goes_offline(self, account, jid, resource, prio,
- still_exists = True):
- '''a remote contact goes offline.'''
- xml = """<presence type='unavailable' from='%s/%s' id='123'>
- <priority>%s</priority>
- <c node='http://gajim.org' ver='pRCD6cgQ4SDqNMCjdhRV6TECx5o='
- hash='sha-1' xmlns='http://jabber.org/protocol/caps'/>
- <status>Goodbye!</status>
- </presence>
- """ % (jid, resource, prio)
- msg = nbxmpp.protocol.Presence(node=nbxmpp.simplexml.XML2Node(xml))
- gajim.connections[account]._presenceCB(None, msg)
-
- contact = None
- for c in gajim.contacts.get_contacts(account, jid):
- if c.resource == resource:
- contact = c
- break
-
- if not still_exists:
- self.assertTrue(contact is None)
- return
-
- self.assertEqual('offline', contact.show)
- self.assertEqual('Goodbye!', contact.status)
- self.assertEqual(prio, contact.priority)
-
- self.assertEqual('Contact Signed Out',
- notify.notifications[-1].popup_event_type)
-
- def user_starts_chatting(self, jid, account, resource=None):
- '''the user opens a chat window and starts talking'''
- ctrl = MockChatControl(jid, account)
- win = MockWindow()
- win.new_tab(ctrl)
- gajim.interface.msg_win_mgr._windows['test'] = win
-
- if resource:
- jid = jid + '/' + resource
-
- # a basic session is started
- session = gajim.connections[account1].make_new_session(jid,
- '01234567890abcdef', cls=MockSession)
- ctrl.set_session(session)
-
- return ctrl
-
- def user_starts_esession(self, jid, resource, account):
- '''the user opens a chat window and starts an encrypted session'''
- ctrl = self.user_starts_chatting(jid, account, resource)
- ctrl.session.status = 'active'
- ctrl.session.enable_encryption = True
-
- return ctrl
-
- def test_contact_comes_online(self):
- jid = 'default1@gajim.org'
-
- # contact is offline initially
- contacts = gajim.contacts.get_contacts(account1, jid)
- self.assertEqual(1, len(contacts))
- self.assertEqual('offline', contacts[0].show)
- self.assertEqual('', contacts[0].status)
-
- self.contact_comes_online(account1, jid, 'lowprio', 1)
-
- def test_contact_goes_offline(self):
- jid = 'default1@gajim.org'
-
- self.contact_comes_online(account1, jid, 'lowprio', 1)
-
- ctrl = self.user_starts_chatting(jid, account1)
- orig_sess = ctrl.session
-
- self.contact_goes_offline(account1, jid, 'lowprio', 1)
-
- # session hasn't changed since we were talking to the bare jid
- self.assertEqual(orig_sess, ctrl.session)
-
- def test_two_resources_higher_comes_online(self):
- jid = 'default1@gajim.org'
-
- self.contact_comes_online(account1, jid, 'lowprio', 1)
-
- ctrl = self.user_starts_chatting(jid, account1)
-
- self.contact_comes_online(account1, jid, 'highprio', 50,
- should_popup=False)
-
- # old session was dropped
- self.assertEqual(None, ctrl.session)
-
- def test_two_resources_higher_goes_offline(self):
- jid = 'default1@gajim.org'
-
- self.contact_comes_online(account1, jid, 'lowprio', 1)
- self.contact_comes_online(account1, jid, 'highprio', 50,
- should_popup=False)
-
- ctrl = self.user_starts_chatting(jid, account1)
-
- self.contact_goes_offline(account1, jid, 'highprio', 50,
- still_exists=False)
-
- # old session was dropped
- self.assertEqual(None, ctrl.session)
-
- def test_two_resources_higher_comes_online_with_esession(self):
- jid = 'default1@gajim.org'
-
- self.contact_comes_online(account1, jid, 'lowprio', 1)
-
- ctrl = self.user_starts_esession(jid, 'lowprio', account1)
-
- self.contact_comes_online(account1, jid, 'highprio', 50,
- should_popup=False)
-
- # session was associated with the low priority full jid, so it should
- # have been removed from the control
- self.assertEqual(None, ctrl.session)
-
- def test_two_resources_higher_goes_offline_with_esession(self):
- jid = 'default1@gajim.org'
-
- self.contact_comes_online(account1, jid, 'lowprio', 1)
- self.contact_comes_online(account1, jid, 'highprio', 50)
-
- ctrl = self.user_starts_esession(jid, 'highprio', account1)
-
- self.contact_goes_offline(account1, jid, 'highprio', 50,
- still_exists=False)
-
- # session was associated with the high priority full jid, so it should
- # have been removed from the control
- self.assertEqual(None, ctrl.session)
-
-if __name__ == '__main__':
- unittest.main()
diff --git a/test/integration/test_resolver.py b/test/integration/test_resolver.py
index f33a33241..2354f70cf 100644
--- a/test/integration/test_resolver.py
+++ b/test/integration/test_resolver.py
@@ -1,8 +1,6 @@
import unittest
-import time
-
-import lib
+from test import lib
lib.setup_env()
from gi.repository import GLib
@@ -14,7 +12,8 @@ JABBERCZ_TXT_NAME = '_xmppconnect.jabber.cz'
JABBERCZ_SRV_NAME = '_xmpp-client._tcp.jabber.cz'
TEST_LIST = [(NONSENSE_NAME, 'srv', False),
- (JABBERCZ_SRV_NAME, 'srv', True)]
+ (JABBERCZ_SRV_NAME, 'srv', True)]
+
class TestResolver(unittest.TestCase):
'''
@@ -45,9 +44,9 @@ class TestResolver(unittest.TestCase):
def _runGR(self, name, type_):
self.resolver.resolve(
- host = name,
- type_ = type_,
- on_ready = self._myonready)
+ host=name,
+ type_=type_,
+ on_ready=self._myonready)
self.main_loop.run()
diff --git a/test/integration/test_roster.py b/test/integration/test_roster.py
deleted file mode 100644
index d2a1cf0a2..000000000
--- a/test/integration/test_roster.py
+++ /dev/null
@@ -1,211 +0,0 @@
-import unittest
-
-import lib
-lib.setup_env()
-
-from data import *
-
-from gajim_mocks import *
-
-from gajim.common import app
-from gajim.common import contacts as contacts_module
-from gajim import roster_window
-
-app.get_jid_from_account = lambda acc: 'myjid@' + acc
-
-
-class TestRosterWindow(unittest.TestCase):
-
- def setUp(self):
- app.interface = MockInterface()
-
- self.C_NAME = roster_window.Column.NAME
- self.C_TYPE = roster_window.Column.TYPE
- self.C_JID = roster_window.Column.JID
- self.C_ACCOUNT = roster_window.Column.ACCOUNT
-
- # Add after creating RosterWindow
- # We want to test the filling explicitly
- app.contacts = contacts_module.LegacyContactsAPI()
- app.connections = {}
- self.roster = roster_window.RosterWindow(app.app)
-
- for acc in contacts:
- app.connections[acc] = MockConnection(acc)
- app.contacts.add_account(acc)
-
- def tearDown(self):
- self.roster.window.destroy()
- # Clean main loop
- from gi.repository import GLib
- mc = GLib.main_context_default()
- while mc.pending():
- mc.iteration()
-
- ### Custom assertions
- def assert_all_contacts_are_in_roster(self, acc):
- for jid in contacts[acc]:
- self.assert_contact_is_in_roster(jid, acc)
-
- def assert_contact_is_in_roster(self, jid, account):
- contacts = app.contacts.get_contacts(account, jid)
- # check for all resources
- for contact in contacts:
- iters = self.roster._get_contact_iter(jid, account,
- model=self.roster.model)
-
- if jid != app.get_jid_from_account(account):
- # We don't care for groups of SelfContact
- self.assertTrue(len(iters) == len(contact.get_shown_groups()),
- msg='Contact is not in all his groups')
-
- # Are we big brother?
- bb_jid = None
- bb_account = None
- family = app.contacts.get_metacontacts_family(account, jid)
- if family:
- nearby_family, bb_jid, bb_account = \
- self.roster._get_nearby_family_and_big_brother(family, account)
-
- is_in_nearby_family = (jid, account) in (
- (data['jid'], data['account']) for data in nearby_family)
- self.assertTrue(is_in_nearby_family,
- msg='Contact not in his own nearby family')
-
- is_big_brother = (bb_jid, bb_account) == (jid, account)
-
- # check for each group tag
- for titerC in iters:
- self.assertTrue(self.roster.model.iter_is_valid(titerC),
- msg='Contact iter invalid')
-
- c_model = self.roster.model[titerC]
- # name can be stricked if contact or group is blocked
-# self.assertEqual(contact.get_shown_name(), c_model[self.C_NAME],
-# msg='Contact name missmatch')
- self.assertEqual(contact.jid, c_model[self.C_JID],
- msg='Jid missmatch')
-
- if not self.roster.regroup:
- self.assertEqual(account, c_model[self.C_ACCOUNT],
- msg='Account missmatch')
-
- # Check for correct nesting
- parent_iter = self.roster.model.iter_parent(titerC)
- p_model = self.roster.model[parent_iter]
- if family:
- if is_big_brother:
- self.assertTrue(p_model[self.C_TYPE] == 'group',
- msg='Big Brother is not on top')
- else:
- self.assertTrue(p_model[self.C_TYPE] == 'contact',
- msg='Little Brother brother has no BigB')
- else:
- if jid == app.get_jid_from_account(account):
- self.assertTrue(p_model[self.C_TYPE] == 'account',
- msg='SelfContact is not on top')
- else:
- self.assertTrue(p_model[self.C_TYPE] == 'group',
- msg='Contact not found in a group')
-
- def assert_group_is_in_roster(self, group, account):
- #TODO
- pass
-
- def assert_account_is_in_roster(self, acc):
- titerA = self.roster._get_account_iter(acc, model=self.roster.model)
- self.assertTrue(self.roster.model.iter_is_valid(titerA),
- msg='Account iter is invalid')
-
- acc_model = self.roster.model[titerA]
- self.assertEqual(acc_model[self.C_TYPE], 'account',
- msg='No account found')
-
- if not self.roster.regroup:
- self.assertEqual(acc_model[self.C_ACCOUNT], acc,
- msg='Account not found')
-
- self_jid = app.get_jid_from_account(acc)
- self.assertEqual(acc_model[self.C_JID], self_jid,
- msg='Account JID not found in account row')
-
- def assert_model_is_in_sync(self):
- #TODO: check that iter_n_children returns the correct numbers
- pass
-
- # tests
- def test_fill_contacts_and_groups_dicts(self):
- for acc in contacts:
- self.roster.fill_contacts_and_groups_dicts(contacts[acc], acc)
-
- for jid in contacts[acc]:
- instances = app.contacts.get_contacts(acc, jid)
-
- # Created a contact for each single jid?
- self.assertTrue(len(instances) == 1)
-
- # Contacts kept their info
- contact = instances[0]
- self.assertEqual(sorted(contact.groups), sorted(contacts[acc][jid]['groups']),
- msg='Group Missmatch')
-
- groups = contacts[acc][jid]['groups'] or ['General',]
-
- def test_fill_roster_model(self):
- for acc in contacts:
- self.roster.fill_contacts_and_groups_dicts(contacts[acc], acc)
-
- self.roster.add_account(acc)
- self.assert_account_is_in_roster(acc)
-
- self.roster.add_account_contacts(acc)
- self.assert_all_contacts_are_in_roster(acc)
-
- self.assert_model_is_in_sync()
-
-
-class TestRosterWindowRegrouped(TestRosterWindow):
-
- def setUp(self):
- app.config.set('mergeaccounts', True)
- TestRosterWindow.setUp(self)
-
- def test_toggle_regroup(self):
- self.roster.regroup = not self.roster.regroup
- self.roster.setup_and_draw_roster()
- self.roster.regroup = not self.roster.regroup
- self.roster.setup_and_draw_roster()
-
-
-class TestRosterWindowMetaContacts(TestRosterWindowRegrouped):
-
- def test_receive_metacontact_data(self):
- for complete_data in metacontact_data:
- t_acc = complete_data[0]['account']
- t_jid = complete_data[0]['jid']
- data = complete_data[1:]
- for brother in data:
- acc = brother['account']
- jid = brother['jid']
- app.contacts.add_metacontact(t_acc, t_jid, acc, jid)
- self.roster.setup_and_draw_roster()
-
- def test_connect_new_metacontact(self):
- self.test_fill_roster_model()
-
- jid = 'coolstuff@gajim.org'
- contact = app.contacts.create_contact(jid, account1)
- app.contacts.add_contact(account1, contact)
- self.roster.add_contact(jid, account1)
- self.roster.chg_contact_status(contact, 'offline', '', account1)
-
- app.contacts.add_metacontact(account1, 'samejid@gajim.org',
- account1, jid)
- self.roster.chg_contact_status(contact, 'online', '', account1)
-
- self.assert_model_is_in_sync()
-
-
-
-if __name__ == '__main__':
- unittest.main()