Mercurial > libervia-backend
annotate src/test/helpers.py @ 568:239abc5484c9
bridge: generic plugin methods handling for frontend side in D-Bus Bridge \o/
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 07 Jan 2013 01:01:10 +0100 |
parents | 862c0d6ab974 |
children | ca13633d3b6b |
rev | line source |
---|---|
335 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT: a jabber client | |
459 | 6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org) |
335 | 7 |
8 This program is free software: you can redistribute it and/or modify | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
335 | 10 the Free Software Foundation, either version 3 of the License, or |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
16 GNU Affero General Public License for more details. |
335 | 17 |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
335 | 19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 """ | |
21 | |
22 import __builtin__ | |
23 from twisted.words.protocols.jabber.jid import JID | |
24 | |
25 TEST_JID_STR = u"test@example.org/SàT" | |
26 TEST_JID = JID(u"test@example.org/SàT") | |
27 TEST_PROFILE = 'test_profile' | |
28 | |
29 class DifferentArgsException(Exception): | |
30 pass | |
31 | |
32 class FakeSAT(object): | |
33 """Class to simulate a SAT instance""" | |
34 | |
35 def __init__(self): | |
36 self.bridge = FakeBridge() | |
37 self.memory = FakeMemory() | |
38 self.trigger = FakeTriggerManager() | |
39 | |
40 | |
41 class FakeBridge(object): | |
42 """Class to simulate and test bridge calls""" | |
43 | |
44 def expectCall(self, name, *check_args, **check_kwargs): | |
45 def checkCall(*args, **kwargs): | |
46 if args != check_args or kwargs != check_kwargs: | |
47 print "\n\n--------------------" | |
48 print "Args are not equals:" | |
49 print "args\n----\n%s (sent)\n%s (wanted)" % (args, check_args) | |
50 print "kwargs\n------\n%s (sent)\n%s (wanted)" % (kwargs, check_kwargs) | |
51 print "--------------------\n\n" | |
52 raise DifferentArgsException | |
53 | |
54 setattr(self, name, checkCall) | |
55 | |
56 | |
57 class FakeMemory(object): | |
58 """Class to simulate and test memory object""" | |
59 | |
60 def getProfileName(self, profile_key): | |
61 return profile_key | |
62 | |
512
862c0d6ab974
core, bridge, quick_frontend: MUC private messages history management:
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
63 def addToHistory(self, from_jid, to_jid, message, _type='chat', timestamp=None, profile=None): |
335 | 64 pass |
65 | |
66 def addContact(self, contact_jid, attributes, groups, profile_key='@DEFAULT@'): | |
67 pass | |
68 | |
484
23cbdf0a0777
core: presence status + last resource refactored and kept in entitiesCache in memory.py, profile cache is purged on disconnection
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
69 def setPresenceStatus(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'): |
335 | 70 pass |
71 | |
72 def addWaitingSub(self, type, contact_jid, profile_key): | |
73 pass | |
74 | |
75 def delWaitingSub(self, contact_jid, profile_key): | |
76 pass | |
77 | |
78 class FakeTriggerManager(object): | |
79 | |
80 def add(self, point_name, callback): | |
81 pass | |
82 | |
83 def point(self, point_name, *args, **kwargs): | |
84 """We always return true to continue the action""" | |
85 return True | |
86 | |
87 class FakeParent(object): | |
88 def __init__(self): | |
89 self.profile = 'test_profile' | |
90 self.jid = TEST_JID | |
91 | |
92 def _(text): | |
93 return text | |
94 | |
95 __builtin__.__dict__['_'] = _ |