Mercurial > libervia-backend
comparison src/test/helpers.py @ 1269:91e5becc6623
test: add tests for plugin_misc_groupblog
author | souliane <souliane@mailoo.org> |
---|---|
date | Mon, 15 Dec 2014 14:05:28 +0100 |
parents | 020e663bc286 |
children | 2308f8405ffb |
comparison
equal
deleted
inserted
replaced
1268:bb30bf3ae932 | 1269:91e5becc6623 |
---|---|
21 ## logging configuration for tests ## | 21 ## logging configuration for tests ## |
22 from sat.core import log_config | 22 from sat.core import log_config |
23 log_config.satConfigure() | 23 log_config.satConfigure() |
24 | 24 |
25 from sat.core import exceptions | 25 from sat.core import exceptions |
26 from constants import Const | 26 from constants import Const as C |
27 from wokkel.xmppim import RosterItem | 27 from wokkel.xmppim import RosterItem |
28 from sat.core.xmpp import SatRosterProtocol | 28 from sat.core.xmpp import SatRosterProtocol |
29 from sat.memory.memory import Params, Memory | 29 from sat.memory.memory import Params, Memory |
30 from twisted.trial.unittest import FailTest | 30 from twisted.trial.unittest import FailTest |
31 from twisted.trial import unittest | 31 from twisted.trial import unittest |
121 return self.profiles[profile] | 121 return self.profiles[profile] |
122 | 122 |
123 def getJidNStream(self, profile_key): | 123 def getJidNStream(self, profile_key): |
124 """Convenient method to get jid and stream from profile key | 124 """Convenient method to get jid and stream from profile key |
125 @return: tuple (jid, xmlstream) from profile, can be None""" | 125 @return: tuple (jid, xmlstream) from profile, can be None""" |
126 return (Const.PROFILE_DICT[profile_key], None) | 126 return (C.PROFILE_DICT[profile_key], None) |
127 | 127 |
128 def isConnected(self, profile): | 128 def isConnected(self, profile): |
129 return True | 129 return True |
130 | 130 |
131 def getSentMessageRaw(self, profile_index): | 131 def getSentMessageRaw(self, profile_index): |
132 """Pop and return the sent message in first position (works like a FIFO). | 132 """Pop and return the sent message in first position (works like a FIFO). |
133 Called by tests. FakeClient instances associated to each profile must have | 133 Called by tests. FakeClient instances associated to each profile must have |
134 been previously initialized with the method FakeSAT.getClient. | 134 been previously initialized with the method FakeSAT.getClient. |
135 @return: the sent message for given profile, or None""" | 135 @return: the sent message for given profile, or None""" |
136 try: | 136 try: |
137 return self.profiles[Const.PROFILE[profile_index]].xmlstream.sent.pop(0) | 137 return self.profiles[C.PROFILE[profile_index]].xmlstream.sent.pop(0) |
138 except IndexError: | 138 except IndexError: |
139 return None | 139 return None |
140 | 140 |
141 def getSentMessage(self, profile_index): | 141 def getSentMessage(self, profile_index): |
142 """Pop and return the sent message in first position (works like a FIFO). | 142 """Pop and return the sent message in first position (works like a FIFO). |
236 profile = self.getProfileName(profile_key) | 236 profile = self.getProfileName(profile_key) |
237 return self.params[profile][(category, name)] | 237 return self.params[profile][(category, name)] |
238 | 238 |
239 def getProfileName(self, profile_key, return_profile_keys=False): | 239 def getProfileName(self, profile_key, return_profile_keys=False): |
240 if profile_key == '@DEFAULT@': | 240 if profile_key == '@DEFAULT@': |
241 return Const.PROFILE[0] | 241 return C.PROFILE[0] |
242 elif profile_key == '@NONE@': | 242 elif profile_key == '@NONE@': |
243 raise exceptions.ProfileNotSetError | 243 raise exceptions.ProfileNotSetError |
244 else: | 244 else: |
245 return profile_key | 245 return profile_key |
246 | 246 |
343 class FakeClient(object): | 343 class FakeClient(object): |
344 """Tests involving more than one profile need one instance of this class per profile""" | 344 """Tests involving more than one profile need one instance of this class per profile""" |
345 | 345 |
346 def __init__(self, host, profile=None): | 346 def __init__(self, host, profile=None): |
347 self.host = host | 347 self.host = host |
348 self.profile = profile if profile else Const.PROFILE[0] | 348 self.profile = profile if profile else C.PROFILE[0] |
349 self.jid = Const.PROFILE_DICT[self.profile] | 349 self.jid = C.PROFILE_DICT[self.profile] |
350 self.roster = FakeRosterProtocol(host, self) | 350 self.roster = FakeRosterProtocol(host, self) |
351 self.xmlstream = FakeXmlStream() | 351 self.xmlstream = FakeXmlStream() |
352 | 352 |
353 def send(self, obj): | 353 def send(self, obj): |
354 return self.xmlstream.send(obj) | 354 return self.xmlstream.send(obj) |