Restructure where the CRUD base class lives for clarity and to avoid circular deps
This commit is contained in:
parent
0d884e5836
commit
c3cd7c2796
8 changed files with 40 additions and 37 deletions
|
|
@ -1,12 +1,12 @@
|
|||
from sqlalchemy import Engine
|
||||
from typing import Callable
|
||||
from src.infra import CRUDRepo, Base
|
||||
from src.infra import CRUDRepoImpl, Base
|
||||
import pytest
|
||||
|
||||
|
||||
class CRUDRepoHelper[A: Base, B, C]:
|
||||
@pytest.fixture
|
||||
def repo(self, db: Engine) -> CRUDRepo[A, B, C]:
|
||||
def repo(self, db: Engine) -> CRUDRepoImpl[A, B, C]:
|
||||
import pdb
|
||||
|
||||
pdb.set_trace()
|
||||
|
|
@ -17,7 +17,7 @@ class CRUDRepoHelper[A: Base, B, C]:
|
|||
raise NotImplementedError()
|
||||
|
||||
@pytest.fixture
|
||||
def item(self, repo: CRUDRepo[A, B, C], dto: C) -> B:
|
||||
def item(self, repo: CRUDRepoImpl[A, B, C], dto: C) -> B:
|
||||
return repo.create(dto, None)
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -31,26 +31,28 @@ class CRUDRepoHelper[A: Base, B, C]:
|
|||
def test_create(self, item: B):
|
||||
assert item is not None
|
||||
|
||||
def test_create_returns_none_if_invalid(self, repo: CRUDRepo[A, B, C], dto: C):
|
||||
def test_create_returns_none_if_invalid(self, repo: CRUDRepoImpl[A, B, C], dto: C):
|
||||
def always_invalid(*_args, **_kw):
|
||||
raise ValueError('test')
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
repo.create(dto, always_invalid)
|
||||
|
||||
def test_create_returns_a_value_if_valid(self, repo: CRUDRepo[A, B, C], dto: C):
|
||||
def test_create_returns_a_value_if_valid(self, repo: CRUDRepoImpl[A, B, C], dto: C):
|
||||
assert repo.create(dto, lambda _: None) is not None
|
||||
|
||||
def test_get_returns_none_when_missing(self, repo: CRUDRepo[A, B, C]):
|
||||
def test_get_returns_none_when_missing(self, repo: CRUDRepoImpl[A, B, C]):
|
||||
assert repo.get(42) is None
|
||||
|
||||
def test_get_returns_a_value_if_it_exists(self, repo: CRUDRepo[A, B, C], item: B):
|
||||
def test_get_returns_a_value_if_it_exists(self, repo: CRUDRepoImpl[A, B, C], item: B):
|
||||
assert repo.get(1) == item
|
||||
|
||||
def test_update(self, repo: CRUDRepo[A, B, C], transform: Callable[[B], B], item: B, expected_transformed_value: B):
|
||||
def test_update(
|
||||
self, repo: CRUDRepoImpl[A, B, C], transform: Callable[[B], B], item: B, expected_transformed_value: B
|
||||
):
|
||||
assert repo.update(1, transform) == expected_transformed_value
|
||||
|
||||
def test_delete(self, repo: CRUDRepo[A, B, C], item: B):
|
||||
def test_delete(self, repo: CRUDRepoImpl[A, B, C], item: B):
|
||||
assert repo.get(1) is not None
|
||||
repo.delete(1, None)
|
||||
assert repo.get(1) is None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue