Skip to content

Commit

Permalink
Update & add test
Browse files Browse the repository at this point in the history
  • Loading branch information
khoidt committed Dec 11, 2024
1 parent 2cf6830 commit fa677bc
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 76 deletions.
6 changes: 6 additions & 0 deletions ebl/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@
from ebl.signs.infrastructure.mongo_sign_repository import MongoSignRepository
from ebl.signs.web.bootstrap import create_signs_routes
from ebl.afo_register.web.bootstrap import create_afo_register_routes
from ebl.dossiers.web.bootstrap import create_dossiers_routes
from ebl.transliteration.application.parallel_line_injector import ParallelLineInjector
from ebl.transliteration.infrastructure.mongo_parallel_repository import (
MongoParallelRepository,
)
from ebl.afo_register.infrastructure.mongo_afo_register_repository import (
MongoAfoRegisterRepository,
)
from ebl.dossiers.infrastructure.mongo_dossiers_repository import (
MongoDossiersRepository,
)
from ebl.users.domain.user import Guest
from ebl.users.infrastructure.auth0 import Auth0Backend
from ebl.fragmentarium.infrastructure.mongo_findspot_repository import (
Expand Down Expand Up @@ -99,6 +103,7 @@ def create_context():
annotations_repository=MongoAnnotationsRepository(database),
lemma_repository=MongoLemmaRepository(database),
afo_register_repository=MongoAfoRegisterRepository(database),
dossiers_repository=MongoDossiersRepository(database),
findspot_repository=MongoFindspotRepository(database),
custom_cache=custom_cache,
cache=cache,
Expand Down Expand Up @@ -128,6 +133,7 @@ def create_app(context: Context, issuer: str = "", audience: str = ""):
create_lemmatization_routes(api, context)
create_markup_routes(api, context)
create_afo_register_routes(api, context)
create_dossiers_routes(api, context)

return api

Expand Down
4 changes: 2 additions & 2 deletions ebl/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from ebl.fragmentarium.infrastructure.mongo_findspot_repository import (
MongoFindspotRepository,
)
from ebl.dossiers.application.dossier_repository import DossierRepository
from ebl.dossiers.application.dossiers_repository import DossiersRepository


@attr.s(auto_attribs=True, frozen=True)
Expand All @@ -54,7 +54,7 @@ class Context:
cache: Cache
parallel_line_injector: ParallelLineInjector
afo_register_repository: AfoRegisterRepository
dossier_repository: DossierRepository
dossiers_repository: DossiersRepository

def get_bibliography(self):
return Bibliography(self.bibliography_repository, self.changelog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
)


class DossierRepository(ABC):
class DossiersRepository(ABC):
@abstractmethod
def fetch(self, name: str) -> DossierRecord: ...
def fetch(self, id: str) -> DossierRecord: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.

@abstractmethod
def create(self, dossier_record: DossierRecord) -> str: ...

Check notice

Code scanning / CodeQL

Statement has no effect Note

This statement has no effect.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ebl.dossiers.domain.dossier_record import (
DossierRecord,
)
from ebl.dossiers.application.dossier_repository import DossierRepository
from ebl.dossiers.application.dossiers_repository import DossiersRepository
from ebl.common.domain.provenance import Provenance
from ebl.fragmentarium.application.fragment_schema import ScriptSchema
from ebl.schemas import NameEnumField
Expand Down Expand Up @@ -46,7 +46,7 @@ def make_record(self, data, **kwargs):
return DossierRecord(**data)


class MongoDossierRepository(DossierRepository):
class MongoDossiersRepository(DossiersRepository):
def __init__(self, database: Database):
self._dossier = MongoCollection(database, COLLECTION)

Expand Down
6 changes: 3 additions & 3 deletions ebl/dossiers/web/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from ebl.context import Context

from ebl.dossiers.web.dossier_records import (
DossierResource,
DossiersResource,
)


def create_afo_register_routes(api: falcon.App, context: Context):
dossier_resourse = DossierResource(context.dossier_repository)
def create_dossiers_routes(api: falcon.App, context: Context):
dossier_resourse = DossiersResource(context.dossiers_repository)
api.add_route("/dossiers", dossier_resourse)
14 changes: 7 additions & 7 deletions ebl/dossiers/web/dossier_records.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from falcon import Request, Response
from ebl.errors import NotFoundError

from ebl.dossiers.application.dossier_repository import DossierRepository
from ebl.dossiers.infrastructure.mongo_dossier_repository import (
from ebl.dossiers.application.dossiers_repository import DossiersRepository
from ebl.dossiers.infrastructure.mongo_dossiers_repository import (
DossierRecordSchema,
)


class DossierResource:
def __init__(self, _dossierRepository: DossierRepository):
self._dossierRepository = _dossierRepository
class DossiersResource:
def __init__(self, _dossiersRepository: DossiersRepository):
self._dossiersRepository = _dossiersRepository

def on_get(self, req: Request, resp: Response) -> None:
try:
response = self._dossierRepository.fetch(req.params)
dossiers = self._dossiersRepository.fetch(req.params["id"])
except ValueError as error:
raise NotFoundError(
f"No dossier records matching {str(req.params)} found."
) from error
resp.media = DossierRecordSchema().dump(response, many=True)
resp.media = DossierRecordSchema().dump([dossiers], many=True)
12 changes: 6 additions & 6 deletions ebl/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
from ebl.afo_register.infrastructure.mongo_afo_register_repository import (
MongoAfoRegisterRepository,
)
from ebl.dossiers.infrastructure.mongo_dossier_repository import (
MongoDossierRepository,
from ebl.dossiers.infrastructure.mongo_dossiers_repository import (
MongoDossiersRepository,
)
from ebl.users.domain.user import Guest, User
from ebl.users.infrastructure.auth0 import Auth0User
Expand Down Expand Up @@ -438,8 +438,8 @@ def user() -> User:


@pytest.fixture
def dossier_repository(database):
return MongoDossierRepository(database)
def dossiers_repository(database):
return MongoDossiersRepository(database)


@pytest.fixture
Expand All @@ -459,7 +459,7 @@ def context(
annotations_repository,
lemma_repository,
afo_register_repository,
dossier_repository,
dossiers_repository,
findspot_repository,
user,
parallel_line_injector,
Expand All @@ -482,7 +482,7 @@ def context(
annotations_repository=annotations_repository,
lemma_repository=lemma_repository,
afo_register_repository=afo_register_repository,
dossier_repository=dossier_repository,
dossiers_repository=dossiers_repository,
findspot_repository=findspot_repository,
cache=Cache({"CACHE_TYPE": "null"}),
custom_cache=ChapterCache(mongo_cache_repository),
Expand Down
6 changes: 4 additions & 2 deletions ebl/tests/dossiers/test_dossier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ebl.dossiers.domain.dossier_record import (
DossierRecord,
)
from ebl.dossiers.infrastructure.mongo_dossier_repository import (
from ebl.dossiers.infrastructure.mongo_dossiers_repository import (
DossierRecordSchema,
)
from ebl.tests.factories.dossier import DossierRecordFactory
Expand Down Expand Up @@ -54,7 +54,9 @@ def test_dossier_record_to_dict(
"yearRangeFrom": dossier_record.year_range_from,
"yearRangeTo": dossier_record.year_range_to,
"relatedKings": dossier_record.related_kings,
"provenance": dossier_record.provenance.long_name,
"provenance": dossier_record.provenance.long_name
if dossier_record.provenance
else None,
"script": ScriptSchema().dump(dossier_record.script),
"references": [
str(reference).replace("ReferenceType.", "")
Expand Down
10 changes: 0 additions & 10 deletions ebl/tests/dossiers/test_dossier_repository.py

This file was deleted.

42 changes: 0 additions & 42 deletions ebl/tests/dossiers/test_dossier_route.py

This file was deleted.

10 changes: 10 additions & 0 deletions ebl/tests/dossiers/test_dossiers_repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from ebl.tests.factories.dossier import DossierRecordFactory
from ebl.dossiers.application.dossiers_repository import DossiersRepository


def test_fetch(dossiers_repository: DossiersRepository):
dossier_record = DossierRecordFactory.build()
dossiers_repository.create(dossier_record)
dossiers_repository.create(DossierRecordFactory.build())

assert dossiers_repository.fetch(dossier_record.id) == dossier_record
28 changes: 28 additions & 0 deletions ebl/tests/dossiers/test_dossiers_route.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import falcon
import pytest

from ebl.dossiers.domain.dossier_record import DossierRecord
from ebl.tests.factories.dossier import (
DossierRecordFactory,
)
from ebl.dossiers.application.dossiers_repository import (
DossiersRepository,
)
from ebl.dossiers.infrastructure.mongo_dossiers_repository import (
DossierRecordSchema,
)


@pytest.fixture
def dossier_record() -> DossierRecord:
return DossierRecordFactory.build()


def test_fetch_dossier_record_route(
dossier_record, dossiers_repository: DossiersRepository, client
) -> None:
dossiers_repository.create(dossier_record)
get_result = client.simulate_get("/dossiers", params={"id": dossier_record.id})

assert get_result.status == falcon.HTTP_OK
assert get_result.json[0] == DossierRecordSchema().dump(dossier_record)

0 comments on commit fa677bc

Please sign in to comment.