-
Notifications
You must be signed in to change notification settings - Fork 64
Closed
Labels
Description
💡 Feature description
The EntityId
class does check not check equality based on key
and name
but on class instance. This causes poor user experience for unit tests as asserting calls on the unittest Mock
class will fail.
Imagine the following orchestrator code:
@blueprint.orchestration_trigger(context_name="context")
def orchestration(context: DurableOrchestrationContext) -> Generator[dict[str, Any], Any, Any]:
return _orchestration(context)
def _orchestration(context: DurableOrchestrationContext) -> Generator[dict[str, Any], Any, Any]:
# do something
yield context.call_entity(
EntityId('example', '123'),
"set",
{"key": "value"},
)
# do something
And the following unit test:
def test_signal_entity(mocker: pytest_mock.MockFixture) -> None:
# Given
call_entity_mock = Mock()
context_mock = Mock()
context_mock.call_entity = call_entity_mock
orchestration = _orchestration(context_mock)
# When
next(orchestration)
# Then
call_entity_mock.assert_called_with(
EntityId('example', '123'),
"set",
{"key": "value"},
)
Changing the EntityId
class to check equality based on key
and name
will make the unit test pass and provide a better user experience.
💭 Describe alternatives you've considered
We considered just using asserting the call (i.e., called x times) and then individually asserting the call args by explicitly checking the key. However, this still prevents using the assert_called_with
api.
Additional context
Addressed by #520
davidmrdavid