Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve id and thid management #90

Merged
merged 6 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Unit tests: test generic message instead of only forward message
Signed-off-by: Sacha Kozma <[email protected]>
  • Loading branch information
yvgny committed Feb 27, 2023
commit 4ce252bb393a2788f8fd9b54a104e3f7ea08f2a3
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