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

gajim_mocks.py « lib « test - dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0b25fa0212039156cc408e0abc5d356918623494 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'''
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': {},
                'gc_config': {}, 'search': {}, 'sub_request': {}}
        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.last_message_time[account] = {}

        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