We are unit testing an Orchestrator in Azure durable function in Python where we want to assert that records created by context.call_activity("GetRecords", reader_activity_input)
are passed to context.call_activity("ProcessRecords", records
) in the following function but in-spite of mocking a return_value in the test ,it returns a None instead of the value setup by mocked_context.call_activity.return_value = iter(records)
Function:
def orchestrator_function(context: df.DurableOrchestrationContext):
.....
records = yield context.call_activity("GetRecords", reader_activity_input)
response = yield context.call_activity("ProcessRecords", records)
return response
Test:
def test_Orchestrator_function_calls_Process(mocker):
mocked_context = mocker.MagicMock()
records = [1,2,3]
mocked_context.call_activity.return_value = iter(records)
list(generator)
mocked_context.call_activity.assert_has_calls([mocker.call("ProcessRecords", records)])
The above assert fails because value of records
is None