From 559a8c8b1359dfdb1cf2af2928c8c8b7e31e220b Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Sat, 9 Aug 2008 06:10:04 +0000 Subject: status change tests, hopefully fix some status change issues --- test/lib/mocks.py | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'test/lib') diff --git a/test/lib/mocks.py b/test/lib/mocks.py index 5790dbde6..f5c74f607 100644 --- a/test/lib/mocks.py +++ b/test/lib/mocks.py @@ -3,9 +3,13 @@ from mock import Mock from common import gajim -class MockConnection(Mock): +from common.connection_handlers import ConnectionHandlersBase + +class MockConnection(Mock, ConnectionHandlersBase): def __init__(self, account, *args): Mock.__init__(self, *args) + ConnectionHandlersBase.__init__(self) + self.name = account self.connected = 2 self.mood = {} @@ -13,6 +17,8 @@ class MockConnection(Mock): self.tune = {} self.blocked_contacts = {} self.blocked_groups = {} + self.sessions = {} + gajim.interface.instances[account] = {'infos': {}, 'disco': {}, 'gc_config': {}, 'search': {}} gajim.interface.minimized_controls[account] = {} gajim.contacts.add_account(account) @@ -37,11 +43,39 @@ 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, *args): + 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 @@ -90,9 +124,12 @@ class MockSession(Mock): self.thread_id = '%0x' % random.randint(0, 10000) def __repr__(self): - print '' % self.thread_id + return '' % self.thread_id def __nonzero__(self): return True + def __eq__(self, other): + return self is other + # vim: se ts=3: -- cgit v1.2.3