Skip to content

Commit

Permalink
Update & fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
khoidt committed Dec 10, 2024
1 parent 1e89adb commit 5415cd8
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 102 deletions.
2 changes: 1 addition & 1 deletion 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.dossier.application.dossier_repository import DossierRepository
from ebl.dossiers.application.dossier_repository import DossierRepository


@attr.s(auto_attribs=True, frozen=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABC, abstractmethod

from ebl.dossier.domain.dossier_record import (
from ebl.dossiers.domain.dossier_record import (
DossierRecord,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import attr
from typing import Sequence, Optional, FrozenSet
from typing import Sequence, Optional

from ebl.common.domain.provenance import Provenance
from ebl.fragmentarium.domain.fragment import Script
Expand All @@ -8,12 +8,12 @@

@attr.s(frozen=True, auto_attribs=True)
class DossierRecord:
name: str
_id: str
description: Optional[str] = None
is_approximate_date: bool = False
year_range_from: Optional[int] = None
year_range_to: Optional[int] = None
related_kings: Optional[Sequence[float]] = []
related_kings: Sequence[float] = []
provenance: Optional[Provenance] = None
script: Optional[Script] = None
references: FrozenSet[ReferenceType] = frozenset()
references: Sequence[ReferenceType] = []
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from marshmallow import Schema, fields, post_load, EXCLUDE
from pymongo.database import Database
from ebl.mongo_collection import MongoCollection
from ebl.dossier.domain.dossier_record import (
from ebl.dossiers.domain.dossier_record import (
DossierRecord,
)
from ebl.dossier.application.dossier_repository import DossierRepository
from ebl.dossiers.application.dossier_repository import DossierRepository
from ebl.common.domain.provenance import Provenance
from ebl.fragmentarium.application.fragment_schema import ScriptSchema
from ebl.schemas import NameEnumField
Expand All @@ -23,7 +23,7 @@ class DossierRecordSchema(Schema):
class Meta:
unknown = EXCLUDE

name = fields.String(required=True, unique=True)
_id = fields.String(required=True, unique=True)
description = fields.String(load_default=None)
is_approximate_date = fields.Boolean(
data_key="isApproximateDate", load_default=False
Expand All @@ -43,19 +43,7 @@ class Meta:

@post_load
def make_record(self, data, **kwargs):
return (
DossierRecord(
data["name"],
data["description"],
data["is_approximate_date"],
data["year_range_from"],
data["year_range_to"],
data["related_kings"],
data["provenance"],
data["script"],
frozenset(data["references"]),
),
)
return DossierRecord(**data)


class MongoDossierRepository(DossierRepository):
Expand All @@ -67,9 +55,6 @@ def fetch(self, name: str) -> DossierRecord:
record_data = self._dossier.find_one(query)
if not record_data:
raise ValueError(f"No dossier record found for the name: {name}")

print("!!!!!!!!!!", record_data)
input()
return DossierRecordSchema().load(record_data)

def create(self, dossier_record: DossierRecord) -> str:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import falcon
from ebl.context import Context

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


def create_afo_register_routes(api: falcon.App, context: Context):
dossier_resourse = DossierResource(context.dossier_repository)
api.add_route("/dossier", dossier_resourse)
api.add_route("/dossiers", dossier_resourse)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from falcon import Request, Response
from ebl.errors import NotFoundError

from ebl.dossier.application.dossier_repository import DossierRepository
from ebl.dossier.infrastructure.mongo_dossier_repository import (
from ebl.dossiers.application.dossier_repository import DossierRepository
from ebl.dossiers.infrastructure.mongo_dossier_repository import (
DossierRecordSchema,
)

Expand All @@ -16,6 +16,6 @@ def on_get(self, req: Request, resp: Response) -> None:
response = self._dossierRepository.fetch(req.params)
except ValueError as error:
raise NotFoundError(
f"No dossier entries matching {str(req.params)} found."
f"No dossier records matching {str(req.params)} found."
) from error
resp.media = DossierRecordSchema().dump(response, many=True)
2 changes: 1 addition & 1 deletion ebl/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
from ebl.afo_register.infrastructure.mongo_afo_register_repository import (
MongoAfoRegisterRepository,
)
from ebl.dossier.infrastructure.mongo_dossier_repository import (
from ebl.dossiers.infrastructure.mongo_dossier_repository import (
MongoDossierRepository,
)
from ebl.users.domain.user import Guest, User
Expand Down
27 changes: 0 additions & 27 deletions ebl/tests/dossier/test_dossier.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
AfoRegisterRecordSchema,
AfoRegisterRecordSuggestionSchema,
)
from ebl.tests.factories.afo_register import (
AfoRegisterRecordFactory,
AfoRegisterRecordSuggestionFactory,
)
@pytest.fixture
def afo_register_record():
Expand Down Expand Up @@ -57,15 +52,6 @@ def test_afo_register_record_to_dict(afo_register_record: AfoRegisterRecord) ->
}
def test_afo_register_record_suggestion_to_dict(
afo_register_record_suggestion: AfoRegisterRecordSuggestion,
) -> None:
assert AfoRegisterRecordSuggestionSchema().dump(afo_register_record_suggestion) == {
"text": afo_register_record_suggestion.text,
"textNumbers": afo_register_record_suggestion.text_numbers,
}
def test_afo_register_record_from_dict(afo_register_record: AfoRegisterRecord) -> None:
serialized_data = AfoRegisterRecordSchema().dump(afo_register_record)
deserialized_object = AfoRegisterRecordSchema().load(serialized_data)
Expand All @@ -80,17 +66,4 @@ def test_afo_register_record_from_dict(afo_register_record: AfoRegisterRecord) -
deserialized_object.discussed_by_notes == afo_register_record.discussed_by_notes
)
def test_afo_register_record_suggestion_from_dict(
afo_register_record_suggestion: AfoRegisterRecordSuggestion,
) -> None:
serialized_data = AfoRegisterRecordSuggestionSchema().dump(
afo_register_record_suggestion
)
deserialized_object = AfoRegisterRecordSuggestionSchema().load(serialized_data)
assert deserialized_object.text == afo_register_record_suggestion.text
assert (
deserialized_object.text_numbers == afo_register_record_suggestion.text_numbers
)
"""
2 changes: 1 addition & 1 deletion ebl/tests/dossier/test_dossier_repository.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ebl.tests.factories.dossier import DossierRecordFactory
from ebl.dossier.application.dossier_repository import DossierRepository
from ebl.dossiers.application.dossier_repository import DossierRepository


def test_fetch(dossier_repository: DossierRepository):
Expand Down
38 changes: 0 additions & 38 deletions ebl/tests/dossier/test_dossier_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,4 @@ def test_search_afo_register_record_route(
assert get_result.status == falcon.HTTP_OK
assert get_result.json == [AfoRegisterRecordSchema().dump(afo_register_record)]
def test_search_by_texts_and_numbers_route(
afo_register_repository: AfoRegisterRepository, client
) -> None:
record1 = AfoRegisterRecordFactory.build(text="Text1", text_number="1")
record2 = AfoRegisterRecordFactory.build(text="Text2", text_number="2")
record3 = AfoRegisterRecordFactory.build(text="Text3", text_number="3")
afo_register_repository.create(record1)
afo_register_repository.create(record2)
afo_register_repository.create(record3)
get_result = client.simulate_post(
"/afo-register/texts-numbers", body=json.dumps(["Text1 1", "Text3 3"])
)
expected_results = [
AfoRegisterRecordSchema().dump(record) for record in [record1, record3]
]
assert get_result.status == falcon.HTTP_OK
assert get_result.json == expected_results
def test_search_afo_register_suggestions_route(
afo_register_record, afo_register_repository: AfoRegisterRepository, client
) -> None:
afo_register_repository.create(afo_register_record)
get_result = client.simulate_get(
"/afo-register/suggestions",
params={"text_query": afo_register_record.text[:-2]},
)
afo_register_record_suggestion = AfoRegisterRecordSuggestionFactory.build(
text=afo_register_record.text, text_numbers=[afo_register_record.text_number]
)
assert get_result.status == falcon.HTTP_OK
assert get_result.json == [
AfoRegisterRecordSuggestionSchema().dump(afo_register_record_suggestion)
]
"""
9 changes: 4 additions & 5 deletions ebl/tests/factories/dossier.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import factory
from random import randint
from ebl.dossier.domain.dossier_record import (
from ebl.dossiers.domain.dossier_record import (
DossierRecord,
)
from ebl.tests.factories.bibliography import ReferenceFactory
from ebl.tests.factories.collections import TupleFactory
from ebl.common.domain.provenance import Provenance
from ebl.tests.factories.fragment import ScriptFactory
from ebl.chronology.chronology import chronology
from ebl.bibliography.domain.reference import ReferenceType


class DossierRecordFactory(factory.Factory):
Expand All @@ -28,6 +27,6 @@ class Meta:
)
provenance = factory.fuzzy.FuzzyChoice(set(Provenance) - {Provenance.STANDARD_TEXT})
script = factory.SubFactory(ScriptFactory)
references = factory.List(
[factory.SubFactory(ReferenceFactory, with_document=True)], TupleFactory
references = factory.LazyAttribute(
lambda _: list({list(ReferenceType)[i] for i in range(randint(1, 6))})
)

0 comments on commit 5415cd8

Please sign in to comment.