test: refactoring:

- rename internal init methods to reinit
    - rename getSentMessage to getSentMessageXml
    - rename getSentMessageRaw to getSentMessage
This commit is contained in:
souliane 2014-12-19 11:36:00 +01:00
commit 852106becd

View file

@ -64,12 +64,15 @@ class FakeSAT(object):
self.bridge = FakeBridge()
self.memory = FakeMemory(self)
self.trigger = FakeTriggerManager()
self.init()
self.profiles = {}
self.reinit()
def init(self):
def reinit(self):
"""This can be called by tests that check for sent and stored messages,
uses FakeClient or get/set some other data that need to be cleaned"""
self.sent_messages = []
for profile in self.profiles:
self.profiles[profile].reinit()
self.memory.reinit()
self.stored_messages = []
self.plugins = {}
self.profiles = {}
@ -90,7 +93,7 @@ class FakeSAT(object):
@param mess_data: message data dictionnary
@param client: profile's client
"""
self.sent_messages.append(mess_data["to"])
client.xmlstream.send(mess_data['xml'])
return mess_data
def _storeMessage(self, mess_data, client):
@ -128,13 +131,18 @@ class FakeSAT(object):
def isConnected(self, profile):
return True
def getSentMessageRaw(self, profile_index):
"""Pop and return the sent message in first position (works like a FIFO).
Called by tests. FakeClient instances associated to each profile must have
been previously initialized with the method FakeSAT.getClient.
@return: the sent message for given profile, or None"""
def getSentMessages(self, profile_index):
"""Return all the sent messages (in the order they have been sent) and
empty the list. Called by tests. FakeClient instances associated to each
profile must have been previously initialized with the method
FakeSAT.getClient.
@param profile_index: index of the profile to consider (cf. C.PROFILE)
@return: the sent messages for given profile, or None"""
try:
return self.profiles[C.PROFILE[profile_index]].xmlstream.sent.pop(0)
tmp = self.profiles[C.PROFILE[profile_index]].xmlstream.sent
self.profiles[C.PROFILE[profile_index]].xmlstream.sent = []
return tmp
except IndexError:
return None
@ -142,8 +150,20 @@ class FakeSAT(object):
"""Pop and return the sent message in first position (works like a FIFO).
Called by tests. FakeClient instances associated to each profile must have
been previously initialized with the method FakeSAT.getClient.
@param profile_index: index of the profile to consider (cf. C.PROFILE)
@return: the sent message for given profile, or None"""
try:
return self.profiles[C.PROFILE[profile_index]].xmlstream.sent.pop(0)
except IndexError:
return None
def getSentMessageXml(self, profile_index):
"""Pop and return the sent message in first position (works like a FIFO).
Called by tests. FakeClient instances associated to each profile must have
been previously initialized with the method FakeSAT.getClient.
@return: XML representation of the sent message for given profile, or None"""
entry = self.getSentMessageRaw(profile_index)
entry = self.getSentMessage(profile_index)
return entry.toXml() if entry else None
def findFeaturesSet(self, features, category=None, type_=None, jid_=None, profile_key=None):
@ -258,9 +278,9 @@ class FakeMemory(Memory):
self.host = host
self.params = FakeParams(host, None)
self.config = self.parseMainConf()
self.init()
self.reinit()
def init(self):
def reinit(self):
"""Tests that manipulate params, entities, features should
re-initialise the memory first to not fake the result."""
self.params.load_default_params()
@ -350,6 +370,9 @@ class FakeClient(object):
self.roster = FakeRosterProtocol(host, self)
self.xmlstream = FakeXmlStream()
def reinit(self):
self.xmlstream = FakeXmlStream()
def send(self, obj):
return self.xmlstream.send(obj)