test: FakeMemory inherits from Memory + more helpers basic support + cleaning

This commit is contained in:
souliane 2014-01-05 13:04:54 +01:00
commit 96b1d58eb7

View file

@ -40,13 +40,16 @@ class XEP_0085Test(helpers.SatTestCase):
self.host.memory.init()
self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, NO_SECURITY_LIMIT, Const.TEST_PROFILE)
for state in plugin.CHAT_STATES:
xml = """
<message type="chat" from="sender@example.net/house" to="sender@example.net/house" id="test_1">
xml = u"""
<message type="chat" from="%s" to="%s" id="test_1">
%s
<%s xmlns='http://jabber.org/protocol/chatstates'/>
<%s xmlns='%s'/>
</message>
""" % ("<body>test</body>" if state == "active" else "", state)
stanza = parseXml(xml)
""" % (Const.TEST_JID_2_STR,
Const.TEST_JID_STR,
"<body>test</body>" if state == "active" else "",
state, plugin.NS_CHAT_STATES)
stanza = parseXml(xml.encode("utf-8"))
self.host.bridge.expectCall("chatStateReceived", u"sender@example.net/house", state, Const.TEST_PROFILE)
self.plugin.messageReceivedTrigger(stanza, defer.Deferred(), Const.TEST_PROFILE)
@ -54,15 +57,17 @@ class XEP_0085Test(helpers.SatTestCase):
self.host.memory.init()
self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, NO_SECURITY_LIMIT, Const.TEST_PROFILE)
for state in plugin.CHAT_STATES:
mess_data = {"to": "test@example.org/SàT",
mess_data = {"to": Const.TEST_JID,
"type": "chat",
"message": "content",
"extra": {} if state == "active" else {"chat_state": state}}
mess_data['xml'] = parseXml("""
<message type="chat" from="sender@example.net/house" to="test@example.org/SàT" id="test_1">
stanza = u"""
<message type="chat" from="%s" to="%s" id="test_1">
%s
</message>
""" % (("<body>%s</body>" % mess_data['message']) if state == "active" else "",))
""" % (Const.TEST_JID_2_STR, Const.TEST_JID_STR,
("<body>%s</body>" % mess_data['message']) if state == "active" else "")
mess_data['xml'] = parseXml(stanza.encode("utf-8"))
expected = deepcopy(mess_data['xml'])
expected.addElement(state, plugin.NS_CHAT_STATES)
treatments = defer.Deferred()