def test_repository_first_raise_error_if_entity_not_found( self, repo: Repository, entity: Entity, ) -> None: """ Given: an empty repository. When: trying to get the first entity. Then: An EntityNotFoundError error is raised. """ with pytest.raises( EntityNotFoundError, match=( f"There are no entities of type {entity.model_name} in the repository" ), ): repo.first(type(entity))
def test_repository_first_returns_first_entity( self, repo: Repository, inserted_entities: List[Entity], ) -> None: """ Given: A repository with many entities. When: using the first method. Then: The smallest entity is returned and saved into the cache """ smaller_entity = min(inserted_entities) result = repo.first(type(smaller_entity)) assert result == smaller_entity assert repo.cache.get(smaller_entity) == smaller_entity