Mercurial > libervia-backend
annotate tests/unit/test_plugin_xep_0234.py @ 4267:32388d743348
tools (common/data_objects): set attachments `url` from `sources` if missing.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 12 Jun 2024 23:06:10 +0200 |
parents | 0fbe5c605eb6 |
children |
rev | line source |
---|---|
4232
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Libervia: an XMPP client |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2024 Jérôme Poisson (goffi@goffi.org) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from unittest.mock import AsyncMock, MagicMock |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 import pytest |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from pytest_twisted import ensureDeferred as ed |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.words.protocols.jabber import jid |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from libervia.backend.core import exceptions |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from libervia.backend.plugins.plugin_xep_0166 import XEP_0166 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from libervia.backend.plugins.plugin_xep_0234 import XEP_0234 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from libervia.backend.tools import xml_tools |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 @pytest.fixture(autouse=True) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 def no_application_register(monkeypatch): |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 """Do not register the application in XEP-0166""" |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 monkeypatch.setattr(XEP_0166, "register_application", lambda *a, **kw: None) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 class TestXEP0234: |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 @ed |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 async def test_parse_file_element(self, host, client): |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 """``parse_file_element`` updates file_data dictionary correctly.""" |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 xep_0234 = XEP_0234(host) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 file_elt = xml_tools.parse( |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 """ |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 <file xmlns='urn:xmpp:jingle:apps:file-transfer:5'> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 <media-type>text/plain</media-type> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 <name>test.txt</name> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 <date>2015-07-26T21:46:00+01:00</date> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 <size>6144</size> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 </file> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 """ |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 ) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 file_data = {} |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 result = await xep_0234.parse_file_element(client, file_elt, file_data) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 expected = { |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 "mime_type": "text/plain", |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 "modified": 1437943560, |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 "name": "test.txt", |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 "size": 6144, |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 } |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 assert result == expected |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 @ed |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 async def test_parse_file_element_no_file_element(self, host, client): |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 """Raise NotFound exception if no <file> element is provided.""" |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 xep_0234 = XEP_0234(host) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 with pytest.raises(exceptions.DataError): |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 await xep_0234.parse_file_element(client, None) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 @ed |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 async def test_parse_file_element_invalid_file_element(self, host, client): |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 """Raise DataError exception if <file> element is invalid.""" |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 xep_0234 = XEP_0234(host) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 file_elt = xml_tools.parse( |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 """ |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 <file xmlns='invalid_namespace'> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 <name>example.txt</name> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 </file> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 """ |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 ) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 with pytest.raises(exceptions.DataError): |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 await xep_0234.parse_file_element(client, file_elt) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 @ed |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 async def test_file_receiving_request_conf(self, monkeypatch, host, client): |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 """Normal use case call "get_dest_dir".""" |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 async def mock_defer_confirm(*args, **kwargs): |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 """Simulate defer_confirm always confirming.""" |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 return True |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 monkeypatch.setattr(xml_tools, "defer_confirm", mock_defer_confirm) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 xep_0234 = XEP_0234(host) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 monkeypatch.setattr( |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 xep_0234._hash, "parse_hash_elt", MagicMock(return_value=(None, None)) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 ) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 mock_get_dest_dir = AsyncMock() |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 mock_get_dest_dir.return_value = True |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 monkeypatch.setattr(xep_0234._f, "get_dest_dir", mock_get_dest_dir) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 session = { |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 "peer_jid": jid.JID("peer@example.com"), |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 "file_accepted": False, |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 "id": "session_id", |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 } |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 content_data = {"application_data": {}, "transport_data": {"webrtc": False}} |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 content_name = "dummy_content" |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 file_data = {"progress_id": "123"} |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 file_elt = xml_tools.parse( |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 """ |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 <file xmlns='urn:xmpp:jingle:apps:file-transfer:5'> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 <media-type>text/plain</media-type> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 <name>test.txt</name> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 <date>2015-07-26T21:46:00+01:00</date> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 <size>6144</size> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 </file> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 """ |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 ) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 confirmed = await xep_0234._file_receiving_request_conf( |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 client, session, content_data, content_name, file_data, file_elt |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 ) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 assert confirmed is True |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 assert ( |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 mock_get_dest_dir.called |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 ), '"get_dest_dir" must be called for non WebRTC case.' |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 @ed |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 async def test_file_receiving_request_conf_webrtc(self, monkeypatch, host, client): |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 """WebRTC use case is handled correctly for received confirmation.""" |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 async def mock_defer_confirm(*args, **kwargs): |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 """Simulate defer_confirm always confirming.""" |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 return True |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 monkeypatch.setattr(xml_tools, "defer_confirm", mock_defer_confirm) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 xep_0234 = XEP_0234(host) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 monkeypatch.setattr( |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 xep_0234._hash, "parse_hash_elt", MagicMock(return_value=(None, None)) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 ) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 mock_get_dest_dir = AsyncMock() |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 mock_get_dest_dir.return_value = True |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 monkeypatch.setattr(xep_0234._f, "get_dest_dir", mock_get_dest_dir) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 session = { |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 "peer_jid": jid.JID("peer@example.com"), |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 "file_accepted": False, |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 "id": "session_id", |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 } |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 content_data = {"application_data": {}, "transport_data": {"webrtc": True}} |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 content_name = "dummy_content" |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 file_data = {"progress_id": "123"} |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 file_elt = xml_tools.parse( |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 """ |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 <file xmlns='urn:xmpp:jingle:apps:file-transfer:5'> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 <media-type>text/plain</media-type> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 <name>test.txt</name> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 <date>2015-07-26T21:46:00+01:00</date> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 <size>6144</size> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 </file> |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 """ |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 ) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 confirmed = await xep_0234._file_receiving_request_conf( |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 client, session, content_data, content_name, file_data, file_elt |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 ) |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 assert confirmed is True |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 # The file is handled by frontend in WebRTC case, so "get_dest_dir" must not be |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 # called. |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 assert ( |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 not mock_get_dest_dir.called |
0fbe5c605eb6
tests (unit/webrtc,XEP-0176, XEP-0234): Fix tests and add webrtc file transfer tests:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 ), '"get_dest_dir" must not be called for WebRTC case.' |