annotate sat/test/test_plugin_xep_0203.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 003b8b4b56a7
children 9d0df638c8b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1 #!/usr/bin/env python3
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
3
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
4 # SAT: a jabber client
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2624
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)
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
7
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or modify
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
11 # (at your option) any later version.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
12
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful,
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
16 # GNU Affero General Public License for more details.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
17
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
20
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
21 """ Plugin XEP-0203 """
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
22
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
23 from sat.test import helpers
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
24 from sat.plugins.plugin_xep_0203 import XEP_0203
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
25 from twisted.words.xish import domish
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
26 from twisted.words.protocols.jabber.jid import JID
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from dateutil.tz import tzutc
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
28 import datetime
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
29
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
30 NS_PUBSUB = "http://jabber.org/protocol/pubsub"
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
31
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
32
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
33 class XEP_0203Test(helpers.SatTestCase):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
34 def setUp(self):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
35 self.host = helpers.FakeSAT()
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
36 self.plugin = XEP_0203(self.host)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
37
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
38 def test_delay(self):
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
39 delay_xml = """
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
40 <delay xmlns='urn:xmpp:delay'
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
41 from='capulet.com'
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
42 stamp='2002-09-10T23:08:25Z'>
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
43 Offline Storage
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
44 </delay>
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
45 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
46 message_xml = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
47 """
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
48 <message
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
49 from='romeo@montague.net/orchard'
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
50 to='juliet@capulet.com'
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
51 type='chat'>
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
52 <body>text</body>
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
53 %s
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
54 </message>
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 """
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 % delay_xml
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 )
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
58
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 parent = domish.Element((None, "message"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 parent["from"] = "romeo@montague.net/orchard"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 parent["to"] = "juliet@capulet.com"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 parent["type"] = "chat"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 parent.addElement("body", None, "text")
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
64 stamp = datetime.datetime(2002, 9, 10, 23, 8, 25, tzinfo=tzutc())
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 elt = self.plugin.delay(stamp, JID("capulet.com"), "Offline Storage", parent)
1273
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
66 self.assertEqualXML(elt.toXml(), delay_xml, True)
f7977b2b727e plugin XEP-0203: first draft
souliane <souliane@mailoo.org>
parents:
diff changeset
67 self.assertEqualXML(parent.toXml(), message_xml, True)