Mercurial > libervia-backend
diff tests/unit/test_plugin_xep_0420.py @ 3911:8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
- support for both (modern) OMEMO under the `urn:xmpp:omemo:2` namespace and (legacy) OMEMO under the `eu.siacs.conversations.axolotl` namespace
- maintains one identity across both versions of OMEMO
- migrates data from the old plugin
- includes more features for protocol stability
- uses SCE for modern OMEMO
- fully type-checked, linted and format-checked
- added type hints to various pieces of backend code used by the plugin
- added stubs for some Twisted APIs used by the plugin under stubs/ (use `export MYPYPATH=stubs/` before running mypy)
- core (xmpp): enabled `send` trigger and made it an asyncPoint
fix 375
author | Syndace <me@syndace.dev> |
---|---|
date | Tue, 23 Aug 2022 21:06:24 +0200 |
parents | 00212260f659 |
children | cecf45416403 |
line wrap: on
line diff
--- a/tests/unit/test_plugin_xep_0420.py Thu Sep 22 12:03:12 2022 +0200 +++ b/tests/unit/test_plugin_xep_0420.py Tue Aug 23 21:06:24 2022 +0200 @@ -16,11 +16,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -# Type-check with `mypy --strict --disable-error-code no-untyped-call` -# Lint with `pylint` - from datetime import datetime, timezone -from typing import Callable, Iterator, Optional, cast +from typing import Callable, cast import pytest @@ -77,8 +74,8 @@ </xs:element>""" def create(self, stanza: domish.Element) -> domish.Element: - recipient = cast(Optional[str], stanza.getAttribute("to", None)) - sender = cast(Optional[str], stanza.getAttribute("from", None)) + recipient = stanza.getAttribute("to", None) + sender = stanza.getAttribute("from", None) if recipient is None or sender is None: raise ValueError( @@ -487,21 +484,15 @@ envelope_serialized = XEP_0420.pack_stanza(profile, stanza) envelope = string_to_domish(envelope_serialized.decode("utf-8")) - content = next(cast(Iterator[domish.Element], envelope.elements(NS_SCE, "content"))) + content = next(envelope.elements(NS_SCE, "content")) # The body should have been assigned ``jabber:client`` as its namespace - assert next( - cast(Iterator[domish.Element], content.elements("jabber:client", "body")), - None - ) is not None + assert next(content.elements("jabber:client", "body"), None) is not None XEP_0420.unpack_stanza(profile, stanza, envelope_serialized) # The body should still have ``jabber:client`` after unpacking - assert next( - cast(Iterator[domish.Element], stanza.elements("jabber:client", "body")), - None - ) is not None + assert next(stanza.elements("jabber:client", "body"), None) is not None def test_non_encryptable_elements() -> None: # pylint: disable=missing-function-docstring @@ -520,18 +511,11 @@ envelope_serialized = XEP_0420.pack_stanza(profile, stanza) envelope = string_to_domish(envelope_serialized.decode("utf-8")) - content = next(cast(Iterator[domish.Element], envelope.elements(NS_SCE, "content"))) + content = next(envelope.elements(NS_SCE, "content")) # The store hint must not have been moved to the content element - assert next( - cast(Iterator[domish.Element], stanza.elements(NS_HINTS, "store")), - None - ) is not None - - assert next( - cast(Iterator[domish.Element], content.elements(NS_HINTS, "store")), - None - ) is None + assert next(stanza.elements(NS_HINTS, "store"), None) is not None + assert next(content.elements(NS_HINTS, "store"), None) is None stanza = string_to_domish( """<message from="foo@example.com" to="bar@example.com"></message>""" @@ -548,10 +532,7 @@ XEP_0420.unpack_stanza(profile, stanza, envelope_serialized) - assert next( - cast(Iterator[domish.Element], stanza.elements(NS_HINTS, "store")), - None - ) is None + assert next(stanza.elements(NS_HINTS, "store"), None) is None def test_schema_validation() -> None: # pylint: disable=missing-function-docstring