diff options
Diffstat (limited to 'test/lib')
-rw-r--r-- | test/lib/mocks.py | 43 |
1 files changed, 40 insertions, 3 deletions
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 '<MockSession %s>' % self.thread_id + return '<MockSession %s>' % self.thread_id def __nonzero__(self): return True + def __eq__(self, other): + return self is other + # vim: se ts=3: |