Skip to content

Commit

Permalink
test: add unit tests to new function
Browse files Browse the repository at this point in the history
#810

Co-authored-by: Sascha Fendrich <[email protected]>
  • Loading branch information
mmerdes and Sascha Fendrich committed Aug 29, 2024
1 parent 8b1f177 commit 9cee56c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ohsome_quality_api/utils/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

def validate_attribute_topic_combination(attribute: AttributeEnum, topic: TopicEnum):
"""As attributes are only meaningful for a certain topic,
we need to check if the given combination is valid"""
we need to check if the given combination is valid."""

valid_attributes_for_topic = get_attributes()[topic]
all_attributes = [attribute for attribute in valid_attributes_for_topic]

Expand Down
18 changes: 18 additions & 0 deletions tests/unittests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

from ohsome_quality_api.utils.exceptions import (
AttributeTopicCombinationError,
GeoJSONError,
GeoJSONGeometryTypeError,
GeoJSONObjectTypeError,
Expand All @@ -12,12 +13,29 @@
)
from ohsome_quality_api.utils.validators import (
validate_area,
validate_attribute_topic_combination,
validate_geojson,
validate_indicator_topic_combination,
)
from tests.unittests.utils import get_geojson_fixture


def test_validate_attribute_topic_combination_with_valid_combination():
validate_attribute_topic_combination("maxspeed", "roads")


def test_validate_attribute_topic_combination_with_invalid_topic():
"""As the method under test requires individually valid arguments
the arguments given lead to a KeyError."""
with pytest.raises(KeyError):
validate_attribute_topic_combination("maxspeed", "xxxxx")


def test_validate_attribute_topic_combination_with_invalid_combination():
with pytest.raises(AttributeTopicCombinationError):
validate_attribute_topic_combination("maxspeed", "building-count")


def test_validate_geojson_feature_collection_single(
feature_collection_germany_heidelberg,
):
Expand Down

0 comments on commit 9cee56c

Please sign in to comment.