Mercurial > libervia-backend
annotate src/test/helpers.py @ 652:8664a72442d6
install: minimum required wokkel version is now 0.7.1, updated setup.py
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 04 Oct 2013 12:22:51 +0200 |
parents | e20c823f23e2 |
children | ffb716804580 |
rev | line source |
---|---|
335 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
4 # SAT: a jabber client |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org) |
335 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
10 # (at your option) any later version. |
335 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
15 # GNU Affero General Public License for more details. |
335 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
335 | 19 |
20 import __builtin__ | |
21 from twisted.words.protocols.jabber.jid import JID | |
649 | 22 from wokkel.xmppim import RosterItem |
23 from sat.core.xmpp import SatRosterProtocol | |
647
63b6e684bbfa
tests: Use of FailTest for DifferentArgsException instead of Exception, so the test fail instead of raising en error.
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
24 from twisted.trial.unittest import FailTest |
335 | 25 |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
26 TEST_JID_STR = u"test@example.org/SàT" |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
27 TEST_JID = JID(u"test@example.org/SàT") |
335 | 28 TEST_PROFILE = 'test_profile' |
29 | |
649 | 30 def b2s(value): |
31 """Convert a bool to a unicode string used in bridge | |
32 @param value: boolean value | |
33 @return: unicode conversion, according to bridge convention | |
34 | |
35 """ | |
36 return u"True" if value else u"False" | |
591
65821b3fa7ab
Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
37 |
647
63b6e684bbfa
tests: Use of FailTest for DifferentArgsException instead of Exception, so the test fail instead of raising en error.
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
38 class DifferentArgsException(FailTest): |
335 | 39 pass |
40 | |
591
65821b3fa7ab
Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
41 |
335 | 42 class FakeSAT(object): |
43 """Class to simulate a SAT instance""" | |
44 | |
45 def __init__(self): | |
46 self.bridge = FakeBridge() | |
47 self.memory = FakeMemory() | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
48 self.trigger = FakeTriggerManager() |
335 | 49 |
649 | 50 def delContact(self, to, profile_key): |
51 #TODO | |
52 pass | |
53 | |
335 | 54 |
55 class FakeBridge(object): | |
56 """Class to simulate and test bridge calls""" | |
57 | |
58 def expectCall(self, name, *check_args, **check_kwargs): | |
59 def checkCall(*args, **kwargs): | |
60 if args != check_args or kwargs != check_kwargs: | |
61 print "\n\n--------------------" | |
62 print "Args are not equals:" | |
63 print "args\n----\n%s (sent)\n%s (wanted)" % (args, check_args) | |
64 print "kwargs\n------\n%s (sent)\n%s (wanted)" % (kwargs, check_kwargs) | |
65 print "--------------------\n\n" | |
66 raise DifferentArgsException | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
67 |
335 | 68 setattr(self, name, checkCall) |
69 | |
70 | |
71 class FakeMemory(object): | |
72 """Class to simulate and test memory object""" | |
73 | |
74 def getProfileName(self, profile_key): | |
75 return profile_key | |
76 | |
512
862c0d6ab974
core, bridge, quick_frontend: MUC private messages history management:
Goffi <goffi@goffi.org>
parents:
484
diff
changeset
|
77 def addToHistory(self, from_jid, to_jid, message, _type='chat', timestamp=None, profile=None): |
335 | 78 pass |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
79 |
335 | 80 def addContact(self, contact_jid, attributes, groups, profile_key='@DEFAULT@'): |
81 pass | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
82 |
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
|
83 def setPresenceStatus(self, contact_jid, show, priority, statuses, profile_key='@DEFAULT@'): |
335 | 84 pass |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
85 |
335 | 86 def addWaitingSub(self, type, contact_jid, profile_key): |
87 pass | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
88 |
335 | 89 def delWaitingSub(self, contact_jid, profile_key): |
90 pass | |
91 | |
591
65821b3fa7ab
Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
92 |
335 | 93 class FakeTriggerManager(object): |
94 | |
95 def add(self, point_name, callback): | |
96 pass | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
97 |
335 | 98 def point(self, point_name, *args, **kwargs): |
99 """We always return true to continue the action""" | |
100 return True | |
101 | |
649 | 102 class FakeRosterProtocol(SatRosterProtocol): |
591
65821b3fa7ab
Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
103 |
649 | 104 def __init__(self, host, parent): |
105 SatRosterProtocol.__init__(self, host) | |
106 self.parent = parent | |
107 self.addItem(TEST_JID) | |
108 | |
109 def addItem(self, jid, *args, **kwargs): | |
110 if not args and not kwargs: | |
111 # defaults values setted for the tests only | |
112 kwargs["subscriptionTo"] = True | |
113 kwargs["subscriptionFrom"] = True | |
114 roster_item = RosterItem(jid, *args, **kwargs) | |
115 attrs = {'to': b2s(roster_item.subscriptionTo), 'from': b2s(roster_item.subscriptionFrom), 'ask': b2s(roster_item.pendingOut)} | |
116 if roster_item.name: | |
117 attrs['name'] = roster_item.name | |
118 self.host.bridge.expectCall("newContact", jid.full(), attrs, roster_item.groups, self.parent.profile) | |
119 self.onRosterSet(roster_item) | |
120 | |
121 | |
122 class FakeClient(object): | |
123 def __init__(self, host): | |
124 self.host = host | |
335 | 125 self.profile = 'test_profile' |
126 self.jid = TEST_JID | |
649 | 127 self.roster = FakeRosterProtocol(host, self) |
128 | |
129 def send(self, obj): | |
130 pass | |
335 | 131 |
591
65821b3fa7ab
Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
132 |
335 | 133 def _(text): |
134 return text | |
135 | |
136 __builtin__.__dict__['_'] = _ |