annotate sat/test/test_plugin_xep_0297.py @ 2979:f44a95f566d2

core, plugin XEP-0045: fix crashes when changing URIs: When adding missing URIs in message, the "children" property was used instead of elements(). "children" not only return elements, and this was causing crashes. This may fix bug 294 rel 294
author Goffi <goffi@goffi.org>
date Sun, 30 Jun 2019 15:52:30 +0200
parents 003b8b4b56a7
children ab2696e34d29
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
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2765
diff changeset
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
1766
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
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
33 NS_PUBSUB = "http://jabber.org/protocol/pubsub"
1274
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 def setUp(self):
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
38 self.host = helpers.FakeSAT()
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
39 self.plugin = XEP_0297(self.host)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
40 self.host.plugins["XEP-0203"] = XEP_0203(self.host)
1274
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
41
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
42 def test_delay(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
43 stanza = parseXml(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
44 """
1274
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>
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 """.encode(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 "utf-8"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 )
1274
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
58 output = """
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
59 <message to='mercutio@verona.lit' type='chat'>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
60 <body>A most courteous exposition!</body>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
61 <forwarded xmlns='urn:xmpp:forward:0'>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
62 <delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
63 <message from='juliet@capulet.lit/orchard'
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
64 id='0202197'
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
65 to='romeo@montague.lit'
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
66 type='chat'
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
67 xmlns='jabber:client'>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
68 <body>Yet I should kill thee with much cherishing.</body>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
69 <mood xmlns='http://jabber.org/protocol/mood'>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
70 <amorous/>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
71 </mood>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
72 </message>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
73 </forwarded>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
74 </message>
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
75 """
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
76 stamp = datetime.datetime(2010, 7, 10, 23, 8, 25, tzinfo=tzutc())
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 d = self.plugin.forward(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 stanza,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 JID("mercutio@verona.lit"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 stamp,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
81 body="A most courteous exposition!",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 profile_key=C.PROFILE[0],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
83 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
84 d.addCallback(
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
85 lambda __: self.assertEqualXML(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
86 self.host.getSentMessageXml(0), output, True
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
88 )
1274
5b6d5e2d6caa plugin XEP-0297: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
89 return d