Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dossier to fragment #595

Merged
merged 10 commits into from
Jan 16, 2025
Merged

Add dossier to fragment #595

merged 10 commits into from
Jan 16, 2025

Conversation

khoidt
Copy link
Contributor

@khoidt khoidt commented Jan 14, 2025

Summary by Sourcery

New Features:

  • Associate dossiers with fragments.

Copy link
Contributor

sourcery-ai bot commented Jan 14, 2025

Reviewer's Guide by Sourcery

This pull request implements the "Add dossier to fragment" feature by adding dossiers to the fragment schema and domain models.

Class diagram for new Dossier and Fragment relationship

classDiagram
    class Fragment {
        +number: MuseumNumber
        +dossiers: Sequence[str]
        +other fields...
    }

    class DossierReference {
        +dossierId: str
        +isUncertain: bool
    }

    class DossierRecord {
        +id: str
        +description: Optional[str]
        +is_approximate_date: bool
        +year_range_from: Optional[int]
        +year_range_to: Optional[int]
        +related_kings: Sequence[float]
        +provenance: Optional[Provenance]
        +script: Optional[Script]
        +references: Sequence[Reference]
    }

    Fragment "1" -- "*" DossierReference
    DossierReference -- DossierRecord

    note for Fragment "Fragment now includes dossier references"
    note for DossierRecord "New entity to store dossier information"
Loading

File-Level Changes

Change Details Files
Added dossiers field to Fragment model and schema.
  • Added the dossiers field to the Fragment class.
  • Added the dossiers field to the FragmentSchema.
  • Added support for dossiers in the fragment factory.
  • Updated tests to include the dossiers field in the expected DTO and factory.
ebl/fragmentarium/application/fragment_schema.py
ebl/fragmentarium/domain/fragment.py
ebl/tests/factories/fragment.py
ebl/tests/fragmentarium/test_dtos.py
Added DossierReference model and schema.
  • Created the DossierReference class.
  • Created the DossierReferenceSchema.
  • Added support for dossier references in the fragment factory.
ebl/fragmentarium/domain/fragment.py
ebl/tests/factories/fragment.py
ebl/fragmentarium/application/fragment_fields_schemas.py
Added dossiers repository and route.
  • Added MongoDossiersRepository.
  • Added /dossiers route.
  • Added DossiersRepository interface.
  • Added dossiers repository to the application context.
  • Added tests for the dossiers repository and route.
  • Created dossier factory.
ebl/tests/conftest.py
ebl/app.py
ebl/context.py
ebl/dossiers/web/bootstrap.py
ebl/dossiers/application/dossiers_repository.py
ebl/dossiers/infrastructure/mongo_dossiers_repository.py
ebl/dossiers/web/dossier_records.py
ebl/dossiers/domain/dossier_record.py
ebl/tests/dossiers/test_dossiers_repository.py
ebl/tests/dossiers/test_dossier.py
ebl/tests/dossiers/test_dossiers_route.py
ebl/tests/factories/dossier.py
Moved nested schemas to separate file.
  • Moved nested schemas from fragment_schema.py to fragment_fields_schemas.py.
  • Updated imports in affected files.
ebl/fragmentarium/application/fragment_schema.py
ebl/fragmentarium/application/fragment_fields_schemas.py
ebl/fragmentarium/web/fragment_script.py
ebl/tests/fragmentarium/test_line_to_vec_ranking_schema.py
ebl/tests/fragmentarium/test_fragment_script_route.py
ebl/tests/fragmentarium/test_script_schema.py
ebl/fragmentarium/application/annotations_schema.py
ebl/fragmentarium/application/fragment_info_schema.py
ebl/fragmentarium/application/line_to_vec_ranking_schema.py
ebl/fragmentarium/infrastructure/mongo_fragment_repository_get_extended.py
Updated king order to be a float.
  • Changed King.order_global type from int to float.
  • Updated KingSchema to use fields.Float for order_global.
  • Updated dossier factory to generate float values for related_kings.
ebl/chronology/chronology.py
ebl/tests/factories/dossier.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@khoidt khoidt changed the title Add-dossier-to-fragment Add dossier to fragment Jan 14, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @khoidt - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Changing order_global from int to float in the King class is a breaking change that could have unintended consequences. Please document the rationale for this change and ensure all consumers of this field are updated accordingly.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +125 to +126
"dossiers": [
DossierReferenceSchema().dump(dossier)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Add a test case for empty dossiers list

It would be beneficial to include a test case where the dossiers list is empty to ensure proper handling of this scenario.

Suggested implementation:

    ScriptSchema,
    DossierReferenceSchema,
)
from ebl.fragmentarium.application.joins_schema import JoinsSchema
from ebl.fragmentarium.domain.lemmatized_fragment import LemmatizedFragment

def test_serialize_lemmatized_fragment_empty_dossiers():
    lemmatized_fragment = LemmatizedFragment(
        # Add minimal required properties
        number="X.1",
        dossiers=[]  # Empty dossiers list
    )

    serialized = LemmatizedFragmentSchema().dump(lemmatized_fragment)

    assert serialized["dossiers"] == []

The test implementation assumes a basic LemmatizedFragment constructor. You may need to:

  1. Add any required constructor parameters based on your actual LemmatizedFragment class implementation
  2. Add any necessary test doubles/mocks for dependencies
  3. Adjust the assertion if there are additional properties that need to be verified

Comment on lines +35 to +36
client,
) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Test for invalid dossier IDs

Add a test case to verify the behavior of the API endpoint when provided with invalid or non-existent dossier IDs. This could involve checking for appropriate error responses (e.g., 404 Not Found) and ensuring that no unexpected exceptions are raised.

Suggested implementation:

    assert sorted(get_result.json, key=lambda r: r["_id"]) == DossierRecordSchema(
        many=True
    ).dump(sorted([dossier_record, another_dossier_record], key=lambda r: r.id))


def test_fetch_dossier_record_route_invalid_ids(
    dossiers_repository: DossiersRepository,
    client,
) -> None:
    non_existent_id = "non_existent_id"
    another_non_existent_id = "another_non_existent_id"

    get_result = client.simulate_get(
        "/dossiers",
        params={"ids[]": [non_existent_id, another_non_existent_id]},
    )

    assert get_result.status == falcon.HTTP_NOT_FOUND
    assert get_result.json == {
        "title": "Dossiers not found",
        "description": f"Dossiers with IDs {[non_existent_id, another_non_existent_id]} not found"
    }

Note: This assumes that:

  1. The API endpoint is already set up to return a 404 status and appropriate error message when dossiers are not found
  2. If the error response format is different in the actual implementation, you'll need to adjust the assertion of get_result.json to match the actual error response structure

Comment on lines +19 to +21
ids = parsed_params.get("ids[]", [])
if not ids:
raise ValueError("No valid IDs provided in the request.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): We've found these issues:

@khoidt khoidt merged commit c179479 into Add-rust-to-docker Jan 16, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant