Mercurial > libervia-backend
comparison src/test/helpers.py @ 944:e1842ebcb2f3
core, plugin XEP-0115: discovery refactoring:
- hashing algorithm of XEP-0115 has been including in core
- our own hash is still calculated by XEP-0115 and can be regenerated with XEP_0115.recalculateHash
- old discovery methods have been removed. Now the following methods are used:
- hasFeature: tell if a feature is available for an entity
- getDiscoInfos: self explaining
- getDiscoItems: self explaining
- findServiceEntities: return all available items of an entity which given (category, type)
- findFeaturesSet: search for a set of features in entity + entity's items
all these methods are asynchronous, and manage cache automatically
- XEP-0115 manage in a better way hashes, and now use a trigger for presence instead of monkey patch
- new FeatureNotFound exception, when we want to do something which is not available
- refactored client initialisation sequence, removed client.initialized Deferred
- added constant APP_URL
- test_plugin_xep_0033.py has been temporarly deactivated, the time to adapt it
- lot of cleaning
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 28 Mar 2014 18:07:22 +0100 |
parents | c6d8fc63b1db |
children | b3f383ab39da |
comparison
equal
deleted
inserted
replaced
943:71926ec2114d | 944:e1842ebcb2f3 |
---|---|
88 if not skip_send: | 88 if not skip_send: |
89 self.sent_messages.append(mess_data["to"]) | 89 self.sent_messages.append(mess_data["to"]) |
90 self.stored_messages.append(mess_data["to"]) | 90 self.stored_messages.append(mess_data["to"]) |
91 pass | 91 pass |
92 | 92 |
93 def requestServerDisco(self, feature, jid_=None, cache_only=False, profile_key="@NONE"): | |
94 """Discover if a server or its items offer a given feature | |
95 @param feature: the feature to check | |
96 @param jid_: the jid of the server, local server if None | |
97 @param cache_only: expect the result to be in cache and don't actually | |
98 make any request. This can be used anytime for requesting a feature on | |
99 the local server because the data are cached for sure. | |
100 @result: the Deferred entity jid offering the feature, or None | |
101 """ | |
102 profile = self.memory.getProfileName(profile_key) | |
103 self.memory.server_features.setdefault(profile, {}) | |
104 if jid_ is None: | |
105 jid_ = self.getClientHostJid(profile_key) | |
106 # call FakeMemory.init and FakeMemory.addServerFeature | |
107 # in your tests to change the return value of this method | |
108 return defer.succeed(jid_ if self.memory.hasServerFeature(feature, jid_, profile_key) else None) | |
109 | |
110 def getClientHostJid(self, profile_key): | |
111 return Const.PROFILE_DICT[profile_key].host | |
112 | |
113 def getClient(self, profile_key): | 93 def getClient(self, profile_key): |
114 """Convenient method to get client from profile key | 94 """Convenient method to get client from profile key |
115 @return: client or None if it doesn't exist""" | 95 @return: client or None if it doesn't exist""" |
116 profile = self.memory.getProfileName(profile_key) | 96 profile = self.memory.getProfileName(profile_key) |
117 if not profile: | 97 if not profile: |
118 raise exceptions.ProfileKeyUnknownError | 98 raise exceptions.ProfileKeyUnknownError |
119 if profile not in self.profiles: | 99 if profile not in self.profiles: |
120 self.profiles[profile] = FakeClient(self, profile) | 100 self.profiles[profile] = FakeClient(self, profile) |
121 self.profiles[profile].client_initialized.callback(None) | |
122 return self.profiles[profile] | 101 return self.profiles[profile] |
123 | 102 |
124 def getJidNStream(self, profile_key): | 103 def getJidNStream(self, profile_key): |
125 """Convenient method to get jid and stream from profile key | 104 """Convenient method to get jid and stream from profile key |
126 @return: tuple (jid, xmlstream) from profile, can be None""" | 105 @return: tuple (jid, xmlstream) from profile, can be None""" |
239 re-initialise the memory first to not fake the result.""" | 218 re-initialise the memory first to not fake the result.""" |
240 self.params.load_default_params() | 219 self.params.load_default_params() |
241 self.params.params.clear() | 220 self.params.params.clear() |
242 self.params.frontends_cache = [] | 221 self.params.frontends_cache = [] |
243 self.entities_data = {} | 222 self.entities_data = {} |
244 self.server_features = {} | |
245 | 223 |
246 def getProfileName(self, profile_key, return_profile_keys=False): | 224 def getProfileName(self, profile_key, return_profile_keys=False): |
247 return self.params.getProfileName(profile_key, return_profile_keys) | 225 return self.params.getProfileName(profile_key, return_profile_keys) |
248 | 226 |
249 def addToHistory(self, from_jid, to_jid, message, _type='chat', extra=None, timestamp=None, profile="@NONE@"): | 227 def addToHistory(self, from_jid, to_jid, message, _type='chat', extra=None, timestamp=None, profile="@NONE@"): |
321 def __init__(self, host, profile=None): | 299 def __init__(self, host, profile=None): |
322 self.host = host | 300 self.host = host |
323 self.profile = profile if profile else Const.PROFILE[0] | 301 self.profile = profile if profile else Const.PROFILE[0] |
324 self.jid = Const.PROFILE_DICT[self.profile] | 302 self.jid = Const.PROFILE_DICT[self.profile] |
325 self.roster = FakeRosterProtocol(host, self) | 303 self.roster = FakeRosterProtocol(host, self) |
326 self.client_initialized = defer.Deferred() | |
327 self.xmlstream = FakeXmlStream() | 304 self.xmlstream = FakeXmlStream() |
328 | 305 |
329 def send(self, obj): | 306 def send(self, obj): |
330 return self.xmlstream.send(obj) | 307 return self.xmlstream.send(obj) |
331 | 308 |