Mercurial > libervia-backend
annotate src/test/helpers.py @ 447:485a6d125498
Wix: fixed asynchronous call to get profile's data in profile manager
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 04 Dec 2011 00:58:20 +0100 |
parents | e4e9187e3b5b |
children | cf005701624b |
rev | line source |
---|---|
335 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SAT: a jabber client | |
6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
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 | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
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 | |
425
e4e9187e3b5b
backend, bridge: asynchronous history
Goffi <goffi@goffi.org>
parents:
335
diff
changeset
|
63 def addToHistory(self, from_jid, to_jid, message, timestamp=None, profile=None): |
335 | 64 pass |
65 | |
66 def addContact(self, contact_jid, attributes, groups, profile_key='@DEFAULT@'): | |
67 pass | |
68 | |
69 def addPresenceStatus(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'): | |
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__['_'] = _ |