-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from spraakbanken/fix-sql-entries
Avoid name clashes in SqlEntryRepository
- Loading branch information
Showing
4 changed files
with
141 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .sql_entry_uows import SqlEntryUowRepository, SqlEntryUowRepositoryUnitOfWork | ||
from .sql_entries import SqlEntryUowCreator | ||
from .sql_entries import SqlEntryUowV1Creator, SqlEntryUowV2Creator | ||
from .sql_resources import SqlResourceRepository, SqlResourceUnitOfWork |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from unittest import mock | ||
|
||
import pytest | ||
import ulid | ||
|
||
from karp.foundation.events import EventBus | ||
from karp import lex | ||
from karp.lex_infrastructure import SqlEntryUowV1Creator, SqlEntryUowV2Creator | ||
from karp.tests.unit.lex import factories | ||
|
||
|
||
@pytest.fixture | ||
def example_uow() -> lex.CreateEntryRepository: | ||
return factories.CreateEntryRepositoryFactory() | ||
|
||
|
||
@pytest.fixture | ||
def sql_entry_uow_v1_creator(sqlite_session_factory) -> SqlEntryUowV1Creator: | ||
return SqlEntryUowV1Creator( | ||
event_bus=mock.Mock(spec=EventBus), | ||
session_factory=sqlite_session_factory, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def sql_entry_uow_v2_creator(sqlite_session_factory) -> SqlEntryUowV2Creator: | ||
return SqlEntryUowV2Creator( | ||
event_bus=mock.Mock(spec=EventBus), | ||
session_factory=sqlite_session_factory, | ||
) | ||
|
||
|
||
class TestSqlEntryUowV1: | ||
def test_creator_repository_type( | ||
self, | ||
sql_entry_uow_v1_creator: SqlEntryUowV1Creator, | ||
): | ||
assert sql_entry_uow_v1_creator.repository_type == 'sql_entries_v1' | ||
|
||
def test_uow_repository_type( | ||
self, | ||
sql_entry_uow_v1_creator: SqlEntryUowV1Creator, | ||
example_uow: lex.CreateEntryRepository, | ||
): | ||
entry_uow = sql_entry_uow_v1_creator( | ||
**example_uow.dict(exclude={'repository_type'}) | ||
) | ||
assert entry_uow.repository_type == 'sql_entries_v1' | ||
|
||
def test_repo_table_name( | ||
self, | ||
sql_entry_uow_v1_creator: SqlEntryUowV1Creator, | ||
example_uow: lex.CreateEntryRepository, | ||
): | ||
entry_uow = sql_entry_uow_v1_creator( | ||
**example_uow.dict(exclude={'repository_type'}) | ||
) | ||
with entry_uow as uw: | ||
assert uw.repo.history_model.__tablename__ == example_uow.name | ||
|
||
|
||
class TestSqlEntryUowV2: | ||
def test_creator_repository_type( | ||
self, | ||
sql_entry_uow_v2_creator: SqlEntryUowV2Creator, | ||
): | ||
assert sql_entry_uow_v2_creator.repository_type == 'sql_entries_v2' | ||
|
||
def test_uow_repository_type( | ||
self, | ||
sql_entry_uow_v2_creator: SqlEntryUowV2Creator, | ||
example_uow: lex.CreateEntryRepository, | ||
): | ||
entry_uow = sql_entry_uow_v2_creator( | ||
**example_uow.dict(exclude={'repository_type'}) | ||
) | ||
assert entry_uow.repository_type == 'sql_entries_v2' | ||
|
||
def test_repo_table_name( | ||
self, | ||
sql_entry_uow_v2_creator: SqlEntryUowV2Creator, | ||
example_uow: lex.CreateEntryRepository, | ||
): | ||
entry_uow = sql_entry_uow_v2_creator( | ||
**example_uow.dict(exclude={'repository_type'}) | ||
) | ||
random_part = ulid.from_uuid(entry_uow.entity_id).randomness().str | ||
with entry_uow as uw: | ||
assert uw.repo.history_model.__tablename__ == f'{example_uow.name}_{random_part}' |