annotate src/test/test_plugin_xep_0297.py @ 2186:9061c7247964

jp (std output): force unicode on simple output
author Goffi <goffi@goffi.org>
date Sun, 12 Mar 2017 23:29:09 +0100
parents 2daf7b4c6756
children 8b37a62336c3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
1 #!/usr/bin/env python2
1274
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
3
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
4 # SAT: a jabber client
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
1274
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
7
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or modify
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
11 # (at your option) any later version.
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
12
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful,
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
16 # GNU Affero General Public License for more details.
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
17
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
20
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
21 """ Plugin XEP-0297 """
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
22
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
23 from constants import Const as C
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
24 from sat.test import helpers
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
25 from sat.plugins.plugin_xep_0203 import XEP_0203
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
26 from sat.plugins.plugin_xep_0297 import XEP_0297
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from twisted.words.protocols.jabber.jid import JID
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
28 from dateutil.tz import tzutc
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
29 import datetime
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
30 from wokkel.generic import parseXml
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
31
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
32
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
33 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
34
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
35
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
36 class XEP_0297Test(helpers.SatTestCase):
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
37
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
38 def setUp(self):
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
39 self.host = helpers.FakeSAT()
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
40 self.plugin = XEP_0297(self.host)
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
41 self.host.plugins['XEP-0203'] = XEP_0203(self.host)
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
42
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
43 def test_delay(self):
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
44 stanza = parseXml("""
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
45 <message from='juliet@capulet.lit/orchard'
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
46 id='0202197'
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
47 to='romeo@montague.lit'
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
48 type='chat'>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
49 <body>Yet I should kill thee with much cherishing.</body>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
50 <mood xmlns='http://jabber.org/protocol/mood'>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
51 <amorous/>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
52 </mood>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
53 </message>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
54 """.encode('utf-8'))
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
55 output = """
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
56 <message to='mercutio@verona.lit' type='chat'>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
57 <body>A most courteous exposition!</body>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
58 <forwarded xmlns='urn:xmpp:forward:0'>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
59 <delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
60 <message from='juliet@capulet.lit/orchard'
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
61 id='0202197'
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
62 to='romeo@montague.lit'
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
63 type='chat'
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
64 xmlns='jabber:client'>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
65 <body>Yet I should kill thee with much cherishing.</body>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
66 <mood xmlns='http://jabber.org/protocol/mood'>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
67 <amorous/>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
68 </mood>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
69 </message>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
70 </forwarded>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
71 </message>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
72 """
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
73 stamp = datetime.datetime(2010, 7, 10, 23, 8, 25, tzinfo=tzutc())
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
74 d = self.plugin.forward(stanza, JID('mercutio@verona.lit'), stamp,
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
75 body='A most courteous exposition!',
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
76 profile_key=C.PROFILE[0])
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
77 d.addCallback(lambda dummy: self.assertEqualXML(self.host.getSentMessageXml(0), output, True))
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
78 return d