Skip to content

Commit adb308a

Browse files
test: unit test translation of indicator metadata
add a fixture for German locale.
1 parent c6f880a commit adb308a

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

tests/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import geojson
66
import pytest
7+
from fastapi_i18n.main import Translator, translator
78
from geojson import Feature, FeatureCollection, Polygon
89

910
from ohsome_quality_api.attributes.models import Attribute
@@ -265,3 +266,14 @@ def metadata_indicator_minimal() -> dict[str, IndicatorMetadata]:
265266
@pytest.fixture
266267
def indicators_metadata() -> dict[str, IndicatorMetadata]:
267268
return get_indicator_metadata()
269+
270+
271+
@pytest.fixture
272+
def locale_de(monkeypatch):
273+
monkeypatch.setenv(
274+
"FASTAPI_I18N_LOCALE_DIR",
275+
"/home/matthias/work/projects/oqapi/ohsome_quality_api/locale",
276+
)
277+
token = translator.set(Translator(locale="de"))
278+
yield
279+
translator.reset(token)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "Mapping Saturation",
3+
"description": "Berechne ob das Kartieren gesättigt ist. Bei hohe Sättigung ist die Steigung der Kurve minimal.",
4+
"projects": [
5+
"core",
6+
"corine-land-cover",
7+
"expanse",
8+
"experimental",
9+
"idealvgi",
10+
"mapaction",
11+
"sketchmap",
12+
"bkg",
13+
"unicef"
14+
],
15+
"quality_dimension": "completeness"
16+
}

tests/unittests/test_indicators_definitions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
import geojson
55
import pytest
6+
from approvaltests import verify
67
from geojson import Feature, Polygon
78

89
from ohsome_quality_api.indicators import definitions, models
10+
from tests.integrationtests.utils import PytestNamer
911

1012

1113
@pytest.fixture(scope="class")
@@ -61,6 +63,12 @@ def test_get_indicator(metadata_indicator_minimal):
6163
assert indicator == metadata_indicator_minimal["minimal"]
6264

6365

66+
@pytest.mark.usefixtures("locale_de")
67+
def test_get_indicator_de():
68+
indicator = definitions.get_indicator("mapping-saturation")
69+
verify(indicator.model_dump_json(indent=2), namer=PytestNamer())
70+
71+
6472
def test_get_coverage(mock_get_reference_coverage):
6573
coverage = asyncio.run(
6674
definitions.get_coverage("building-comparison", inverse=False)

0 commit comments

Comments
 (0)