Philipp Hörist pushed to branch mainwindow at gajim / gajim
Commits: 540d2996 by lovetox at 2021-12-04T15:34:24+01:00 Fix tests
Remove all broken tests
- - - - -
17 changed files:
- − test/broken/integration/test_gui_event_integration.py - − test/broken/integration/test_roster.py - − test/broken/test_pluginmanager.py - − test/broken/unit/test_jingle.py - − test/broken/unit/test_sessions.py - − test/broken/unit/test_socks5.py - − test/lib/__init__.py - − test/lib/data.py - − test/lib/gajim_mocks.py - − test/lib/mock.py - − test/lib/notify.py - test/no_gui/__init__.py - test/no_gui/unit/test_nick_completion.py → test/no_gui/test_nick_completion.py - test/no_gui/test_styling.py - − test/no_gui/unit/__init__.py - − test/unit/__init__.py - − test/unit/test_gui_interface.py
Changes:
===================================== test/broken/integration/test_gui_event_integration.py deleted ===================================== @@ -1,220 +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 - -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%27/%3E - <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%27/%3E - <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()
===================================== test/broken/integration/test_roster.py deleted ===================================== @@ -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.settings.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()
===================================== test/broken/test_pluginmanager.py deleted ===================================== @@ -1,89 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -## This file is part of Gajim. -## -## Gajim is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published -## by the Free Software Foundation; version 3 only. -## -## Gajim is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Gajim. If not, see http://www.gnu.org/licenses/. -## - -''' -Testing PluginManager class. - -:author: Mateusz Biliński mateusz@bilinski.it -:since: 05/30/2008 -:copyright: Copyright (2008) Mateusz Biliński mateusz@bilinski.it -:license: GPL -''' - -import sys -import os -import unittest - -gajim_root = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..') -sys.path.append(gajim_root + '/gajim') - -# a temporary version of ~/.gajim for testing -configdir = gajim_root + '/test/tmp' - -import time - -# define _ for i18n -import builtins -builtins._ = lambda x: x - -# wipe config directory -import os -if os.path.isdir(configdir): - import shutil - shutil.rmtree(configdir) - -os.mkdir(configdir) - -from gajim.common import configpaths -configpaths.set_config_root(configdir) -configpaths.init() - -# for some reason common.app needs to be imported before xmpppy? - -configpaths.override_path('DATA', gajim_root + '/gajim/data') - -# name to use for the test account -account_name = 'test' - -from plugins import PluginManager - -class PluginManagerTestCase(unittest.TestCase): - def setUp(self): - self.pluginmanager = PluginManager() - - def tearDown(self): - pass - - def test_01_Singleton(self): - """ 1. Checking whether PluginManger class is singleton. """ - self.pluginmanager.test_arg = 1 - secondPluginManager = PluginManager() - - self.assertEqual(id(secondPluginManager), id(self.pluginmanager), - 'Different IDs in references to PluginManager objects (not a singleton)') - self.assertEqual(secondPluginManager.test_arg, 1, - 'References point to different PluginManager objects (not a singleton') - -def suite(): - suite = unittest.TestLoader().loadTestsFromTestCase(PluginManagerTestCase) - return suite - -if __name__=='__main__': - runner = unittest.TextTestRunner() - test_suite = suite() - runner.run(test_suite)
===================================== test/broken/unit/test_jingle.py deleted ===================================== @@ -1,156 +0,0 @@ -''' -Tests for dispatcher.py -''' -import unittest - -import lib -lib.setup_env() - -from mock import Mock - - -from nbxmpp import dispatcher -from nbxmpp.namespaces import Namespace - -from gajim.common.protocol.bytestream import ConnectionIBBytestream -from gajim.common.protocol.bytestream import ConnectionSocks5Bytestream -from gajim.common.jingle import ConnectionJingle -from gajim.common import app -from gajim.common.socks5 import SocksQueue - - -session_init = ''' -<iq xmlns="jabber:client" to="jingleft@thiessen.im/Gajim" type="set" id="43"> -<jingle xmlns="urn:xmpp:jingle:1" action="session-initiate" initiator="jtest@thiessen.im/Gajim" sid="38"> -<content name="fileWL1Y2JIPTM5RAD68" creator="initiator"> -<security xmlns="urn:xmpp:jingle:security:xtls:0"> -<method name="x509" /> -</security> -<description xmlns="urn:xmpp:jingle:apps:file-transfer:1"> -<offer> -<file xmlns="http://jabber.org/protocol/si/profile/file-transfer" name="to" size="2273"> -<desc /> -</file> -</offer> -</description> -<transport xmlns="urn:xmpp:jingle:transports:s5b:1" sid="39"> -<candidate jid="jtest@thiessen.im/Gajim" cid="40" priority="8257536" host="192.168.2.100" type="direct" port="28011" /> -<candidate jid="proxy.thiessen.im" cid="41" priority="655360" host="192.168.2.100" type="proxy" port="5000" /> -<candidate jid="proxy.jabbim.cz" cid="42" priority="655360" host="192.168.2.100" type="proxy" port="7777" /> -</transport> -</content> -</jingle> -</iq> - ''' - - -transport_info = ''' -<iq from='jtest@thiessen.im/Gajim' - id='hjdi8' - to='jingleft@thiessen.im/Gajim' - type='set'> - <jingle xmlns='urn:xmpp:jingle:1' - action='transport-info' - initiator='jtest@thiessen.im/Gajim' - sid='38'> - <content creator='initiator' name='fileWL1Y2JIPTM5RAD68'> - <transport xmlns='urn:xmpp:jingle:transports:s5b:1' - sid='vj3hs98y'> - <candidate-used cid='hr65dqyd'/> - </transport> - </content> - </jingle> -</iq> - -''' - -class Connection(Mock, ConnectionJingle, ConnectionSocks5Bytestream, - ConnectionIBBytestream): - - def __init__(self): - Mock.__init__(self) - ConnectionJingle.__init__(self) - ConnectionSocks5Bytestream.__init__(self) - ConnectionIBBytestream.__init__(self) - self.connected = 2 # This tells gajim we are connected - - def send(self, stanza=None, when=None): - # Called when gajim wants to send something - print(str(stanza)) - - -class TestJingle(unittest.TestCase): - - def setUp(self): - self.dispatcher = dispatcher.XMPPDispatcher() - app.nec = Mock() - app.socks5queue = SocksQueue(Mock()) - # Setup mock client - self.client = Connection() - self.client.__str__ = lambda: 'Mock' # FIXME: why do I need this one? - self.client._caller = Connection() - self.client.defaultNamespace = Namespace.CLIENT - self.client.Connection = Connection() # mock transport - self.con = self.client.Connection - self.con.server_resource = None - self.con.connection = Connection() - - ''' - Fake file_props when we receive a file. Gajim creates a file_props - out of a FileRequestReceive event and from then on it changes in - a lot of places. It is easier to just copy it in here. - If the session_initiate stanza changes, this also must change. - ''' - self.receive_file = {'stream-methods': - 'http://jabber.org/protocol/bytestreams', - 'sender': 'jtest@thiessen.im/Gajim', - 'file-name': 'test_received_file', - 'request-id': '43', 'sid': '39', - 'session-sid': '38', 'session-type': 'jingle', - 'transfered_size': [], 'receiver': - 'jingleft@thiessen.im/Gajim', 'desc': '', - 'size': '2273', 'type': 'r', - 'streamhosts': [{'initiator': - 'jtest@thiessen.im/Gajim', - 'target': 'jingleft@thiessen.im/Gajim', - 'cid': '41', 'state': 0, 'host': '192.168.2.100', - 'type': 'direct', 'port': '28011'}, - {'initiator': 'jtest@thiessen.im/Gajim', - 'target': 'jingleft@thiessen.im/Gajim', - 'cid': '42', 'state': 0, 'host': '192.168.2.100', - 'type': 'proxy', 'port': '5000'}], - 'name': 'to'} - - def tearDown(self): - # Unplug if needed - if hasattr(self.dispatcher, '_owner'): - self.dispatcher.PlugOut() - - def _simulate_connect(self): - self.dispatcher.PlugIn(self.client) # client is owner - # Simulate that we have established a connection - self.dispatcher.StreamInit() - self.dispatcher.ProcessNonBlocking("<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client'>") - - def _simulate_jingle_session(self): - - self.dispatcher.RegisterHandler('iq', self.con._JingleCB, 'set', - Namespace.JINGLE) - self.dispatcher.ProcessNonBlocking(session_init) - session = list(self.con._sessions.values())[0] # The only session we have - jft = list(session.contents.values())[0] # jingleFT object - jft.file_props = self.receive_file # We plug file_props manually - # The user accepts to receive the file - # we have to manually simulate this behavior - session.approve_session() - self.con.send_file_approval(self.receive_file) - - self.dispatcher.ProcessNonBlocking(transport_info) - - def test_jingle_session(self): - self._simulate_connect() - self._simulate_jingle_session() - - -if __name__ == '__main__': - unittest.main()
===================================== test/broken/unit/test_sessions.py deleted ===================================== @@ -1,167 +0,0 @@ -import unittest - -import lib -lib.setup_env() - -import notify -import nbxmpp - -from gajim.common import app -from gajim.common import nec -from gajim.common import ged -from gajim.common.nec import NetworkEvent - -from gajim.session import ChatControlSession -from gajim.roster_window import RosterWindow - -from gajim_mocks import * -from data import account1 - -app.interface = MockInterface() - - -# name to use for the test account -account_name = account1 - - -class TestChatControlSession(unittest.TestCase): - ''' Testclass for session.py ''' - - @classmethod - def setUpClass(cls): - app.nec = nec.NetworkEventsController() - cls.conn = MockConnection(account_name, {'send_stanza': None}) - app.logger = MockLogger() - app.default_session_type = ChatControlSession - - def setUp(self): - app.notification = notify.Notification() - - # no notifications have been sent - self.assertEqual(0, len(notify.notifications)) - - def tearDown(self): - app.notification.clean() - - def receive_chat_msg(self, jid, msgtxt): - '''simulate receiving a chat message from jid''' - msg = nbxmpp.Message() - msg.setBody(msgtxt) - msg.setType('chat') - - xml = """<message from='%s' id='1' type='chat'><body>%s</body> - <thread>123</thread></message>""" % (jid, msgtxt) - stanza = nbxmpp.protocol.Message(node=nbxmpp.simplexml.XML2Node(xml)) - self.conn._messageCB(None, stanza) - - # ----- custom assertions ----- - def assert_new_message_notification(self): - '''a new_message notification has been sent''' - self.assertEqual(1, len(notify.notifications)) - notif = notify.notifications[-1] - self.assertEqual('New Message', notif.popup_event_type) - - def assert_first_message_notification(self): - '''this message was treated as a first message''' - self.assert_new_message_notification() - notif = notify.notifications[-1] - first = notif.first_unread - self.assertTrue(first, - 'message should have been treated as a first message') - - def assert_not_first_message_notification(self): - '''this message was not treated as a first message''' - self.assert_new_message_notification() - notif = notify.notifications[-1] - first = notif.first_unread - self.assertTrue(not first, - 'message was unexpectedly treated as a first message') - - # ----- tests ----- - def test_receive_1nocontrol(self): - '''test receiving a message in a blank state''' - jid = 'bct@necronomicorp.com' - fjid = 'bct@necronomicorp.com/Gajim' - msgtxt = 'testing one' - - self.receive_chat_msg(fjid, msgtxt) - - # session is created - self.assertTrue((jid in self.conn.sessions) and ( - '123' in self.conn.sessions[jid]), 'session is not created') - sess = self.conn.sessions[jid]['123'] - - # message was logged - calls = app.storage.archive.mockGetNamedCalls('insert_into_logs') - self.assertEqual(1, len(calls)) - - # no ChatControl was open and autopopup was off - # so the message goes into the event queue - self.assertEqual(1, len(app.events.get_events(account_name))) - - self.assert_first_message_notification() - - # no control is attached to the session - self.assertEqual(None, sess.control) - - def test_receive_2already_has_control(self): - '''test receiving a message with a session already attached to a - control''' - jid = 'bct@necronomicorp.com' - fjid = 'bct@necronomicorp.com/Gajim' - msgtxt = 'testing two' - app.interface.roster = RosterWindow(app.app) - - sess = self.conn.sessions[jid]['123'] - sess.control = MockChatControl(fjid, account_name) - - self.receive_chat_msg(fjid, msgtxt) - - # message was logged - calls = app.storage.archive.mockGetNamedCalls('insert_into_logs') - self.assertEqual(2, len(calls)) - - # the message does not go into the event queue - self.assertEqual(1, len(app.events.get_events(account_name))) - - self.assert_not_first_message_notification() - - # message was printed to the control - calls = sess.control.mockGetNamedCalls('print_conversation') - self.assertEqual(1, len(calls)) - app.interface.roster.window.destroy() - - #def test_received_3orphaned_control(self): - #'''test receiving a message when a control that doesn't have a session - #attached exists''' - - #jid = 'bct@necronomicorp.com' - #fjid = jid + '/Gajim' - #msgtxt = 'testing three' - - #ctrl = MockChatControl(jid, account_name) - #gajim.interface.msg_win_mgr = Mock({'get_control': ctrl}) - #gajim.interface.msg_win_mgr.mockSetExpectation('get_control', - #expectParams(jid, account_name)) - - #self.receive_chat_msg(fjid, msgtxt) - - ## message was logged - #calls = gajim.logger.mockGetNamedCalls('insert_into_logs') - #self.assertEqual(1, len(calls)) - - ## the message does not go into the event queue - #self.assertEqual(0, len(gajim.events.get_events(account_name))) - - #self.assert_not_first_message_notification() - - ## this session is now attached to that control - #self.assertEqual(self.sess, ctrl.session) - #self.assertEqual(ctrl, self.sess.control, 'foo') - - ## message was printed to the control - #calls = ctrl.mockGetNamedCalls('print_conversation') - #self.assertEqual(1, len(calls)) - -if __name__ == '__main__': - unittest.main()
===================================== test/broken/unit/test_socks5.py deleted ===================================== @@ -1,172 +0,0 @@ -''' -Tests for dispatcher.py -''' -import unittest - -import lib -lib.setup_env() - -from mock import Mock -import sys -import socket - -from gajim.common.socks5 import * -from gajim.common import jingle_xtls - -class fake_sock(Mock): - def __init__(self, sockobj): - Mock.__init__(self) - - self.sockobj = sockobj - - - def setup_stream(self): - sha1 = self.sockobj._get_sha1_auth() - - self.incoming = [] - self.incoming.append(self.sockobj._get_auth_response()) - self.incoming.append(self.sockobj._get_request_buff(sha1, 0x00)) - self.outgoing = [] - self.outgoing.append(self.sockobj._get_auth_buff()) - self.outgoing.append(self.sockobj._get_request_buff(sha1)) - - def switch_stream(self): - # Roles are reversed, client will be expecting server stream - # and server will be expecting client stream - - temp = self.incoming - self.incoming = self.outgoing - self.outgoing = temp - - def _recv(self, foo): - return self.incoming.pop(0) - - def _send(self, data): - # This method is surrounded by a try block, - # we can't use assert here - - if data != self.outgoing[0]: - print('FAILED SENDING TEST') - self.outgoing.pop(0) - -class fake_idlequeue(Mock): - - def __init__(self): - Mock.__init__(self) - - def plug_idle(self, obj, writable=True, readable=True): - - if readable: - obj.pollin() - if writable: - obj.pollout() - -class TestSocks5(unittest.TestCase): - ''' - Test class for Socks5 - ''' - def setUp(self): - streamhost = { 'host': None, - 'port': 1, - 'initiator' : None, - 'target' : None} - queue = Mock() - queue.file_props = {} - #self.sockobj = Socks5Receiver(fake_idlequeue(), streamhost, None) - self.sockobj = Socks5Sender(fake_idlequeue(), None, 'server', Mock() , - None, None, True, file_props={}) - sock = fake_sock(self.sockobj) - self.sockobj._sock = sock - self.sockobj._recv = sock._recv - self.sockobj._send = sock._send - self.sockobj.state = 1 - self.sockobj.connected = True - self.sockobj.pollend = self._pollend - - # Something that the receiver needs - #self.sockobj.file_props['type'] = 'r' - - # Something that the sender needs - self.sockobj.file_props = {} - self.sockobj.file_props['type'] = 'r' - self.sockobj.file_props['paused'] = '' - self.sockobj.queue = Mock() - self.sockobj.queue.process_result = self._pollend - - def _pollend(self, foo = None, duu = None): - # This is a disconnect function - sys.exit("end of the road") - - def _check_inout(self): - # Check if there isn't anything else to receive or send - sock = self.sockobj._sock - assert(sock.incoming == []) - assert(sock.outgoing == []) - - def test_connection_server(self): - return - mocksock = self.sockobj._sock - mocksock.setup_stream() - #self.sockobj._sock.switch_stream() - s = socket.socket(2, 1, 6) - server = ('127.0.0.1', 28000) - - s.connect(server) - - s.send(mocksock.outgoing.pop(0)) - self.assertEqual(s.recv(64), mocksock.incoming.pop(0)) - - s.send(mocksock.outgoing.pop(0)) - self.assertEqual(s.recv(64), mocksock.incoming.pop(0)) - - def test_connection_client(self): - - - mocksock = self.sockobj._sock - mocksock.setup_stream() - mocksock.switch_stream() - s = socket.socket(10, 1, 6) - - - s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) - s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) - - netadd = ('::', 28000, 0, 0) - s.bind(netadd) - s.listen(socket.SOMAXCONN) - (s, address) = s.accept() - - - self.assertEqual(s.recv(64), mocksock.incoming.pop(0)) - s.send(mocksock.outgoing.pop(0)) - - buff = s.recv(64) - inco = mocksock.incoming.pop(0) - #self.assertEqual(s.recv(64), mocksock.incoming.pop(0)) - s.send(mocksock.outgoing.pop(0)) - - def test_client_negoc(self): - return - self.sockobj._sock.setup_stream() - try: - self.sockobj.pollout() - except SystemExit: - pass - - self._check_inout() - - def test_server_negoc(self): - return - self.sockobj._sock.setup_stream() - self.sockobj._sock.switch_stream() - try: - self.sockobj.idlequeue.plug_idle(self.sockobj, False, True) - except SystemExit: - pass - self._check_inout() - - -if __name__ == '__main__': - - unittest.main()
===================================== test/lib/__init__.py deleted ===================================== @@ -1,46 +0,0 @@ -import os - -from tempfile import gettempdir - -# a temporary version of ~/.gajim for testing -configdir = os.path.join(gettempdir(), 'gajim') -os.makedirs(configdir, exist_ok=True) - -# plugins config dir -pluginsconfigdir = configdir + '/pluginsconfig' -# theme config directory -themedir = configdir + '/theme' - -# define _ for i18n -import builtins -builtins._ = lambda x: x - -from gajim.common.contacts import LegacyContactsAPI - -def setup_env(use_x=True): - # wipe config directory - if os.path.isdir(configdir): - import shutil - shutil.rmtree(configdir) - - os.mkdir(configdir) - os.mkdir(pluginsconfigdir) - os.mkdir(themedir) - - from gajim.common import configpaths - configpaths.set_config_root(configdir) - configpaths.init() - - # for some reason gajim.common.app needs to be imported before xmpppy? - from gajim.common import app - - import logging - logging.basicConfig() - - app.use_x = use_x - app.contacts = LegacyContactsAPI() - app.connections = {} - - if use_x: - from gajim.application import GajimApplication - app.app = GajimApplication()
===================================== test/lib/data.py deleted ===================================== @@ -1,77 +0,0 @@ -# -*- coding: utf-8 -*- -account1 = 'acc1' -account2 = 'Cool"chârßéµö' -account3 = 'dingdong.org' - -contacts = {} -contacts[account1] = { - 'myjid@'+account1: { - 'ask': None, 'groups': [], 'name': None, 'resources': {}, - 'subscription': 'both'}, - 'default1@gajim.org': { - 'ask': None, 'groups': [], 'name': None, 'resources': {}, - 'subscription': 'both'}, - 'default2@gajim.org': { - 'ask': None, 'groups': ['GroupA',], 'name': None, 'resources': {}, - 'subscription': 'both'}, - 'Cool"chârßéµö@gajim.org': { - 'ask': None, 'groups': ['<Cool"chârßéµö', 'GroupB'], - 'name': None, 'resources': {}, 'subscription': 'both'}, - 'samejid@gajim.org': { - 'ask': None, 'groups': ['GroupA',], 'name': None, 'resources': {}, - 'subscription': 'both'} -} -contacts[account2] = { - 'myjid@'+account2: { - 'ask': None, 'groups': [], 'name': None, 'resources': {}, - 'subscription': 'both'}, - 'default3@gajim.org': { - 'ask': None, 'groups': ['GroupC',], 'name': None, 'resources': {}, - 'subscription': 'both'}, - 'asksubfrom@gajim.org': { - 'ask': 'subscribe', 'groups': ['GroupA',], 'name': None, - 'resources': {}, 'subscription': 'from'}, - 'subto@gajim.org': { - 'ask': None, 'groups': ['GroupB'], 'name': None, 'resources': {}, - 'subscription': 'to'}, - 'samejid@gajim.org': { - 'ask': None, 'groups': ['GroupA', 'GroupB'], 'name': None, - 'resources': {}, 'subscription': 'both'} -} -contacts[account3] = { - #'guypsych0\40h.com@msn.dingdong.org': { - # 'ask': None, 'groups': [], 'name': None, 'resources': {}, - # 'subscription': 'both'}, - 'guypsych0%h.com@msn.delx.cjb.net': { - 'ask': 'subscribe', 'groups': [], 'name': None, - 'resources': {}, 'subscription': 'from'}, - #'guypsych0%h.com@msn.jabber.wiretrip.org': { - # 'ask': None, 'groups': [], 'name': None, 'resources': {}, - # 'subscription': 'to'}, - #'guypsycho\40g.com@gtalk.dingdong.org': { - # 'ask': None, 'groups': [], 'name': None, - # 'resources': {}, 'subscription': 'both'} -} - -# We have contacts that are not in roster but only specified in the metadata -metacontact_data = [ - [{'account': account3, - 'jid': 'guypsych0\40h.com@msn.dingdong.org', - 'order': 0}, - {'account': account3, - 'jid': 'guypsych0%h.com@msn.delx.cjb.net', - 'order': 0}, - {'account': account3, - 'jid': 'guypsych0%h.com@msn.jabber.wiretrip.org', - 'order': 0}, - {'account': account3, - 'jid': 'guypsycho\40g.com@gtalk.dingdong.org', - 'order': 0}], - - [{'account': account1, - 'jid': 'samejid@gajim.org', - 'order': 0}, - {'account': account2, - 'jid': 'samejid@gajim.org', - 'order': 0}] - ]
===================================== test/lib/gajim_mocks.py deleted ===================================== @@ -1,140 +0,0 @@ -''' -Module with dummy classes for Gajim specific unit testing -''' - -from .mock import Mock -from gajim.common import app -from gajim.common import ged - -from gajim.common.connection_handlers import ConnectionHandlers - -class MockConnection(Mock, ConnectionHandlers): - def __init__(self, account, *args): - Mock.__init__(self, *args) - - self.connection = Mock() - - self.name = account - - ConnectionHandlers.__init__(self) - - self.connected = 2 - self.pep = {} - self.sessions = {} - self.server_resource = 'Gajim' - - app.interface.instances[account] = { - 'infos': {}, - 'disco': {} - } - app.interface.minimized_controls[account] = {} - app.contacts.add_account(account) - app.groups[account] = {} - app.gc_connected[account] = {} - app.automatic_rooms[account] = {} - app.newly_added[account] = [] - app.to_be_removed[account] = [] - app.nicks[account] = app.settings.get_account_setting(account, 'name') - app.block_signed_in_notifications[account] = True - - app.connections[account] = self - -class MockWindow(Mock): - def __init__(self, *args): - Mock.__init__(self, *args) - self.window = Mock() - self._controls = {} - - def get_control(self, jid, account): - try: - return self._controls[account][jid] - except KeyError: - return None - - def has_control(self, jid, acct): - return self.get_control(jid, acct) is not None - - def new_tab(self, ctrl): - account = ctrl.account - jid = ctrl.jid - - if account not in self._controls: - self._controls[account] = {} - - if jid not in self._controls[account]: - self._controls[account][jid] = {} - - self._controls[account][jid] = ctrl - - def __nonzero__(self): - return True - -class MockChatControl(Mock): - def __init__(self, jid, account, *args): - Mock.__init__(self, *args) - - self.jid = jid - self.account = account - - self.parent_win = MockWindow({'get_active_control': self}) - self.session = None - - def set_session(self, sess): - self.session = sess - - def __nonzero__(self): - return True - - def __eq__(self, other): - return self is other - - -class MockInterface(Mock): - def __init__(self, *args): - Mock.__init__(self, *args) - app.interface = self - self.msg_win_mgr = Mock() - self.roster = Mock() - app.ged = ged.GlobalEventsDispatcher() - from gajim import plugins - app.plugin_manager = plugins.PluginManager() - - self.instances = {} - self.minimized_controls = {} - - -class MockLogger(Mock): - def __init__(self): - Mock.__init__(self, {'insert_into_logs': None, - 'get_transports_type': {}}) - self.cur = Mock() - - -class MockContact(Mock): - def __nonzero__(self): - return True - - -import random - -class MockSession(Mock): - def __init__(self, conn, jid, thread_id, type_): - Mock.__init__(self) - - self.conn = conn - self.jid = jid - self.type_ = type_ - self.thread_id = thread_id - self.resource = '' - - if not self.thread_id: - self.thread_id = '%0x' % random.randint(0, 10000) - - def __repr__(self): - return '<MockSession %s>' % self.thread_id - - def __nonzero__(self): - return True - - def __eq__(self, other): - return self is other
===================================== test/lib/mock.py deleted ===================================== @@ -1,466 +0,0 @@ -# -# (c) Dave Kirby 2001 - 2005 -# mock@thedeveloperscoach.com -# -# Original call interceptor and call assertion code by Phil Dawes (pdawes@users.sourceforge.net) -# Call interceptor code enhanced by Bruce Cropley (cropleyb@yahoo.com.au) -# -# This Python module and associated files are released under the FreeBSD -# license. Essentially, you can do what you like with it except pretend you wrote -# it yourself. -# -# -# Copyright (c) 2005, Dave Kirby -# Copyright (c) 2009, Yann Leboulanger -# -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of this library nor the names of its -# contributors may be used to endorse or promote products derived from -# this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# mock@thedeveloperscoach.com - - -""" -Mock object library for Python. Mock objects can be used when unit testing -to remove a dependency on another production class. They are typically used -when the dependency would either pull in lots of other classes, or -significantly slow down the execution of the test. -They are also used to create exceptional conditions that cannot otherwise -be easily triggered in the class under test. -""" - -__version__ = "0.1.0" - -# Added in Python 2.1 -import inspect -import re - -class MockInterfaceError(Exception): - pass - -class Mock(object): - """ - The Mock class emulates any other class for testing purposes. - All method calls are stored for later examination. - """ - - def __init__(self, returnValues=None, realClass=None): - """ - The Mock class constructor takes a dictionary of method names and - the values they return. Methods that are not in the returnValues - dictionary will return None. - You may also supply a class whose interface is being mocked. - All calls will be checked to see if they appear in the original - interface. Any calls to methods not appearing in the real class - will raise a MockInterfaceError. Any calls that would fail due to - non-matching parameter lists will also raise a MockInterfaceError. - Both of these help to prevent the Mock class getting out of sync - with the class it is Mocking. - """ - self.mockCalledMethods = {} - self.mockAllCalledMethods = [] - self.mockReturnValues = returnValues or {} - self.mockExpectations = {} - self.realClass = realClass - self.realClassMethods = None - if realClass: - self.realClassMethods = dict(inspect.getmembers(realClass, inspect.isroutine)) - for retMethod in self.mockReturnValues.keys(): - if retMethod not in self.realClassMethods: - raise MockInterfaceError("Return value supplied for method '%s' that was not in the original class" % retMethod) - self._setupSubclassMethodInterceptors() - - def _setupSubclassMethodInterceptors(self): - methods = inspect.getmembers(self.realClass, inspect.isroutine) - baseMethods = dict(inspect.getmembers(Mock, inspect.ismethod)) - for m in methods: - name = m[0] - # Don't record calls to methods of Mock base class. - if not name in baseMethods: - self.__dict__[name] = MockCallable(name, self, handcrafted=True) - - def get_module(self, name): - return Mock() - - def __getattr__(self, name): - return MockCallable(name, self) - - def mockAddReturnValues(self, **methodReturnValues ): - self.mockReturnValues.update(methodReturnValues) - - def mockSetExpectation(self, name, testFn, after=0, until=0): - self.mockExpectations.setdefault(name, []).append((testFn, after, until)) - - def _checkInterfaceCall(self, name, callParams, callKwParams): - """ - Check that a call to a method of the given name to the original - class with the given parameters would not fail. If it would fail, - raise a MockInterfaceError. - Based on the Python 2.3.3 Reference Manual section 5.3.4: Calls. - """ - if self.realClassMethods is None: - return - if name not in self.realClassMethods: - return - - func = self.realClassMethods[name] - try: - args, varargs, varkw, defaults = inspect.getargspec(func) - except TypeError: - # func is not a Python function. It is probably a builtin, - # such as __repr__ or __coerce__. TODO: Checking? - # For now assume params are OK. - return - - # callParams doesn't include self; args does include self. - numPosCallParams = 1 + len(callParams) - - if numPosCallParams > len(args) and not varargs: - raise MockInterfaceError("Original %s() takes at most %s arguments (%s given)" % - (name, len(args), numPosCallParams)) - - # Get the number of positional arguments that appear in the call, - # also check for duplicate parameters and unknown parameters - numPosSeen = _getNumPosSeenAndCheck(numPosCallParams, callKwParams, args, varkw) - - lenArgsNoDefaults = len(args) - len(defaults or []) - if numPosSeen < lenArgsNoDefaults: - raise MockInterfaceError("Original %s() takes at least %s arguments (%s given)" % (name, lenArgsNoDefaults, numPosSeen)) - - def mockGetAllCalls(self): - """ - Return a list of MockCall objects, - representing all the methods in the order they were called. - """ - return self.mockAllCalledMethods - getAllCalls = mockGetAllCalls # deprecated - kept for backward compatibility - - def mockGetNamedCalls(self, methodName): - """ - Return a list of MockCall objects, - representing all the calls to the named method in the order they were called. - """ - return self.mockCalledMethods.get(methodName, []) - getNamedCalls = mockGetNamedCalls # deprecated - kept for backward compatibility - - def mockCheckCall(self, index, name, *args, **kwargs): - '''test that the index-th call had the specified name and parameters''' - call = self.mockAllCalledMethods[index] - assert name == call.getName(), "%r != %r" % (name, call.getName()) - call.checkArgs(*args, **kwargs) - - -def _getNumPosSeenAndCheck(numPosCallParams, callKwParams, args, varkw): - """ - Positional arguments can appear as call parameters either named as - a named (keyword) parameter, or just as a value to be matched by - position. Count the positional arguments that are given by either - keyword or position, and check for duplicate specifications. - Also check for arguments specified by keyword that do not appear - in the method's parameter list. - """ - posSeen = {} - for arg in args[:numPosCallParams]: - posSeen[arg] = True - for kwp in callKwParams: - if kwp in posSeen: - raise MockInterfaceError("%s appears as both a positional and named parameter." % kwp) - if kwp in args: - posSeen[kwp] = True - elif not varkw: - raise MockInterfaceError("Original method does not have a parameter '%s'" % kwp) - return len(posSeen) - -class MockCall: - """ - MockCall records the name and parameters of a call to an instance - of a Mock class. Instances of MockCall are created by the Mock class, - but can be inspected later as part of the test. - """ - def __init__(self, name, params, kwparams ): - self.name = name - self.params = params - self.kwparams = kwparams - - def checkArgs(self, *args, **kwargs): - assert args == self.params, "%r != %r" % (args, self.params) - assert kwargs == self.kwparams, "%r != %r" % (kwargs, self.kwparams) - - def getParam( self, n ): - if isinstance(n, int): - return self.params[n] - elif isinstance(n, str): - return self.kwparams[n] - else: - raise IndexError('illegal index type for getParam') - - def getNumParams(self): - return len(self.params) - - def getNumKwParams(self): - return len(self.kwparams) - - def getName(self): - return self.name - - #pretty-print the method call - def __str__(self): - s = self.name + "(" - sep = '' - for p in self.params: - s = s + sep + repr(p) - sep = ', ' - items = sorted(self.kwparams.items()) - for k, v in items: - s = s + sep + k + '=' + repr(v) - sep = ', ' - s = s + ')' - return s - def __repr__(self): - return self.__str__() - -class MockCallable: - """ - Intercepts the call and records it, then delegates to either the mock's - dictionary of mock return values that was passed in to the constructor, - or a handcrafted method of a Mock subclass. - """ - def __init__(self, name, mock, handcrafted=False): - self.name = name - self.mock = mock - self.handcrafted = handcrafted - - def __call__(self, *params, **kwparams): - self.mock._checkInterfaceCall(self.name, params, kwparams) - thisCall = self.recordCall(params, kwparams) - self.checkExpectations(thisCall, params, kwparams) - return self.makeCall(params, kwparams) - - def recordCall(self, params, kwparams): - """ - Record the MockCall in an ordered list of all calls, and an ordered - list of calls for that method name. - """ - thisCall = MockCall(self.name, params, kwparams) - calls = self.mock.mockCalledMethods.setdefault(self.name, []) - calls.append(thisCall) - self.mock.mockAllCalledMethods.append(thisCall) - return thisCall - - def makeCall(self, params, kwparams): - if self.handcrafted: - allPosParams = (self.mock,) + params - func = _findFunc(self.mock.realClass, self.name) - if not func: - raise NotImplementedError - return func(*allPosParams, **kwparams) - else: - returnVal = self.mock.mockReturnValues.get(self.name) - if isinstance(returnVal, ReturnValuesBase): - returnVal = returnVal.next() - return returnVal - - def checkExpectations(self, thisCall, params, kwparams): - if self.name in self.mock.mockExpectations: - callsMade = len(self.mock.mockCalledMethods[self.name]) - for (expectation, after, until) in self.mock.mockExpectations[self.name]: - if callsMade > after and (until==0 or callsMade < until): - assert expectation(self.mock, thisCall, len(self.mock.mockAllCalledMethods)-1), 'Expectation failed: '+str(thisCall) - - -def _findFunc(cl, name): - """ Depth first search for a method with a given name. """ - if name in cl.__dict__: - return cl.__dict__[name] - for base in cl.__bases__: - func = _findFunc(base, name) - if func: - return func - return None - - - -class ReturnValuesBase: - def next(self): - try: - return self.iter.next() - except StopIteration: - raise AssertionError("No more return values") - def __iter__(self): - return self - -class ReturnValues(ReturnValuesBase): - def __init__(self, *values): - self.iter = iter(values) - - -class ReturnIterator(ReturnValuesBase): - def __init__(self, iterator): - self.iter = iter(iterator) - - -def expectParams(*params, **keywords): - '''check that the callObj is called with specified params and keywords - ''' - def fn(mockObj, callObj, idx): - return callObj.params == params and callObj.kwparams == keywords - return fn - - -def expectAfter(*methods): - '''check that the function is only called after all the functions in 'methods' - ''' - def fn(mockObj, callObj, idx): - calledMethods = [method.getName() for method in mockObj.mockGetAllCalls()] - #skip last entry, since that is the current call - calledMethods = calledMethods[:-1] - for method in methods: - if method not in calledMethods: - return False - return True - return fn - -def expectException(exception, *args, **kwargs): - ''' raise an exception when the method is called - ''' - def fn(mockObj, callObj, idx): - raise exception(*args, **kwargs) - return fn - - -def expectParam(paramIdx, cond): - '''check that the callObj is called with parameter specified by paramIdx (a position index or keyword) - fulfills the condition specified by cond. - cond is a function that takes a single argument, the value to test. - ''' - def fn(mockObj, callObj, idx): - param = callObj.getParam(paramIdx) - return cond(param) - return fn - -def EQ(value): - def testFn(param): - return param == value - return testFn - -def NE(value): - def testFn(param): - return param != value - return testFn - -def GT(value): - def testFn(param): - return param > value - return testFn - -def LT(value): - def testFn(param): - return param < value - return testFn - -def GE(value): - def testFn(param): - return param >= value - return testFn - -def LE(value): - def testFn(param): - return param <= value - return testFn - -def AND(*condlist): - def testFn(param): - for cond in condlist: - if not cond(param): - return False - return True - return testFn - -def OR(*condlist): - def testFn(param): - for cond in condlist: - if cond(param): - return True - return False - return testFn - -def NOT(cond): - def testFn(param): - return not cond(param) - return testFn - -def MATCHES(regex, *args, **kwargs): - compiled_regex = re.compile(regex, *args, **kwargs) - def testFn(param): - return compiled_regex.match(param) is not None - return testFn - -def SEQ(*sequence): - iterator = iter(sequence) - def testFn(param): - try: - cond = iterator.next() - except StopIteration: - raise AssertionError('SEQ exhausted') - return cond(param) - return testFn - -def IS(instance): - def testFn(param): - return param is instance - return testFn - -def ISINSTANCE(class_): - def testFn(param): - return isinstance(param, class_) - return testFn - -def ISSUBCLASS(class_): - def testFn(param): - return issubclass(param, class_) - return testFn - -def CONTAINS(val): - def testFn(param): - return val in param - return testFn - -def IN(container): - def testFn(param): - return param in container - return testFn - -def HASATTR(attr): - def testFn(param): - return hasattr(param, attr) - return testFn - -def HASMETHOD(method): - def testFn(param): - return hasattr(param, method) and callable(getattr(param, method)) - return testFn - -CALLABLE = callable
===================================== test/lib/notify.py deleted ===================================== @@ -1,28 +0,0 @@ -# mock notify module - -from gajim.common import app -from gajim.common import ged - -notifications = [] - -class Notification: - def _nec_notification(self, obj): - global notifications - notifications.append(obj) - - def clean(self): - global notifications - notifications = [] - app.ged.remove_event_handler('notification', ged.GUI2, - self._nec_notification) - - def __init__(self): - app.ged.register_event_handler('notification', ged.GUI2, - self._nec_notification) - - -def notify(event, jid, account, parameters, advanced_notif_num = None): - notifications.append((event, jid, account, parameters, advanced_notif_num)) - -def get_advanced_notification(event, account, contact): - return None
===================================== test/no_gui/__init__.py ===================================== @@ -0,0 +1,11 @@ +import gi + +def require_versions(): + gi.require_versions({'Gdk': '3.0', + 'GLib': '2.0', + 'Gio': '2.0', + 'Gtk': '3.0', + 'GObject': '2.0', + 'Pango': '1.0'}) + +require_versions()
===================================== test/no_gui/unit/test_nick_completion.py → test/no_gui/test_nick_completion.py =====================================
===================================== test/no_gui/test_styling.py ===================================== @@ -8,8 +8,8 @@ from gajim.common.styling import StrongSpan from gajim.common.styling import EmphasisSpan from gajim.common.styling import StrikeSpan -from gajim.common.styling import Url -from gajim.common.styling import URL_RX +from gajim.common.styling import Uri +from gajim.common.styling import URI_RX from gajim.common.styling import ADDRESS_RX
@@ -135,7 +135,7 @@ 'pre block with closing': { 'input': '```\npre *fmt* ```\n```\nplain', 'tokens': [ - PreBlock(start=0, end=22, text='```\npre *fmt* ```\n```\n', spans=[]), + PreBlock(start=0, end=22, text='```\npre *fmt* ```\n```\n'), PlainBlock(start=22, end=27, text='plain', spans=[]) ] }, @@ -143,7 +143,7 @@ 'pre block EOF': { 'input': '````\na\n```', 'tokens': [ - PreBlock(start=0, end=10, text='````\na\n```', spans=[]) + PreBlock(start=0, end=10, text='````\na\n```') ] },
@@ -164,7 +164,7 @@ 'single level block quote': { 'input': '> quoted\nnot quoted', 'tokens': [ - QuoteBlock(start=0, end=10, text='> quoted\n', spans=[], blocks=[ + QuoteBlock(start=0, end=10, text='> quoted\n', blocks=[ PlainBlock(start=0, end=8, text=' quoted\n', spans=[]) ]), PlainBlock(start=10, end=20, text='not quoted', spans=[]) @@ -174,9 +174,9 @@ 'multi level block quote': { 'input': '> quoted\n>> quote > 2\n>quote 1\n\nnot quoted', 'tokens': [ - QuoteBlock(start=0, end=34, text='> quoted\n>> quote > 2\n>quote 1\n', spans=[], blocks=[ + QuoteBlock(start=0, end=34, text='> quoted\n>> quote > 2\n>quote 1\n', blocks=[ PlainBlock(start=0, end=8, text=' quoted\n', spans=[]), - QuoteBlock(start=8, end=22, text='> quote > 2\n', spans=[], blocks=[ + QuoteBlock(start=8, end=22, text='> quote > 2\n', blocks=[ PlainBlock(start=0, end=12, text=' quote > 2\n', spans=[]) ]), PlainBlock(start=22, end=30, text='quote 1\n', spans=[]) @@ -188,15 +188,15 @@ 'quote start then EOF': { 'input': '> ', 'tokens': [ - QuoteBlock(start=0, end=2, text='> ', spans=[], blocks=[]) + QuoteBlock(start=0, end=2, text='> ', blocks=[]) ] },
'quote with children': { 'input': '> ```\n> pre\n> ```\n> not pre', 'tokens': [ - QuoteBlock(start=0, end=27, text='> ```\n> pre\n> ```\n> not pre', spans=[], blocks=[ - PreBlock(start=0, end=12, text='```\npre\n```\n', spans=[]), + QuoteBlock(start=0, end=27, text='> ```\n> pre\n> ```\n> not pre', blocks=[ + PreBlock(start=0, end=12, text='```\npre\n```\n'), PlainBlock(start=12, end=19, text='not pre', spans=[]) ]) ] @@ -205,8 +205,8 @@ 'pre end of parent': { 'input': '> ``` \n> pre\nplain', 'tokens': [ - QuoteBlock(start=0, end=13, text='> ``` \n> pre\n', spans=[], blocks=[ - PreBlock(start=0, end=9, text='``` \npre\n', spans=[]) + QuoteBlock(start=0, end=13, text='> ``` \n> pre\n', blocks=[ + PreBlock(start=0, end=9, text='``` \npre\n') ]), PlainBlock(start=13, end=18, text='plain', spans=[]) ] @@ -223,7 +223,7 @@ 'input': 'some kind of link http://foo.com/blah_blah', 'tokens': [ PlainBlock(start=0, end=42, text='some kind of link http://foo.com/blah_blah', spans=[], uris=[ - Url(start=18, end=42, text='http://foo.com/blah_blah') + Uri(start=18, end=42, text='http://foo.com/blah_blah') ]) ] }, @@ -232,7 +232,7 @@ 'input': 'some kind of link http://foo.com/blah_blah,', 'tokens': [ PlainBlock(start=0, end=43, text='some kind of link http://foo.com/blah_blah,', spans=[], uris=[ - Url(start=18, end=42, text='http://foo.com/blah_blah') + Uri(start=18, end=42, text='http://foo.com/blah_blah') ]) ] }, @@ -243,7 +243,7 @@ PlainBlock(start=0, end=44, text='some *kind* of link http://foo.com/blah_blah', spans=[ StrongSpan(start=5, end=11, text='*kind*') ], uris=[ - Url(start=20, end=44, text='http://foo.com/blah_blah') + Uri(start=20, end=44, text='http://foo.com/blah_blah') ]) ] }, @@ -316,7 +316,7 @@ def test_styling(self):
def test_urls(self): for url in URLS: - match = URL_RX.search(url) + match = URI_RX.search(url) self.assertIsNotNone(match) start = match.start() end = match.end() @@ -332,7 +332,7 @@ def test_emails(self):
def test_url_with_text(self): for text, result in URL_WITH_TEXT: - match = URL_RX.search(text) + match = URI_RX.search(text) self.assertIsNotNone(match) start = match.start() end = match.end()
===================================== test/no_gui/unit/__init__.py deleted ===================================== @@ -1,5 +0,0 @@ -''' - -This package just contains plain unit tests - -'''
===================================== test/unit/__init__.py deleted ===================================== @@ -1,5 +0,0 @@ -''' - -This package just contains plain unit tests - -'''
===================================== test/unit/test_gui_interface.py deleted ===================================== @@ -1,32 +0,0 @@ -''' -Some diverse tests covering functionality in the GUI Interface class. -''' -import unittest - -import gajim.gui -gajim.gui.init('gtk') - -from test import lib -lib.setup_env() - -from gajim.common import logging_helpers -logging_helpers.set_quiet() - -from gajim.common import app - -from gajim.gui_interface import Interface - -from gi.repository import GLib - -class TestInterface(unittest.TestCase): - - def test_instantiation(self): - ''' Test that we can proper initialize and do not fail on globals ''' - def close_app(): - app.app.quit() - GLib.idle_add(close_app) - app.app.run() - - -if __name__ == "__main__": - unittest.main()
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/540d29968e4dcfcb0ab19a713a6d64356...