Mercurial > libervia-backend
annotate libervia/backend/test/helpers.py @ 4335:430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
rel 453
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 03 Dec 2024 00:13:07 +0100 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
335 | 3 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
4 # SAT: a jabber client |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
335 | 6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
10 # (at your option) any later version. |
335 | 11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
15 # GNU Affero General Public License for more details. |
335 | 16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
591
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
335 | 19 |
998
f5761534e0f3
tests: fixed log init in helpers (log init must be done before any call to a log method)
Goffi <goffi@goffi.org>
parents:
997
diff
changeset
|
20 |
f5761534e0f3
tests: fixed log init in helpers (log init must be done before any call to a log method)
Goffi <goffi@goffi.org>
parents:
997
diff
changeset
|
21 ## logging configuration for tests ## |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
22 from libervia.backend.core import log_config |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
23 |
4078
15055a00162c
refactoring: rename `sat_configure` to `libervia_configure`
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
24 log_config.libervia_configure() |
998
f5761534e0f3
tests: fixed log init in helpers (log init must be done before any call to a log method)
Goffi <goffi@goffi.org>
parents:
997
diff
changeset
|
25 |
1909
0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
26 import logging |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
27 from libervia.backend.core.log import getLogger |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
28 |
1909
0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
29 getLogger().setLevel(logging.WARNING) # put this to DEBUG when needed |
0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
30 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
31 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
32 from libervia.backend.tools import config as tools_config |
3028 | 33 from .constants import Const as C |
649 | 34 from wokkel.xmppim import RosterItem |
1277
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
35 from wokkel.generic import parseXml |
4107
bc7d45dedeb0
backend: rename `SatRosterProtocol` to `LiberviaRosterProtocol`
Goffi <goffi@goffi.org>
parents:
4078
diff
changeset
|
36 from libervia.backend.core.xmpp import LiberviaRosterProtocol |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
37 from libervia.backend.memory.memory import Params, Memory |
647
63b6e684bbfa
tests: Use of FailTest for DifferentArgsException instead of Exception, so the test fail instead of raising en error.
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
38 from twisted.trial.unittest import FailTest |
693
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
39 from twisted.trial import unittest |
782
0e5807193721
test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
781
diff
changeset
|
40 from twisted.internet import defer |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
782
diff
changeset
|
41 from twisted.words.protocols.jabber.jid import JID |
1277
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
42 from twisted.words.xish import domish |
693
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
43 from xml.etree import cElementTree as etree |
789
0cb423500fbb
test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
44 from collections import Counter |
693
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
45 import re |
335 | 46 |
47 | |
649 | 48 def b2s(value): |
49 """Convert a bool to a unicode string used in bridge | |
50 @param value: boolean value | |
51 @return: unicode conversion, according to bridge convention | |
52 | |
53 """ | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
54 return "True" if value else "False" |
591
65821b3fa7ab
Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
55 |
780
9810f22ba733
test: store the constants in constants.py + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
56 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
57 def mute_logging(): |
1909
0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
58 """Temporarily set the logging level to CRITICAL to not pollute the output with expected errors.""" |
0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
59 logger = getLogger() |
0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
60 logger.original_level = logger.getEffectiveLevel() |
0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
61 logger.setLevel(logging.CRITICAL) |
0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
62 |
0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
63 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
64 def unmute_logging(): |
1909
0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
65 """Restore the logging level after it has been temporarily disabled.""" |
0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
66 logger = getLogger() |
0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
67 logger.setLevel(logger.original_level) |
0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
68 |
0681d69cbe0a
test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents:
1766
diff
changeset
|
69 |
647
63b6e684bbfa
tests: Use of FailTest for DifferentArgsException instead of Exception, so the test fail instead of raising en error.
Goffi <goffi@goffi.org>
parents:
609
diff
changeset
|
70 class DifferentArgsException(FailTest): |
335 | 71 pass |
72 | |
780
9810f22ba733
test: store the constants in constants.py + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
73 |
693
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
74 class DifferentXMLException(FailTest): |
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
75 pass |
591
65821b3fa7ab
Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
76 |
780
9810f22ba733
test: store the constants in constants.py + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
77 |
789
0cb423500fbb
test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
78 class DifferentListException(FailTest): |
0cb423500fbb
test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
79 pass |
0cb423500fbb
test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
80 |
0cb423500fbb
test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
81 |
335 | 82 class FakeSAT(object): |
83 """Class to simulate a SAT instance""" | |
84 | |
85 def __init__(self): | |
86 self.bridge = FakeBridge() | |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
87 self.memory = FakeMemory(self) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
88 self.trigger = FakeTriggerManager() |
1271 | 89 self.profiles = {} |
90 self.reinit() | |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
782
diff
changeset
|
91 |
1271 | 92 def reinit(self): |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
93 """This can be called by tests that check for sent and stored messages, |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
94 uses FakeClient or get/set some other data that need to be cleaned""" |
1271 | 95 for profile in self.profiles: |
96 self.profiles[profile].reinit() | |
97 self.memory.reinit() | |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
782
diff
changeset
|
98 self.stored_messages = [] |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
99 self.plugins = {} |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
100 self.profiles = {} |
335 | 101 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
102 def contact_del(self, to, profile_key): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
103 # TODO |
649 | 104 pass |
105 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
106 def register_callback(self, callback, *args, **kwargs): |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
107 pass |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
108 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
109 def message_send( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
110 self, to_s, msg, subject=None, mess_type="auto", extra={}, profile_key="@NONE@" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
111 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
112 self.send_and_store_message({"to": JID(to_s)}) |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
782
diff
changeset
|
113 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
114 def _send_message_to_stream(self, mess_data, client): |
1206
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
115 """Save the information to check later to whom messages have been sent. |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
116 |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
117 @param mess_data: message data dictionnary |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
118 @param client: profile's client |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
119 """ |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
120 client.xmlstream.send(mess_data["xml"]) |
1206
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
121 return mess_data |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
122 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
123 def _store_message(self, mess_data, client): |
1206
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
124 """Save the information to check later if entries have been added to the history. |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
125 |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
126 @param mess_data: message data dictionnary |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
127 @param client: profile's client |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
128 """ |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
782
diff
changeset
|
129 self.stored_messages.append(mess_data["to"]) |
1206
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
130 return mess_data |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
131 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
132 def send_message_to_bridge(self, mess_data, client): |
1206
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
133 """Simulate the message being sent to the frontends. |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
134 |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
135 @param mess_data: message data dictionnary |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
136 @param client: profile's client |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
137 """ |
020e663bc286
test: fixes FakeSAT for plugin XEP-0033
souliane <souliane@mailoo.org>
parents:
1037
diff
changeset
|
138 return mess_data # TODO |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
139 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
140 def get_profile_name(self, profile_key): |
1284
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
141 """Get the profile name from the profile_key""" |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
142 return profile_key |
41ffe2c2dddc
plugin XEP-0313: update (still draft)
souliane <souliane@mailoo.org>
parents:
1277
diff
changeset
|
143 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
144 def get_client(self, profile_key): |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
145 """Convenient method to get client from profile key |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
146 @return: client or None if it doesn't exist""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
147 profile = self.memory.get_profile_name(profile_key) |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
148 if not profile: |
1624 | 149 raise exceptions.ProfileKeyUnknown |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
150 if profile not in self.profiles: |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
151 self.profiles[profile] = FakeClient(self, profile) |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
152 return self.profiles[profile] |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
153 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
154 def get_jid_n_stream(self, profile_key): |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
155 """Convenient method to get jid and stream from profile key |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
156 @return: tuple (jid, xmlstream) from profile, can be None""" |
1269
91e5becc6623
test: add tests for plugin_misc_groupblog
souliane <souliane@mailoo.org>
parents:
1206
diff
changeset
|
157 return (C.PROFILE_DICT[profile_key], None) |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
158 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
159 def is_connected(self, profile): |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
160 return True |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
161 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
162 def get_sent_messages(self, profile_index): |
1271 | 163 """Return all the sent messages (in the order they have been sent) and |
164 empty the list. Called by tests. FakeClient instances associated to each | |
165 profile must have been previously initialized with the method | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
166 FakeSAT.get_client. |
1271 | 167 |
168 @param profile_index: index of the profile to consider (cf. C.PROFILE) | |
169 @return: the sent messages for given profile, or None""" | |
829
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
170 try: |
1271 | 171 tmp = self.profiles[C.PROFILE[profile_index]].xmlstream.sent |
172 self.profiles[C.PROFILE[profile_index]].xmlstream.sent = [] | |
173 return tmp | |
829
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
174 except IndexError: |
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
175 return None |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
176 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
177 def get_sent_message(self, profile_index): |
829
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
178 """Pop and return the sent message in first position (works like a FIFO). |
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
179 Called by tests. FakeClient instances associated to each profile must have |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
180 been previously initialized with the method FakeSAT.get_client. |
1271 | 181 |
182 @param profile_index: index of the profile to consider (cf. C.PROFILE) | |
183 @return: the sent message for given profile, or None""" | |
184 try: | |
185 return self.profiles[C.PROFILE[profile_index]].xmlstream.sent.pop(0) | |
186 except IndexError: | |
187 return None | |
188 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
189 def get_sent_message_xml(self, profile_index): |
1271 | 190 """Pop and return the sent message in first position (works like a FIFO). |
191 Called by tests. FakeClient instances associated to each profile must have | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
192 been previously initialized with the method FakeSAT.get_client. |
829
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
193 @return: XML representation of the sent message for given profile, or None""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
194 entry = self.get_sent_message(profile_index) |
829
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
195 return entry.toXml() if entry else None |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
782
diff
changeset
|
196 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
197 def find_features_set( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
198 self, features, identity=None, jid_=None, profile=C.PROF_KEY_NONE |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
199 ): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
200 """Call self.add_feature from your tests to change the return value. |
999
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
201 |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
202 @return: a set of entities |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
203 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
204 client = self.get_client(profile) |
999
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
205 if jid_ is None: |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
206 jid_ = JID(client.jid.host) |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
207 try: |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
208 if set(features).issubset(client.features[jid_]): |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
209 return defer.succeed(set([jid_])) |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
210 except (TypeError, AttributeError, KeyError): |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
211 pass |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
212 return defer.succeed(set()) |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
213 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
214 def add_feature(self, jid_, feature, profile_key): |
999
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
215 """Add a feature to an entity. |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
216 |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
217 To be called from your tests when needed. |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
218 """ |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
219 client = self.get_client(profile_key) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
220 if not hasattr(client, "features"): |
999
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
221 client.features = {} |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
222 if jid_ not in client.features: |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
223 client.features[jid_] = set() |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
224 client.features[jid_].add(feature) |
c37a24922f27
plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents:
998
diff
changeset
|
225 |
335 | 226 |
227 class FakeBridge(object): | |
228 """Class to simulate and test bridge calls""" | |
229 | |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
230 def __init__(self): |
829
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
231 self.expected_calls = {} |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
232 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
233 def expect_call(self, name, *check_args, **check_kwargs): |
829
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
234 if hasattr(self, name): # queue this new call as one already exists |
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
235 self.expected_calls.setdefault(name, []) |
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
236 self.expected_calls[name].append((check_args, check_kwargs)) |
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
237 return |
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
238 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
239 def check_call(*args, **kwargs): |
335 | 240 if args != check_args or kwargs != check_kwargs: |
3028 | 241 print("\n\n--------------------") |
242 print("Args are not equals:") | |
243 print("args\n----\n%s (sent)\n%s (wanted)" % (args, check_args)) | |
244 print("kwargs\n------\n%s (sent)\n%s (wanted)" % (kwargs, check_kwargs)) | |
245 print("--------------------\n\n") | |
335 | 246 raise DifferentArgsException |
829
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
247 delattr(self, name) |
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
248 |
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
249 if name in self.expected_calls: # register the next call |
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
250 args, kwargs = self.expected_calls[name].pop(0) |
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
251 if len(self.expected_calls[name]) == 0: |
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
252 del self.expected_calls[name] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
253 self.expect_call(name, *args, **kwargs) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
254 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
255 setattr(self, name, check_call) |
335 | 256 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
257 def add_method( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
258 self, name, int_suffix, in_sign, out_sign, method, async_=False, doc=None |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
259 ): |
694
4284b6ad8aa3
tests: plugin text syntaxes sanitisation tests
Goffi <goffi@goffi.org>
parents:
693
diff
changeset
|
260 pass |
335 | 261 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
262 def add_signal(self, name, int_suffix, signature): |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
263 pass |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
264 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
265 def add_test_callback(self, name, method): |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
266 """This can be used to register callbacks for bridge methods AND signals. |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
267 Contrary to expect_call, this will not check if the method or signal is |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
268 called/sent with the correct arguments, it will instead run the callback |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
269 of your choice.""" |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
270 setattr(self, name, method) |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
271 |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
272 |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
273 class FakeParams(Params): |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
274 """Class to simulate and test params object. The methods of Params that could |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
275 not be run (for example those using the storage attribute must be overwritten |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
276 by a naive simulation of what they should do.""" |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
277 |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
278 def __init__(self, host, storage): |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
279 Params.__init__(self, host, storage) |
782
0e5807193721
test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
781
diff
changeset
|
280 self.params = {} # naive simulation of values storage |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
281 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
282 def param_set(self, name, value, category, security_limit=-1, profile_key="@NONE@"): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
283 profile = self.get_profile_name(profile_key) |
782
0e5807193721
test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
781
diff
changeset
|
284 self.params.setdefault(profile, {}) |
0e5807193721
test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
781
diff
changeset
|
285 self.params[profile_key][(category, name)] = value |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
286 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
287 def param_get_a(self, name, category, attr="value", profile_key="@NONE@"): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
288 profile = self.get_profile_name(profile_key) |
782
0e5807193721
test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
781
diff
changeset
|
289 return self.params[profile][(category, name)] |
0e5807193721
test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
781
diff
changeset
|
290 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
291 def get_profile_name(self, profile_key, return_profile_keys=False): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
292 if profile_key == "@DEFAULT@": |
1269
91e5becc6623
test: add tests for plugin_misc_groupblog
souliane <souliane@mailoo.org>
parents:
1206
diff
changeset
|
293 return C.PROFILE[0] |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
294 elif profile_key == "@NONE@": |
782
0e5807193721
test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
781
diff
changeset
|
295 raise exceptions.ProfileNotSetError |
0e5807193721
test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
781
diff
changeset
|
296 else: |
0e5807193721
test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
781
diff
changeset
|
297 return profile_key |
0e5807193721
test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
781
diff
changeset
|
298 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
299 def load_ind_params(self, profile, cache=None): |
782
0e5807193721
test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
781
diff
changeset
|
300 self.params[profile] = {} |
0e5807193721
test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
781
diff
changeset
|
301 return defer.succeed(None) |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
302 |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
303 |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
782
diff
changeset
|
304 class FakeMemory(Memory): |
335 | 305 """Class to simulate and test memory object""" |
306 | |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
307 def __init__(self, host): |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
782
diff
changeset
|
308 # do not call Memory.__init__, we just want to call the methods that are |
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
782
diff
changeset
|
309 # manipulating basic stuff, the others should be overwritten when needed |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
310 self.host = host |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
311 self.params = FakeParams(host, None) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
312 self.config = tools_config.parse_main_conf() |
1271 | 313 self.reinit() |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
314 |
1271 | 315 def reinit(self): |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
782
diff
changeset
|
316 """Tests that manipulate params, entities, features should |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
317 re-initialise the memory first to not fake the result.""" |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
318 self.params.load_default_params() |
782
0e5807193721
test: added some tests for Memory
souliane <souliane@mailoo.org>
parents:
781
diff
changeset
|
319 self.params.params.clear() |
833
9bac2fc74968
memory: bug fix to not register twice frontends parameters + added some tests for param update
souliane <souliane@mailoo.org>
parents:
829
diff
changeset
|
320 self.params.frontends_cache = [] |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
782
diff
changeset
|
321 self.entities_data = {} |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
322 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
323 def get_profile_name(self, profile_key, return_profile_keys=False): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
324 return self.params.get_profile_name(profile_key, return_profile_keys) |
335 | 325 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
326 def add_to_history( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
327 self, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
328 from_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
329 to_jid, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
330 message, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
331 _type="chat", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
332 extra=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
333 timestamp=None, |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
334 profile="@NONE@", |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
335 ): |
335 | 336 pass |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
337 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
338 def contact_add(self, contact_jid, attributes, groups, profile_key="@DEFAULT@"): |
335 | 339 pass |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
340 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
341 def set_presence_status( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
342 self, contact_jid, show, priority, statuses, profile_key="@DEFAULT@" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
343 ): |
335 | 344 pass |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
345 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
346 def add_waiting_sub(self, type_, contact_jid, profile_key): |
335 | 347 pass |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
348 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
349 def del_waiting_sub(self, contact_jid, profile_key): |
335 | 350 pass |
351 | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
352 def update_entity_data( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
353 self, entity_jid, key, value, silent=False, profile_key="@NONE@" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
354 ): |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
355 self.entities_data.setdefault(entity_jid, {}) |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
356 self.entities_data[entity_jid][key] = value |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
357 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
358 def entity_data_get(self, entity_jid, keys, profile_key): |
781
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
359 result = {} |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
360 for key in keys: |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
361 result[key] = self.entities_data[entity_jid][key] |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
362 return result |
80ab2b58e205
test: added support of basic memory stuff in helpers.py
souliane <souliane@mailoo.org>
parents:
780
diff
changeset
|
363 |
591
65821b3fa7ab
Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
364 |
335 | 365 class FakeTriggerManager(object): |
366 | |
786
c3acc1298a2f
test: FakeMemory inherits from Memory + more helpers basic support + cleaning
souliane <souliane@mailoo.org>
parents:
782
diff
changeset
|
367 def add(self, point_name, callback, priority=0): |
335 | 368 pass |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
369 |
335 | 370 def point(self, point_name, *args, **kwargs): |
371 """We always return true to continue the action""" | |
372 return True | |
373 | |
780
9810f22ba733
test: store the constants in constants.py + better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
771
diff
changeset
|
374 |
4107
bc7d45dedeb0
backend: rename `SatRosterProtocol` to `LiberviaRosterProtocol`
Goffi <goffi@goffi.org>
parents:
4078
diff
changeset
|
375 class FakeRosterProtocol(LiberviaRosterProtocol): |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
376 """This class is used by FakeClient (one instance per profile)""" |
591
65821b3fa7ab
Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
377 |
649 | 378 def __init__(self, host, parent): |
4107
bc7d45dedeb0
backend: rename `SatRosterProtocol` to `LiberviaRosterProtocol`
Goffi <goffi@goffi.org>
parents:
4078
diff
changeset
|
379 LiberviaRosterProtocol.__init__(self, host) |
649 | 380 self.parent = parent |
1412 | 381 self._jids = {} |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
382 self.add_item(parent.jid.userhostJID()) |
649 | 383 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
384 def add_item(self, jid, *args, **kwargs): |
649 | 385 if not args and not kwargs: |
386 # defaults values setted for the tests only | |
387 kwargs["subscriptionTo"] = True | |
388 kwargs["subscriptionFrom"] = True | |
389 roster_item = RosterItem(jid, *args, **kwargs) | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
390 attrs = { |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
391 "to": b2s(roster_item.subscriptionTo), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
392 "from": b2s(roster_item.subscriptionFrom), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
393 "ask": b2s(roster_item.pendingOut), |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
394 } |
649 | 395 if roster_item.name: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
396 attrs["name"] = roster_item.name |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
397 self.host.bridge.expect_call( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
398 "contact_new", jid.full(), attrs, roster_item.groups, self.parent.profile |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
399 ) |
1412 | 400 self._jids[jid] = roster_item |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
401 self._register_item(roster_item) |
649 | 402 |
403 | |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
404 class FakeXmlStream(object): |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
405 """This class is used by FakeClient (one instance per profile)""" |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
406 |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
407 def __init__(self): |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
408 self.sent = [] |
649 | 409 |
410 def send(self, obj): | |
1277
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
411 """Save the sent messages to compare them later. |
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
412 |
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
413 @param obj (domish.Element, str or unicode): message to send |
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
414 """ |
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
415 if not isinstance(obj, domish.Element): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
416 assert isinstance(obj, str) or isinstance(obj, str) |
1277
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
417 obj = parseXml(obj) |
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
418 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
419 if obj.name == "iq": |
1277
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
420 # IQ request expects an answer, return the request itself so |
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
421 # you can check if it has been well built by your plugin. |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
422 self.iqDeferreds[obj["id"]].callback(obj) |
1277
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
423 |
829
187d2443c82d
test: improvements for the helpers classes:
souliane <souliane@mailoo.org>
parents:
811
diff
changeset
|
424 self.sent.append(obj) |
849
c5a8f602662b
plugin room_game, radiocol: RoomGame.send returns a Deferred.
souliane <souliane@mailoo.org>
parents:
833
diff
changeset
|
425 return defer.succeed(None) |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
426 |
1277
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
427 def addObserver(self, *argv): |
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
428 pass |
3a3e3014f9f8
plugin XEP-0313: first draft:
souliane <souliane@mailoo.org>
parents:
1271
diff
changeset
|
429 |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
430 |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
431 class FakeClient(object): |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
432 """Tests involving more than one profile need one instance of this class per profile""" |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
433 |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
434 def __init__(self, host, profile=None): |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
435 self.host = host |
1269
91e5becc6623
test: add tests for plugin_misc_groupblog
souliane <souliane@mailoo.org>
parents:
1206
diff
changeset
|
436 self.profile = profile if profile else C.PROFILE[0] |
91e5becc6623
test: add tests for plugin_misc_groupblog
souliane <souliane@mailoo.org>
parents:
1206
diff
changeset
|
437 self.jid = C.PROFILE_DICT[self.profile] |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
438 self.roster = FakeRosterProtocol(host, self) |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
439 self.xmlstream = FakeXmlStream() |
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
440 |
1271 | 441 def reinit(self): |
442 self.xmlstream = FakeXmlStream() | |
443 | |
794
52c4b755aba6
test: make FakeClient profile dependent and add some tools to test MUC
souliane <souliane@mailoo.org>
parents:
792
diff
changeset
|
444 def send(self, obj): |
849
c5a8f602662b
plugin room_game, radiocol: RoomGame.send returns a Deferred.
souliane <souliane@mailoo.org>
parents:
833
diff
changeset
|
445 return self.xmlstream.send(obj) |
335 | 446 |
591
65821b3fa7ab
Fix pep8 support in src/test.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
447 |
693
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
448 class SatTestCase(unittest.TestCase): |
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
449 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
450 def assert_equal_xml(self, xml, expected, ignore_blank=False): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
451 def equal_elt(got_elt, exp_elt): |
696
f1a2831d549d
test: better ignore_blank in helpers's assertEqualXML
Goffi <goffi@goffi.org>
parents:
694
diff
changeset
|
452 if ignore_blank: |
f1a2831d549d
test: better ignore_blank in helpers's assertEqualXML
Goffi <goffi@goffi.org>
parents:
694
diff
changeset
|
453 for elt in got_elt, exp_elt: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
454 for attr in ("text", "tail"): |
696
f1a2831d549d
test: better ignore_blank in helpers's assertEqualXML
Goffi <goffi@goffi.org>
parents:
694
diff
changeset
|
455 value = getattr(elt, attr) |
f1a2831d549d
test: better ignore_blank in helpers's assertEqualXML
Goffi <goffi@goffi.org>
parents:
694
diff
changeset
|
456 try: |
f1a2831d549d
test: better ignore_blank in helpers's assertEqualXML
Goffi <goffi@goffi.org>
parents:
694
diff
changeset
|
457 value = value.strip() or None |
f1a2831d549d
test: better ignore_blank in helpers's assertEqualXML
Goffi <goffi@goffi.org>
parents:
694
diff
changeset
|
458 except AttributeError: |
f1a2831d549d
test: better ignore_blank in helpers's assertEqualXML
Goffi <goffi@goffi.org>
parents:
694
diff
changeset
|
459 value = None |
f1a2831d549d
test: better ignore_blank in helpers's assertEqualXML
Goffi <goffi@goffi.org>
parents:
694
diff
changeset
|
460 setattr(elt, attr, value) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
461 if got_elt.tag != exp_elt.tag: |
3028 | 462 print("XML are not equals (elt %s/%s):" % (got_elt, exp_elt)) |
463 print("tag: got [%s] expected: [%s]" % (got_elt.tag, exp_elt.tag)) | |
693
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
464 return False |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
465 if got_elt.attrib != exp_elt.attrib: |
3028 | 466 print("XML are not equals (elt %s/%s):" % (got_elt, exp_elt)) |
467 print("attribs: got %s expected %s" % (got_elt.attrib, exp_elt.attrib)) | |
693
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
468 return False |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
469 if got_elt.tail != exp_elt.tail or got_elt.text != exp_elt.text: |
3028 | 470 print("XML are not equals (elt %s/%s):" % (got_elt, exp_elt)) |
471 print("text: got [%s] expected: [%s]" % (got_elt.text, exp_elt.text)) | |
472 print("tail: got [%s] expected: [%s]" % (got_elt.tail, exp_elt.tail)) | |
693
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
473 return False |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
474 if len(got_elt) != len(exp_elt): |
3028 | 475 print("XML are not equals (elt %s/%s):" % (got_elt, exp_elt)) |
476 print("children len: got %d expected: %d" % (len(got_elt), len(exp_elt))) | |
693
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
477 return False |
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
478 for idx, child in enumerate(got_elt): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
479 if not equal_elt(child, exp_elt[idx]): |
693
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
480 return False |
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
481 return True |
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
482 |
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
483 def remove_blank(xml): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
484 lines = [ |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
485 line.strip() for line in re.sub(r"[ \t\r\f\v]+", " ", xml).split("\n") |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
486 ] |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
487 return "\n".join([line for line in lines if line]) |
693
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
488 |
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
489 xml_elt = etree.fromstring(remove_blank(xml) if ignore_blank else xml) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
490 expected_elt = etree.fromstring( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
491 remove_blank(expected) if ignore_blank else expected |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
492 ) |
693
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
493 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
494 if not equal_elt(xml_elt, expected_elt): |
3028 | 495 print("---") |
496 print("XML are not equals:") | |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
497 print("got:\n-\n%s\n-\n\n" % etree.tostring(xml_elt, encoding="utf-8")) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
498 print( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
499 "was expecting:\n-\n%s\n-\n\n" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
500 % etree.tostring(expected_elt, encoding="utf-8") |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4107
diff
changeset
|
501 ) |
3028 | 502 print("---") |
693
65b30bc7f1b3
tests: added XML comparaison method to helpers
Goffi <goffi@goffi.org>
parents:
669
diff
changeset
|
503 raise DifferentXMLException |
789
0cb423500fbb
test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
504 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
505 def assert_equal_unsorted_list(self, a, b, msg): |
789
0cb423500fbb
test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
506 counter_a = Counter(a) |
0cb423500fbb
test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
507 counter_b = Counter(b) |
0cb423500fbb
test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
508 if counter_a != counter_b: |
3028 | 509 print("---") |
510 print("Unsorted lists are not equals:") | |
511 print("got : %s" % counter_a) | |
512 print("was expecting: %s" % counter_b) | |
789
0cb423500fbb
test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
513 if msg: |
3028 | 514 print(msg) |
515 print("---") | |
789
0cb423500fbb
test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents:
786
diff
changeset
|
516 raise DifferentListException |