Skip to content

Commit

Permalink
Add corpus type to config (#252)
Browse files Browse the repository at this point in the history
* Add corpus types to config

* Bump to 2.17.15

* Check uniqueness

* Don't include taxonomy in ct on config

* Revert "Don't include taxonomy in ct on config"

This reverts commit b967c7a.
  • Loading branch information
katybaulch authored Nov 20, 2024
1 parent 81e159c commit f549e9a
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/model/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ class ConfigReadDTO(BaseModel):

geographies: Sequence[dict]
corpora: Sequence[CorpusData]
corpus_types: Sequence[dict]
languages: Mapping[str, str]
document: DocumentConfig
27 changes: 27 additions & 0 deletions app/repository/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def get(db: Session, user: UserContext) -> ConfigReadDTO:
corpora = get_corpora(db, user)
languages = {lang.language_code: lang.name for lang in db.query(Language).all()}

corpus_types = get_unique_corpus_types(corpora)

# Now Document config
doc_config = DocumentConfig(
variants=[
Expand All @@ -101,6 +103,31 @@ def get(db: Session, user: UserContext) -> ConfigReadDTO:
return ConfigReadDTO(
geographies=geographies,
corpora=corpora,
corpus_types=corpus_types,
languages=languages,
document=doc_config,
)


def get_unique_corpus_types(corpora):
"""Generate a list of unique corpus type dictionaries.
:param List[Corpus] corpora: List of corpus items.
:return List[Dict[str, Any]]: List of unique corpus type
dictionaries.
"""
seen = set()
unique_corpus_types = []
for c in corpora:
# Create a tuple of name and description for uniqueness check
unique_key = (c.corpus_type, c.corpus_type_description)
if unique_key not in seen:
seen.add(unique_key)
unique_corpus_types.append(
{
"name": c.corpus_type,
"description": c.corpus_type_description,
"taxonomy": c.taxonomy,
}
)
return unique_corpus_types
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "admin_backend"
version = "2.17.14"
version = "2.17.15"
description = ""
authors = ["CPR-dev-team <[email protected]>"]
packages = [{ include = "app" }, { include = "tests" }]
Expand Down
8 changes: 7 additions & 1 deletion tests/integration_tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

from tests.integration_tests.setup_db import setup_db

EXPECTED_CONFIG_KEYS = {"geographies", "corpora", "languages", "document"}
EXPECTED_CONFIG_KEYS = {
"geographies",
"corpora",
"corpus_types",
"languages",
"document",
}
EXPECTED_CORPORA_CONFIG_KEYS = {
"corpus_import_id",
"title",
Expand Down
1 change: 1 addition & 0 deletions tests/mocks/repos/config_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def mock_get(_) -> Optional[ConfigReadDTO]:
return ConfigReadDTO(
geographies=[],
corpora=[],
corpus_types=[],
languages={},
document=DocumentConfig(variants=[]),
)
Expand Down
1 change: 1 addition & 0 deletions tests/mocks/services/config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def mock_get_config(_) -> ConfigReadDTO:
return ConfigReadDTO(
geographies=[],
corpora=[],
corpus_types=[],
languages={},
document=DocumentConfig(variants=[]),
)
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/routers/config/test_get_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def test_get_when_ok(client: TestClient, user_header_token, config_service_mock)
keys = data.keys()
assert "geographies" in keys
assert "corpora" in keys
assert "corpus_types" in keys
assert "languages" in keys
assert "document" in keys
assert config_service_mock.get.call_count == 1
Expand Down

0 comments on commit f549e9a

Please sign in to comment.