2009-01-11 14:49:03 +01:00
|
|
|
'''
|
|
|
|
Module with dummy classes for Gajim specific unit testing
|
|
|
|
'''
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2018-11-11 01:31:50 +01:00
|
|
|
from .mock import Mock
|
2017-08-13 13:18:56 +02:00
|
|
|
from gajim.common import app
|
2017-08-12 02:39:55 +02:00
|
|
|
from gajim.common import ged
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2017-08-12 02:39:55 +02:00
|
|
|
from gajim.common.connection_handlers import ConnectionHandlers
|
2008-08-09 08:10:04 +02:00
|
|
|
|
2013-04-07 23:41:15 +02:00
|
|
|
class MockConnection(Mock, ConnectionHandlers):
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self, account, *args):
|
|
|
|
Mock.__init__(self, *args)
|
2013-04-08 18:57:39 +02:00
|
|
|
|
|
|
|
self.connection = Mock()
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
self.name = account
|
2013-04-08 18:57:39 +02:00
|
|
|
|
|
|
|
ConnectionHandlers.__init__(self)
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.connected = 2
|
|
|
|
self.pep = {}
|
|
|
|
self.sessions = {}
|
2017-06-14 20:25:06 +02:00
|
|
|
self.server_resource = 'Gajim'
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface.instances[account] = {'infos': {}, 'disco': {},
|
2011-05-23 22:35:19 +02:00
|
|
|
'gc_config': {}, 'search': {}, 'sub_request': {}}
|
2017-08-13 13:18:56 +02:00
|
|
|
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.config.get_per('accounts', account, 'name')
|
|
|
|
app.block_signed_in_notifications[account] = True
|
|
|
|
app.sleeper_state[account] = 0
|
|
|
|
app.last_message_time[account] = {}
|
|
|
|
app.status_before_autoaway[account] = ''
|
|
|
|
app.gajim_optional_features[account] = []
|
|
|
|
app.caps_hash[account] = ''
|
|
|
|
|
|
|
|
app.connections[account] = self
|
2008-06-04 01:54:22 +02:00
|
|
|
|
|
|
|
class MockWindow(Mock):
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self, *args):
|
|
|
|
Mock.__init__(self, *args)
|
|
|
|
self.window = Mock()
|
|
|
|
self._controls = {}
|
2008-08-09 08:10:04 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def get_control(self, jid, account):
|
|
|
|
try:
|
|
|
|
return self._controls[account][jid]
|
|
|
|
except KeyError:
|
|
|
|
return None
|
2008-08-09 08:10:04 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def has_control(self, jid, acct):
|
|
|
|
return self.get_control(jid, acct) is not None
|
2008-08-09 08:10:04 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def new_tab(self, ctrl):
|
|
|
|
account = ctrl.account
|
|
|
|
jid = ctrl.jid
|
2008-08-09 08:10:04 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
if account not in self._controls:
|
|
|
|
self._controls[account] = {}
|
2008-08-09 08:10:04 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
if jid not in self._controls[account]:
|
|
|
|
self._controls[account][jid] = {}
|
2008-08-09 08:10:04 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self._controls[account][jid] = ctrl
|
2008-08-09 08:10:04 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def __nonzero__(self):
|
|
|
|
return True
|
2008-06-04 01:54:22 +02:00
|
|
|
|
|
|
|
class MockChatControl(Mock):
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self, jid, account, *args):
|
|
|
|
Mock.__init__(self, *args)
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.jid = jid
|
|
|
|
self.account = account
|
2008-08-09 08:10:04 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.parent_win = MockWindow({'get_active_control': self})
|
|
|
|
self.session = None
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def set_session(self, sess):
|
|
|
|
self.session = sess
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def __nonzero__(self):
|
|
|
|
return True
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def __eq__(self, other):
|
|
|
|
return self is other
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2009-11-05 09:06:46 +01:00
|
|
|
|
2008-06-04 01:54:22 +02:00
|
|
|
class MockInterface(Mock):
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self, *args):
|
|
|
|
Mock.__init__(self, *args)
|
2017-08-13 13:18:56 +02:00
|
|
|
app.interface = self
|
2010-02-08 15:08:40 +01:00
|
|
|
self.msg_win_mgr = Mock()
|
|
|
|
self.roster = Mock()
|
2017-08-13 13:18:56 +02:00
|
|
|
app.ged = ged.GlobalEventsDispatcher()
|
2017-09-15 15:11:55 +02:00
|
|
|
from gajim import plugins
|
2017-08-13 13:18:56 +02:00
|
|
|
app.plugin_manager = plugins.PluginManager()
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.remote_ctrl = None
|
|
|
|
self.instances = {}
|
|
|
|
self.minimized_controls = {}
|
|
|
|
self.status_sent_to_users = Mock()
|
2008-08-06 22:17:00 +02:00
|
|
|
|
2017-08-13 13:18:56 +02:00
|
|
|
if app.use_x:
|
2013-04-07 23:41:15 +02:00
|
|
|
self.jabber_state_images = {'16': {}, '24': {}, '32': {},
|
|
|
|
'opened': {}, 'closed': {}}
|
2008-08-27 09:55:06 +02:00
|
|
|
|
2017-09-15 15:11:55 +02:00
|
|
|
from gajim import gtkgui_helpers
|
2010-02-08 15:08:40 +01:00
|
|
|
gtkgui_helpers.make_jabber_state_images()
|
|
|
|
else:
|
2013-04-07 23:41:15 +02:00
|
|
|
self.jabber_state_images = {'16': Mock(), '24': Mock(),
|
|
|
|
'32': Mock(), 'opened': Mock(), 'closed': Mock()}
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2009-11-05 09:06:46 +01:00
|
|
|
|
2008-06-04 01:54:22 +02:00
|
|
|
class MockLogger(Mock):
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self):
|
2017-08-09 15:34:58 +02:00
|
|
|
Mock.__init__(self, {'insert_into_logs': None,
|
|
|
|
'get_transports_type': {}})
|
2013-04-08 18:57:39 +02:00
|
|
|
self.cur = Mock()
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2009-11-05 09:06:46 +01:00
|
|
|
|
2008-06-04 01:54:22 +02:00
|
|
|
class MockContact(Mock):
|
2010-02-08 15:08:40 +01:00
|
|
|
def __nonzero__(self):
|
|
|
|
return True
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2009-11-05 09:06:46 +01:00
|
|
|
|
2008-06-04 01:54:22 +02:00
|
|
|
import random
|
|
|
|
|
|
|
|
class MockSession(Mock):
|
2010-02-08 15:08:40 +01:00
|
|
|
def __init__(self, conn, jid, thread_id, type_):
|
|
|
|
Mock.__init__(self)
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
self.conn = conn
|
|
|
|
self.jid = jid
|
2012-08-22 12:55:57 +02:00
|
|
|
self.type_ = type_
|
2010-02-08 15:08:40 +01:00
|
|
|
self.thread_id = thread_id
|
2013-04-08 18:57:39 +02:00
|
|
|
self.resource = ''
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
if not self.thread_id:
|
|
|
|
self.thread_id = '%0x' % random.randint(0, 10000)
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def __repr__(self):
|
|
|
|
return '<MockSession %s>' % self.thread_id
|
2008-06-04 01:54:22 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def __nonzero__(self):
|
|
|
|
return True
|
2008-07-29 21:49:31 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def __eq__(self, other):
|
|
|
|
return self is other
|