Skip to content

Commit

Permalink
refactor: Improve Editor class dependency injection
Browse files Browse the repository at this point in the history
This commit refactors the Editor class to reduce direct dependencies on the Config module:
- Remove direct import of Config from editor.py
- Add dataset_is_quadstore parameter to Editor constructor with sensible default
- Update all Editor instantiations to pass configuration explicitly
- Improve testability by reducing tight coupling with configuration

These changes make the Editor class more modular and testable, while also fixing the ImportError in GitHub Actions tests by eliminating the dependency on the config.py file.
  • Loading branch information
arcangelo7 committed Feb 27, 2025
1 parent 14376df commit 38759f7
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions heritrace/editor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections import defaultdict
from datetime import datetime

from config import Config
from rdflib import XSD, Graph, Literal, URIRef
from rdflib.plugins.sparql.algebra import translateUpdate
from rdflib.plugins.sparql.parser import parseUpdate
Expand All @@ -21,14 +20,15 @@ def __init__(
resp_agent: URIRef,
source: URIRef = None,
c_time: datetime | None = None,
dataset_is_quadstore: bool = True,
):
self.dataset_endpoint = dataset_endpoint
self.provenance_endpoint = provenance_endpoint
self.counter_handler = counter_handler
self.resp_agent = resp_agent
self.source = source
self.c_time = self.to_posix_timestamp(c_time)
self.dataset_is_quadstore = Config.DATASET_IS_QUADSTORE
self.dataset_is_quadstore = dataset_is_quadstore
self.g_set = (
OCDMConjunctiveGraph(self.counter_handler)
if self.dataset_is_quadstore
Expand Down
1 change: 1 addition & 0 deletions heritrace/routes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ def apply_changes():
URIRef(f"https://orcid.org/{current_user.orcid}"),
current_app.config["PRIMARY_SOURCE"],
current_app.config["DATASET_GENERATION_TIME"],
dataset_is_quadstore=current_app.config["DATASET_IS_QUADSTORE"],
)
editor = import_entity_graph(editor, subject)
editor.preexisting_finished()
Expand Down
2 changes: 2 additions & 0 deletions heritrace/routes/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ def create_entity():
URIRef(f"https://orcid.org/{current_user.orcid}"),
current_app.config["PRIMARY_SOURCE"],
current_app.config["DATASET_GENERATION_TIME"],
dataset_is_quadstore=current_app.config["DATASET_IS_QUADSTORE"],
)

if get_form_fields():
Expand Down Expand Up @@ -1084,6 +1085,7 @@ def restore_version(entity_uri, timestamp):
URIRef(f"https://orcid.org/{current_user.orcid}"),
None if is_deleted else entity_snapshots[entity_uri]["source"],
current_app.config["DATASET_GENERATION_TIME"],
dataset_is_quadstore=current_app.config["DATASET_IS_QUADSTORE"],
)

# Import current state into editor
Expand Down
Binary file modified tests/test_dataset_db/virtuoso.trx
Binary file not shown.
Binary file modified tests/test_provenance_db/virtuoso.trx
Binary file not shown.
1 change: 1 addition & 0 deletions tests/unit/test_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def editor(mock_counter_handler):
provenance_endpoint=provenance_endpoint,
counter_handler=mock_counter_handler,
resp_agent=resp_agent,
dataset_is_quadstore=True,
)
return editor

Expand Down

0 comments on commit 38759f7

Please sign in to comment.