apply black to the whole codebase.
This commit is contained in:
parent
420df3340d
commit
82e2c6efac
1 changed files with 175 additions and 448 deletions
|
|
@ -35,7 +35,6 @@ from libervia.backend.plugins.plugin_xep_0420 import (
|
|||
from libervia.backend.tools.xml_tools import ElementParser
|
||||
from twisted.words.xish import domish
|
||||
|
||||
|
||||
__all__ = [ # pylint: disable=unused-variable
|
||||
"test_unpack_matches_original",
|
||||
"test_affixes_included",
|
||||
|
|
@ -150,13 +149,11 @@ def test_affixes_included() -> None: # pylint: disable=missing-function-docstri
|
|||
custom_policies={custom_affix: SCEAffixPolicy.OPTIONAL},
|
||||
)
|
||||
|
||||
stanza = string_to_domish(
|
||||
"""<message from="foo@example.com" to="bar@example.com">
|
||||
stanza = string_to_domish("""<message from="foo@example.com" to="bar@example.com">
|
||||
<body>
|
||||
Make sure that both the REQUIRED and the OPTIONAL affixes are included.
|
||||
</body>
|
||||
</message>"""
|
||||
)
|
||||
</message>""")
|
||||
|
||||
affix_values = XEP_0420.unpack_stanza(
|
||||
profile, stanza, XEP_0420.pack_stanza(profile, stanza)
|
||||
|
|
@ -186,13 +183,11 @@ def test_all_affixes_verified() -> None: # pylint: disable=missing-function-doc
|
|||
custom_policies={},
|
||||
)
|
||||
|
||||
stanza = string_to_domish(
|
||||
"""<message from="foo@example.com" to="bar@example.com">
|
||||
stanza = string_to_domish("""<message from="foo@example.com" to="bar@example.com">
|
||||
<body>
|
||||
When unpacking, all affixes are loaded, even those marked as NOT_NEEDED.
|
||||
</body>
|
||||
</message>"""
|
||||
)
|
||||
</message>""")
|
||||
|
||||
envelope_serialized = XEP_0420.pack_stanza(packing_profile, stanza)
|
||||
|
||||
|
|
@ -229,11 +224,9 @@ def test_incomplete_affixes() -> None: # pylint: disable=missing-function-docst
|
|||
custom_policies={},
|
||||
)
|
||||
|
||||
stanza = string_to_domish(
|
||||
"""<message from="foo@example.com" to="bar@example.com">
|
||||
stanza = string_to_domish("""<message from="foo@example.com" to="bar@example.com">
|
||||
<body>Check that all affixes REQUIRED by the profile are present.</body>
|
||||
</message>"""
|
||||
)
|
||||
</message>""")
|
||||
|
||||
with pytest.raises(ProfileRequirementsNotMet):
|
||||
XEP_0420.unpack_stanza(
|
||||
|
|
@ -259,14 +252,12 @@ def test_incomplete_affixes() -> None: # pylint: disable=missing-function-docst
|
|||
custom_policies={custom_affix: SCEAffixPolicy.REQUIRED},
|
||||
)
|
||||
|
||||
stanza = string_to_domish(
|
||||
"""<message from="foo@example.com" to="bar@example.com">
|
||||
stanza = string_to_domish("""<message from="foo@example.com" to="bar@example.com">
|
||||
<body>
|
||||
Check that all affixes REQUIRED by the profile are present, including custom
|
||||
affixes.
|
||||
</body>
|
||||
</message>"""
|
||||
)
|
||||
</message>""")
|
||||
|
||||
with pytest.raises(ProfileRequirementsNotMet):
|
||||
XEP_0420.unpack_stanza(
|
||||
|
|
@ -284,11 +275,9 @@ def test_rpad_affix() -> None: # pylint: disable=missing-function-docstring
|
|||
)
|
||||
|
||||
for _ in range(100):
|
||||
stanza = string_to_domish(
|
||||
"""<message from="foo@example.com" to="bar@example.com">
|
||||
stanza = string_to_domish("""<message from="foo@example.com" to="bar@example.com">
|
||||
<body>OK</body>
|
||||
</message>"""
|
||||
)
|
||||
</message>""")
|
||||
|
||||
affix_values = XEP_0420.unpack_stanza(
|
||||
profile, stanza, XEP_0420.pack_stanza(profile, stanza)
|
||||
|
|
@ -321,9 +310,7 @@ def test_time_affix() -> None: # pylint: disable=missing-function-docstring
|
|||
</body>
|
||||
</content>
|
||||
<time stamp="1969-07-21T02:56:15Z"/>
|
||||
</envelope>""".encode(
|
||||
"utf-8"
|
||||
)
|
||||
</envelope>""".encode("utf-8")
|
||||
|
||||
affix_values = XEP_0420.unpack_stanza(profile, stanza, envelope_serialized)
|
||||
assert affix_values.timestamp == datetime(1969, 7, 21, 2, 56, 15, tzinfo=timezone.utc)
|
||||
|
|
@ -338,11 +325,9 @@ def test_to_affix() -> None: # pylint: disable=missing-function-docstring
|
|||
custom_policies={},
|
||||
)
|
||||
|
||||
stanza = string_to_domish(
|
||||
"""<message from="foo@example.com" to="bar@example.com">
|
||||
stanza = string_to_domish("""<message from="foo@example.com" to="bar@example.com">
|
||||
<body>Check that the ``to`` affix is correctly added.</body>
|
||||
</message>"""
|
||||
)
|
||||
</message>""")
|
||||
|
||||
envelope_serialized = XEP_0420.pack_stanza(profile, stanza)
|
||||
affix_values = XEP_0420.unpack_stanza(profile, stanza, envelope_serialized)
|
||||
|
|
@ -366,13 +351,11 @@ def test_to_affix() -> None: # pylint: disable=missing-function-docstring
|
|||
assert affix_values.recipient is not None
|
||||
assert affix_values.recipient.userhost() == "bar@example.com"
|
||||
|
||||
stanza = string_to_domish(
|
||||
"""<message from="foo@example.com">
|
||||
stanza = string_to_domish("""<message from="foo@example.com">
|
||||
<body>
|
||||
Check that a missing "to" attribute on the stanza fails stanza packing.
|
||||
</body>
|
||||
</message>"""
|
||||
)
|
||||
</message>""")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
XEP_0420.pack_stanza(profile, stanza)
|
||||
|
|
@ -387,11 +370,9 @@ def test_from_affix() -> None: # pylint: disable=missing-function-docstring
|
|||
custom_policies={},
|
||||
)
|
||||
|
||||
stanza = string_to_domish(
|
||||
"""<message from="foo@example.com" to="bar@example.com">
|
||||
stanza = string_to_domish("""<message from="foo@example.com" to="bar@example.com">
|
||||
<body>Check that the ``from`` affix is correctly added.</body>
|
||||
</message>"""
|
||||
)
|
||||
</message>""")
|
||||
|
||||
envelope_serialized = XEP_0420.pack_stanza(profile, stanza)
|
||||
affix_values = XEP_0420.unpack_stanza(profile, stanza, envelope_serialized)
|
||||
|
|
@ -415,13 +396,11 @@ def test_from_affix() -> None: # pylint: disable=missing-function-docstring
|
|||
assert affix_values.sender is not None
|
||||
assert affix_values.sender.userhost() == "foo@example.com"
|
||||
|
||||
stanza = string_to_domish(
|
||||
"""<message to="bar@example.com">
|
||||
stanza = string_to_domish("""<message to="bar@example.com">
|
||||
<body>
|
||||
Check that a missing "from" attribute on the stanza fails stanza packing.
|
||||
</body>
|
||||
</message>"""
|
||||
)
|
||||
</message>""")
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
XEP_0420.pack_stanza(profile, stanza)
|
||||
|
|
@ -446,14 +425,12 @@ def test_custom_affixes() -> None: # pylint: disable=missing-function-docstring
|
|||
custom_policies={},
|
||||
)
|
||||
|
||||
stanza = string_to_domish(
|
||||
"""<message from="foo@example.com" to="bar@example.com">
|
||||
stanza = string_to_domish("""<message from="foo@example.com" to="bar@example.com">
|
||||
<body>
|
||||
If a custom affix is included in the envelope, but not excpected by the
|
||||
recipient, the schema validation should fail.
|
||||
</body>
|
||||
</message>"""
|
||||
)
|
||||
</message>""")
|
||||
|
||||
with pytest.raises(exceptions.ParsingError):
|
||||
XEP_0420.unpack_stanza(
|
||||
|
|
@ -462,12 +439,10 @@ def test_custom_affixes() -> None: # pylint: disable=missing-function-docstring
|
|||
|
||||
profile = packing_profile
|
||||
|
||||
stanza = string_to_domish(
|
||||
"""<message from="foo@example.com/device0"
|
||||
stanza = string_to_domish("""<message from="foo@example.com/device0"
|
||||
to="bar@example.com/Libervia.123">
|
||||
<body>The affix element should be returned as part of the affix values.</body>
|
||||
</message>"""
|
||||
)
|
||||
</message>""")
|
||||
|
||||
affix_values = XEP_0420.unpack_stanza(
|
||||
profile, stanza, XEP_0420.pack_stanza(profile, stanza)
|
||||
|
|
@ -526,12 +501,10 @@ def test_non_encryptable_elements() -> None: # pylint: disable=missing-function
|
|||
custom_policies={},
|
||||
)
|
||||
|
||||
stanza = string_to_domish(
|
||||
"""<message from="foo@example.com" to="bar@example.com">
|
||||
stanza = string_to_domish("""<message from="foo@example.com" to="bar@example.com">
|
||||
<body>This stanza includes a store hint which must not be encrypted.</body>
|
||||
<store xmlns="urn:xmpp:hints"/>
|
||||
</message>"""
|
||||
)
|
||||
</message>""")
|
||||
|
||||
envelope_serialized = XEP_0420.pack_stanza(profile, stanza)
|
||||
envelope = string_to_domish(envelope_serialized.decode("utf-8"))
|
||||
|
|
@ -552,9 +525,7 @@ def test_non_encryptable_elements() -> None: # pylint: disable=missing-function
|
|||
</body>
|
||||
<store xmlns="urn:xmpp:hints"/>
|
||||
</content>
|
||||
</envelope>""".encode(
|
||||
"utf-8"
|
||||
)
|
||||
</envelope>""".encode("utf-8")
|
||||
|
||||
XEP_0420.unpack_stanza(profile, stanza, envelope_serialized)
|
||||
|
||||
|
|
@ -582,9 +553,7 @@ def test_schema_validation() -> None: # pylint: disable=missing-function-docstr
|
|||
<store xmlns="urn:xmpp:hints"/>
|
||||
</content>
|
||||
<unknown-affix unknown-attr="unknown"/>
|
||||
</envelope>""".encode(
|
||||
"utf-8"
|
||||
)
|
||||
</envelope>""".encode("utf-8")
|
||||
|
||||
with pytest.raises(exceptions.ParsingError):
|
||||
XEP_0420.unpack_stanza(profile, stanza, envelope_serialized)
|
||||
|
|
|
|||
Loading…
Reference in a new issue