annotate src/test/test_plugin_xep_0085.py @ 970:2e052998c7eb

jp: using C.APP_URL for application url
author Goffi <goffi@goffi.org>
date Wed, 02 Apr 2014 12:11:07 +0200
parents 861593a5652b
children 87fbe4640448
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
783
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/usr/bin/python
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
3
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
4 # SAT: a jabber client
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 792
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 792
diff changeset
6 # Copyright (C) 2013, 2014 Adrien Cossa (souliane@mailoo.org)
783
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
7
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or modify
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
11 # (at your option) any later version.
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
12
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful,
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
16 # GNU Affero General Public License for more details.
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
17
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
20
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
21 """ Plugin chat states notification tests """
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
22
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
23 from constants import Const
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
24 from sat.test import helpers
915
6f96ee4d8cc0 tests: tests fixes
Goffi <goffi@goffi.org>
parents: 811
diff changeset
25 from sat.core.constants import Const as C
783
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
26 from sat.plugins import plugin_xep_0085 as plugin
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from copy import deepcopy
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
28 from twisted.internet import defer
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
29 from wokkel.generic import parseXml
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
30 from twisted.words.protocols.jabber.jid import JID
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
31
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
32
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
33 class XEP_0085Test(helpers.SatTestCase):
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
34
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
35 def setUp(self):
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
36 self.host = helpers.FakeSAT()
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
37 self.plugin = plugin.XEP_0085(self.host)
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
38
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
39 def test_messageReceived(self):
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
40 self.host.memory.init()
915
6f96ee4d8cc0 tests: tests fixes
Goffi <goffi@goffi.org>
parents: 811
diff changeset
41 self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, C.NO_SECURITY_LIMIT, Const.PROFILE[0])
783
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
42 for state in plugin.CHAT_STATES:
786
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 783
diff changeset
43 xml = u"""
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 783
diff changeset
44 <message type="chat" from="%s" to="%s" id="test_1">
783
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
45 %s
786
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 783
diff changeset
46 <%s xmlns='%s'/>
783
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
47 </message>
792
2136be5a44a8 test: define the constants JIDs and profiles as lists
souliane <souliane@mailoo.org>
parents: 786
diff changeset
48 """ % (Const.JID_STR[1],
2136be5a44a8 test: define the constants JIDs and profiles as lists
souliane <souliane@mailoo.org>
parents: 786
diff changeset
49 Const.JID_STR[0],
786
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 783
diff changeset
50 "<body>test</body>" if state == "active" else "",
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 783
diff changeset
51 state, plugin.NS_CHAT_STATES)
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 783
diff changeset
52 stanza = parseXml(xml.encode("utf-8"))
792
2136be5a44a8 test: define the constants JIDs and profiles as lists
souliane <souliane@mailoo.org>
parents: 786
diff changeset
53 self.host.bridge.expectCall("chatStateReceived", Const.JID_STR[1], state, Const.PROFILE[0])
2136be5a44a8 test: define the constants JIDs and profiles as lists
souliane <souliane@mailoo.org>
parents: 786
diff changeset
54 self.plugin.messageReceivedTrigger(stanza, defer.Deferred(), Const.PROFILE[0])
783
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
55
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
56 def test_sendMessageTrigger(self):
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
57 self.host.memory.init()
915
6f96ee4d8cc0 tests: tests fixes
Goffi <goffi@goffi.org>
parents: 811
diff changeset
58 self.host.memory.setParam(plugin.PARAM_NAME, True, plugin.PARAM_KEY, C.NO_SECURITY_LIMIT, Const.PROFILE[0])
783
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
59 for state in plugin.CHAT_STATES:
792
2136be5a44a8 test: define the constants JIDs and profiles as lists
souliane <souliane@mailoo.org>
parents: 786
diff changeset
60 mess_data = {"to": Const.JID[0],
783
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
61 "type": "chat",
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
62 "message": "content",
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
63 "extra": {} if state == "active" else {"chat_state": state}}
786
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 783
diff changeset
64 stanza = u"""
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 783
diff changeset
65 <message type="chat" from="%s" to="%s" id="test_1">
783
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
66 %s
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
67 </message>
792
2136be5a44a8 test: define the constants JIDs and profiles as lists
souliane <souliane@mailoo.org>
parents: 786
diff changeset
68 """ % (Const.JID_STR[1], Const.JID_STR[0],
786
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 783
diff changeset
69 ("<body>%s</body>" % mess_data['message']) if state == "active" else "")
c3acc1298a2f test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents: 783
diff changeset
70 mess_data['xml'] = parseXml(stanza.encode("utf-8"))
783
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
71 expected = deepcopy(mess_data['xml'])
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
72 expected.addElement(state, plugin.NS_CHAT_STATES)
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
73 treatments = defer.Deferred()
924
861593a5652b test: fix tests fo plugins XEP-0033 and XEP-0085
souliane <souliane@mailoo.org>
parents: 915
diff changeset
74 self.plugin.sendMessageTrigger(mess_data, defer.Deferred(), treatments, Const.PROFILE[0])
783
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
75 xml = treatments.callbacks[0][0][0](mess_data)
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
76 # cancel the timer to not block the process
792
2136be5a44a8 test: define the constants JIDs and profiles as lists
souliane <souliane@mailoo.org>
parents: 786
diff changeset
77 self.plugin.map[Const.PROFILE[0]][Const.JID[0].userhostJID()].timer.cancel()
783
27581cddb758 test: added tests for XEP-0085
souliane <souliane@mailoo.org>
parents:
diff changeset
78 self.assertEqualXML(xml['xml'].toXml().encode("utf-8"), expected.toXml().encode("utf-8"))