Skip to content

Commit

Permalink
Merge pull request #34 from lyz-code/fix/set_typevar_entity_in_abstra…
Browse files Browse the repository at this point in the history
…ct_adapter

fix: use entity typevar for abstract repository definition
  • Loading branch information
lyz-code committed Apr 15, 2021
2 parents 2955df2 + 868cdee commit 4351f54
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/repository_orm/adapters/abstract.py
@@ -1,10 +1,12 @@
"""Define the interface of the repositories."""

import abc
from typing import Dict, List, Type, Union
from typing import Dict, List, Type, TypeVar, Union

from ..exceptions import EntityNotFoundError
from ..model import Entity
from ..model import Entity as EntityModel

Entity = TypeVar("Entity", bound=EntityModel)


class AbstractRepository(abc.ABC):
Expand Down
8 changes: 2 additions & 6 deletions tests/integration/test_repository.py
Expand Up @@ -114,9 +114,7 @@ def test_repository_can_save_an_entity_without_id(

saved_entity = repo.last(type(inserted_entity))
assert saved_entity.id_ == inserted_entity.id_ + 1
# ignore: Entity doesn't have a name attribute, but all the models in the test
# cases do.
assert saved_entity.name == "Entity without id" # type: ignore
assert saved_entity.name == "Entity without id"


def test_repository_cant_save_an_entity_with_a_negative_id(
Expand All @@ -135,9 +133,7 @@ def test_repository_cant_save_an_entity_with_a_negative_id(

saved_entity = repo.last(type(inserted_entity))
assert saved_entity.id_ == inserted_entity.id_ + 1
# ignore: Entity doesn't have a name attribute, but all the models in the test
# cases do.
assert saved_entity.name == "Entity with negative id" # type: ignore
assert saved_entity.name == "Entity with negative id"


def test_repo_add_entity_is_idempotent(
Expand Down

0 comments on commit 4351f54

Please sign in to comment.