comparison src/test/helpers.py @ 999:c37a24922f27

plugin XEP_0033: fixes the server part and the tests
author souliane <souliane@mailoo.org>
date Fri, 11 Apr 2014 11:02:42 +0200
parents f5761534e0f3
children 002ee8397208
comparison
equal deleted inserted replaced
998:f5761534e0f3 999:c37a24922f27
91 """Save the information to check later to whom messages have been sent and 91 """Save the information to check later to whom messages have been sent and
92 if entries have been added to the history""" 92 if entries have been added to the history"""
93 if not skip_send: 93 if not skip_send:
94 self.sent_messages.append(mess_data["to"]) 94 self.sent_messages.append(mess_data["to"])
95 self.stored_messages.append(mess_data["to"]) 95 self.stored_messages.append(mess_data["to"])
96 pass
97 96
98 def getClient(self, profile_key): 97 def getClient(self, profile_key):
99 """Convenient method to get client from profile key 98 """Convenient method to get client from profile key
100 @return: client or None if it doesn't exist""" 99 @return: client or None if it doesn't exist"""
101 profile = self.memory.getProfileName(profile_key) 100 profile = self.memory.getProfileName(profile_key)
128 Called by tests. FakeClient instances associated to each profile must have 127 Called by tests. FakeClient instances associated to each profile must have
129 been previously initialized with the method FakeSAT.getClient. 128 been previously initialized with the method FakeSAT.getClient.
130 @return: XML representation of the sent message for given profile, or None""" 129 @return: XML representation of the sent message for given profile, or None"""
131 entry = self.getSentMessageRaw(profile_index) 130 entry = self.getSentMessageRaw(profile_index)
132 return entry.toXml() if entry else None 131 return entry.toXml() if entry else None
132
133 def findFeaturesSet(self, features, category=None, type_=None, jid_=None, profile_key=None):
134 """Call self.addFeature from your tests to change the return value.
135
136 @return: a set of entities
137 """
138 client = self.getClient(profile_key)
139 if jid_ is None:
140 jid_ = JID(client.jid.host)
141 try:
142 if set(features).issubset(client.features[jid_]):
143 return defer.succeed(set([jid_]))
144 except (TypeError, AttributeError, KeyError):
145 pass
146 return defer.succeed(set())
147
148 def addFeature(self, jid_, feature, profile_key):
149 """Add a feature to an entity.
150
151 To be called from your tests when needed.
152 """
153 client = self.getClient(profile_key)
154 if not hasattr(client, 'features'):
155 client.features = {}
156 if jid_ not in client.features:
157 client.features[jid_] = set()
158 client.features[jid_].add(feature)
133 159
134 160
135 class FakeBridge(object): 161 class FakeBridge(object):
136 """Class to simulate and test bridge calls""" 162 """Class to simulate and test bridge calls"""
137 163