BTHLABS-61: Service layer refactoring

A journey to fix `ValidationError` in Pocket imports turned service
layer refactoring :D
This commit is contained in:
2025-10-12 18:37:32 +00:00
parent ac7a8dd90e
commit 8b86145519
45 changed files with 1023 additions and 337 deletions

View File

@@ -76,6 +76,18 @@ def starred_association_out(starred_association):
)
@pytest.fixture
def deleted_save_association(association_factory, deleted_save):
return association_factory(target=deleted_save)
@pytest.fixture
def deleted_save_association_out(deleted_save_association):
return AssociationWithTargetOut.model_validate(
deleted_save_association, from_attributes=True,
)
@pytest.fixture
def other_account_association(association_factory, other_account):
return association_factory(account=other_account)
@@ -124,6 +136,18 @@ def other_account_starred_association_out(other_account_starred_association):
)
@pytest.fixture
def other_account_deleted_save_association(association_factory, other_account, deleted_save):
return association_factory(account=other_account, target=deleted_save)
@pytest.fixture
def other_account_deleted_save_association_out(other_account_deleted_save_association):
return AssociationWithTargetOut.model_validate(
other_account_deleted_save_association, from_attributes=True,
)
@pytest.fixture
def browsable_associations(association,
deleted_association,

View File

@@ -64,11 +64,25 @@ def pocket_import_banned_netloc_save_spec():
})
@pytest.fixture
def pocket_import_invalid_url_spec():
return PocketImportSaveSpec.model_validate({
'title': "This isn't right",
'url': 'thisisntright',
'time_added': datetime.datetime(
2021, 1, 18, 8, 0, 0, 0, tzinfo=datetime.UTC,
),
'tags': '',
'status': 'unread',
})
@pytest.fixture
def pocket_csv_content(pocket_import_created_save_spec,
pocket_import_reused_save_spec,
pocket_import_other_account_save_spec,
pocket_import_banned_netloc_save_spec,
pocket_import_invalid_url_spec,
):
with io.StringIO() as csv_f:
field_names = [
@@ -82,6 +96,7 @@ def pocket_csv_content(pocket_import_created_save_spec,
pocket_import_reused_save_spec.dict(),
pocket_import_other_account_save_spec.dict(),
pocket_import_banned_netloc_save_spec.dict(),
pocket_import_invalid_url_spec.dict(),
])
csv_f.seek(0)

View File

@@ -29,6 +29,20 @@ class AssociationsTestingService:
if reference is not None:
assert association.updated_at > reference.updated_at
def assert_deleted(self, *, pk: uuid.UUID, reference: typing.Any = None):
association = Association.objects.get(pk=pk)
assert association.deleted_at is not None
if reference is not None:
assert association.updated_at > reference.updated_at
def assert_not_deleted(self, *, pk: uuid.UUID, reference: typing.Any = None):
association = Association.objects.get(pk=pk)
assert association.deleted_at is None
if reference is not None:
assert association.updated_at == reference.updated_at
def assert_starred(self, *, pk: uuid.UUID, reference: typing.Any = None):
association = Association.objects.get(pk=pk)
assert association.starred_at is not None