From 6de33c1bf07d7930ff4399d0ad0cc10fb9b15bae Mon Sep 17 00:00:00 2001 From: Matthias Schaub Date: Mon, 18 Nov 2024 17:04:04 +1300 Subject: [PATCH] refactor: remove unnecessary check check is not needed anymore because of request validation by pydantic models --- .../attribute_completeness/indicator.py | 23 ++++++------------- .../indicators/test_attribute_completeness.py | 15 ------------ tests/integrationtests/test_ohsome_client.py | 2 +- 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/ohsome_quality_api/indicators/attribute_completeness/indicator.py b/ohsome_quality_api/indicators/attribute_completeness/indicator.py index 2884be6ca..2a10c71b0 100644 --- a/ohsome_quality_api/indicators/attribute_completeness/indicator.py +++ b/ohsome_quality_api/indicators/attribute_completeness/indicator.py @@ -26,7 +26,8 @@ class AttributeCompleteness(BaseIndicator): attribute: Additional (expected) tag(s) describing a map feature. attribute_keys: a set of predefined attributes wich will be translated to an ohsome filter - attribute_filter: a custom ohsome filter + attribute_filter: ohsome filter query representing custom attributes + attribute_names: Names of the attributed represented by the Attribute Filter Example: How many buildings (topic) have height information (attribute)? @@ -54,16 +55,6 @@ def __init__( self.absolute_value_1 = None self.absolute_value_2 = None self.description = None - # fmt: off - # TODO: Remove once validated by pydantic request model - if ( - all(v is None for v in (attribute_keys, attribute_filter)) or - all(v is not None for v in (attribute_keys, attribute_filter)) - ): - raise TypeError( - "Either `attribute_keys` or `attribute_filter` needs to be given" - ) - # fmt: on if self.attribute_keys: self.attribute_filter = build_attribute_filter( self.attribute_keys, @@ -113,15 +104,15 @@ def calculate(self) -> None: ) def create_description(self): - all, matched = self.compute_units_for_all_and_matched() if self.result.value is None: - raise TypeError("result value should not be None") + raise TypeError("Result value should not be None.") else: result = round(self.result.value * 100, 1) - if len(self.attribute_names) > 1: - tags = "attributes " + ", ".join(self.attribute_names) + if self.attribute_names is None: + raise TypeError("Attribute names should not be None.") else: - tags = "attribute " + self.attribute_names[0] + tags = "attributes " + ", ".join(self.attribute_names) + all, matched = self.compute_units_for_all_and_matched() self.description = Template(self.templates.result_description).substitute( result=result, all=all, diff --git a/tests/integrationtests/indicators/test_attribute_completeness.py b/tests/integrationtests/indicators/test_attribute_completeness.py index cc59234ef..2c5984eb1 100644 --- a/tests/integrationtests/indicators/test_attribute_completeness.py +++ b/tests/integrationtests/indicators/test_attribute_completeness.py @@ -17,21 +17,6 @@ oqapi_vcr, ) - def test_preprocess_too_many_parameter( - self, - topic_building_count, - feature_germany_heidelberg, - attribute_key, - attribute_filter, - ): - with pytest.raises(TypeError): - AttributeCompleteness( - topic_building_count, - feature_germany_heidelberg, - attribute_key, - attribute_filter, - ) - class TestPreprocess: @oqapi_vcr.use_cassette diff --git a/tests/integrationtests/test_ohsome_client.py b/tests/integrationtests/test_ohsome_client.py index 0963f39e0..ace28f347 100644 --- a/tests/integrationtests/test_ohsome_client.py +++ b/tests/integrationtests/test_ohsome_client.py @@ -22,7 +22,7 @@ def test_query_ohsome_api_exceptions_404(): asyncio.run(ohsome_client.query_ohsome_api(url, {})) -@oqapi_vcr.use_cassette() +@oqapi_vcr.use_cassette def test_query_ohsome_api_exceptions_400(): url = "https://api.ohsome.org/v1/elements/length" with pytest.raises(OhsomeApiError, match="Invalid filter syntax."):