async def test_should_raise_not_found_error_when_already_raised_before( repository, mocker): fake_entity = 'fake' fields = ['id', 'integer', 'inner_entities'] expected_query = HashQuery(repository, memory=True, id=fake_entity, fields=fields) repository.memory_data_source.hmget = asynctest.CoroutineMock( side_effect=[[None]]) repository.memory_data_source.exists = asynctest.CoroutineMock( side_effect=[True]) repository.memory_data_source.hmset = asynctest.CoroutineMock() with pytest.raises(EntityNotFoundError) as exc_info: await repository.query('fake', fields=fields).entity assert exc_info.value.args == (expected_query, ) assert repository.memory_data_source.hmget.call_args_list == [ mocker.call('fake:fake', *fields), ] assert repository.memory_data_source.exists.call_args_list == [ mocker.call('fake:not-found:fake') ] assert not repository.memory_data_source.hmset.called
async def test_should_raise_not_found_error(repository, fake_entity, mocker): fake_query = HashQuery(repository, memory=True, id=fake_entity.id) with pytest.raises(EntityNotFoundError) as exc_info: await repository.query(fake_entity.id).entity assert exc_info.value.args == (fake_query, )
async def test_should_set_already_not_found_error(repository, mocker): fake_entity = 'fake' expected_query = HashQuery(repository, memory=True, id=fake_entity) repository.memory_data_source.hgetall = asynctest.CoroutineMock( side_effect=[None]) repository.memory_data_source.exists = asynctest.CoroutineMock( side_effect=[False]) repository.fallback_data_source.get = asynctest.CoroutineMock( return_value=None) repository.memory_data_source.set = asynctest.CoroutineMock() repository.memory_data_source.hmset = asynctest.CoroutineMock() with pytest.raises(EntityNotFoundError) as exc_info: await repository.query(fake_entity).entity assert exc_info.value.args == (expected_query, ) assert repository.memory_data_source.hgetall.call_args_list == [ mocker.call('fake:fake'), ] assert repository.memory_data_source.exists.call_args_list == [ mocker.call('fake:not-found:fake') ] assert repository.fallback_data_source.get.call_args_list == [ mocker.call('fake:fake') ] assert repository.memory_data_source.set.call_args_list == [ mocker.call('fake:not-found:fake', '1') ] assert not repository.memory_data_source.hmset.called