Skip to content

Commit

Permalink
Rename metadata model to config and add corpus type name to the confi…
Browse files Browse the repository at this point in the history
…g object
  • Loading branch information
annaCPR committed Dec 19, 2024
1 parent 6ecf584 commit 74d8c35
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/api/api_v1/routers/lookups/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from app.api.api_v1.routers.lookups.router import lookups_router
from app.clients.db.session import get_db
from app.models.metadata import ApplicationConfig
from app.models.config import ApplicationConfig
from app.repository.lookups import get_config
from app.service.custom_app import AppTokenFactory

Expand Down
1 change: 1 addition & 0 deletions app/models/metadata.py → app/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class CorpusConfig(BaseModel):
class CorpusTypeConfig(BaseModel):
"""Contains the CorpusType info as well as data of any corpora of that type"""

corpus_type_name: str
corpus_type_description: str
taxonomy: TaxonomyData
corpora: Sequence[CorpusConfig]
Expand Down
4 changes: 3 additions & 1 deletion app/repository/corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sqlalchemy.orm import Session

from app import config
from app.models.metadata import CorpusConfig, CorpusTypeConfig
from app.models.config import CorpusConfig, CorpusTypeConfig


def _get_family_stats_per_corpus(db: Session, corpus_import_id: str) -> dict[str, Any]:
Expand Down Expand Up @@ -46,6 +46,7 @@ def _to_corpus_type_config(row, stats: dict[str, Any]) -> dict[str, CorpusTypeCo
corpus_text = row.text if row.text is not None else ""
return {
row.corpus_type: CorpusTypeConfig(
corpus_type_name=row.corpus_type_name,
corpus_type_description=row.corpus_type_description,
taxonomy={**row.taxonomy},
corpora=[
Expand Down Expand Up @@ -81,6 +82,7 @@ def get_config_for_allowed_corpora(
Corpus.corpus_image_url.label("image_url"),
Corpus.corpus_text.label("text"),
Corpus.corpus_type_name.label("corpus_type"),
CorpusType.name.label("corpus_type_name"),
CorpusType.description.label("corpus_type_description"),
CorpusType.valid_metadata.label("taxonomy"),
Organisation.id.label("organisation_id"),
Expand Down
2 changes: 1 addition & 1 deletion app/repository/lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sqlalchemy.exc import MultipleResultsFound
from sqlalchemy.orm import Session

from app.models.metadata import ApplicationConfig
from app.models.config import ApplicationConfig
from app.repository.corpus import get_config_for_allowed_corpora
from app.repository.organisation import get_organisation_config, get_organisations
from app.service.pipeline import IMPORT_ID_MATCHER
Expand Down
2 changes: 1 addition & 1 deletion app/repository/organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sqlalchemy.orm import Session

from app import config
from app.models.metadata import CorpusData, OrganisationConfig
from app.models.config import CorpusData, OrganisationConfig


def _to_corpus_data(row) -> CorpusData:
Expand Down
1 change: 1 addition & 0 deletions tests/non_search/routers/lookups/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def test_config_endpoint_content(data_client, data_db, app_token_factory, valid_
assert list(corpus_types.keys()) == ["Laws and Policies", "Intl. agreements"]

laws_and_policies = corpus_types["Laws and Policies"]
assert laws_and_policies["corpus_type_name"] == "Laws and Policies"
assert laws_and_policies["corpus_type_description"] == "Laws and policies"

taxonomy = laws_and_policies["taxonomy"]
Expand Down

0 comments on commit 74d8c35

Please sign in to comment.