Skip to content

Commit

Permalink
Unit tests: test generic message instead of only forward message
Browse files Browse the repository at this point in the history
Signed-off-by: Sacha Kozma <[email protected]>
  • Loading branch information
yvgny committed Feb 27, 2023
1 parent 58ccc39 commit 4ce252b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
Empty file added tests/unit/didcomm/__init__.py
Empty file.
26 changes: 26 additions & 0 deletions tests/unit/didcomm/message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest
import attr

from didcomm.core import converters
from didcomm.message import GenericMessage


@pytest.mark.parametrize(
"m_id, m_id_expected",
[
pytest.param("123", "123", id="str"),
pytest.param(lambda: "345", "345", id="function"),
pytest.param(None, None, id="default"),
],
)
def test_forward_message__id_good(m_id, m_id_expected, mocker):
if m_id is None:
# XXX mocks in-place of imports doesn't work for attrs calsses
# by some reason
spy = mocker.spy(converters, "didcomm_id_generator_default")
msg = GenericMessage(type="test_type", body="test_body")
assert spy.call_count == 1
assert msg.id == spy.spy_return
else:
msg = GenericMessage(type="test_type", body="test_body")
assert attr.evolve(msg, **dict(id=m_id)).id == m_id_expected
21 changes: 0 additions & 21 deletions tests/unit/didcomm/protocols/routing/test_forward_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Callable

from didcomm.errors import DIDCommValueError, MalformedMessageError
from didcomm.core import converters
from didcomm.core.types import DIDCOMM_ORG_DOMAIN, DIDCommFields
from didcomm.message import Attachment, AttachmentDataJson, AttachmentDataLinks
from didcomm.protocols.routing.forward import (
Expand Down Expand Up @@ -33,26 +32,6 @@ def test_forward_message__id_bad(m_id, fwd_msg):
attr.evolve(fwd_msg, **dict(id=m_id))


@pytest.mark.parametrize(
"m_id, m_id_expected",
[
pytest.param("123", "123", id="str"),
pytest.param(lambda: "345", "345", id="function"),
pytest.param(None, None, id="default"),
],
)
def test_forward_message__id_good(m_id, m_id_expected, mocker, fwd_msg):
if m_id is None:
# XXX mocks in-place of imports doesn't work for attrs calsses
# by some reason
spy = mocker.spy(converters, "didcomm_id_generator_default")
msg = gen_fwd_msg()
assert spy.call_count == 1
assert msg.id == spy.spy_return
else:
assert attr.evolve(fwd_msg, **dict(id=m_id)).id == m_id_expected


def _build_mturi(
scheme="https",
domain=DIDCOMM_ORG_DOMAIN,
Expand Down

0 comments on commit 4ce252b

Please sign in to comment.