Skip to content

Commit

Permalink
fix tests and mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonavic committed Dec 2, 2024
1 parent 554947a commit f7c34d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions meldingen_core/actions/melding.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ async def __call__(self, pk: int, values: dict[str, Any], token: str) -> T:


class BaseStateTransitionAction(Generic[T, T_co], metaclass=ABCMeta):
"""
This action covers transitions that do not require the melding's token to be verified.
Typically these actions are performed by authenticated users.
"""
_state_machine: BaseMeldingStateMachine[T]
_repository: BaseMeldingRepository[T, T_co]

Expand Down
12 changes: 7 additions & 5 deletions tests/test_actions/test_melding_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,14 @@ async def test_add_attachments_action() -> None:
async def test_add_attachments_action_not_found() -> None:
repository = Mock(BaseMeldingRepository)
repository.retrieve.return_value = None
token_verifier: TokenVerifier[Melding, Melding] = TokenVerifier(repository)

process: MeldingAddAttachmentsAction[Melding, Melding] = MeldingAddAttachmentsAction(
Mock(BaseMeldingStateMachine), repository
Mock(BaseMeldingStateMachine), Mock(BaseMeldingRepository), token_verifier
)

with pytest.raises(NotFoundException):
await process(1)
await process(1, 'token')


@pytest.mark.anyio
Expand Down Expand Up @@ -212,18 +213,19 @@ async def test_submit_location_action() -> None:
melding = await submit_location(1, "token")

assert melding == repo_melding
state_machine.transition.assert_called_once_with(repo_melding, MeldingTransitions.ADD_ATTACHMENTS)
state_machine.transition.assert_called_once_with(repo_melding, MeldingTransitions.SUBMIT_LOCATION)
repository.save.assert_called_once_with(repo_melding)


@pytest.mark.anyio
async def test_submit_location_action_not_found() -> None:
repository = Mock(BaseMeldingRepository)
repository.retrieve.return_value = None
token_verifier: TokenVerifier[Melding, Melding] = TokenVerifier(repository)

process: MeldingSubmitLocationAction[Melding, Melding] = MeldingSubmitLocationAction(
Mock(BaseMeldingStateMachine), repository
Mock(BaseMeldingStateMachine), Mock(BaseMeldingRepository), token_verifier
)

with pytest.raises(NotFoundException):
await process(1)
await process(1, 'token')

0 comments on commit f7c34d3

Please sign in to comment.