Skip to content

Commit

Permalink
ensure external identifiers structure
Browse files Browse the repository at this point in the history
  • Loading branch information
the-infinity committed Nov 27, 2024
1 parent dab5784 commit 011ed3a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
25 changes: 16 additions & 9 deletions src/parkapi_sources/converters/kienzler/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from datetime import datetime, timezone
from decimal import Decimal
from typing import Optional
from typing import Any, Optional

from validataclass.dataclasses import Default, ValidataclassMixin, validataclass
from validataclass.validators import (
Expand All @@ -18,7 +18,8 @@
)

from parkapi_sources.models import GeojsonBaseFeatureInput, RealtimeParkingSiteInput, StaticParkingSiteInput
from parkapi_sources.models.enums import ExternalIdentifierType, ParkAndRideType, ParkingSiteType, PurposeType
from parkapi_sources.models.enums import ParkAndRideType, ParkingSiteType, PurposeType
from parkapi_sources.models.parking_site_inputs import ExternalIdentifierInput


@validataclass
Expand Down Expand Up @@ -55,12 +56,6 @@ def to_realtime_parking_site(self) -> RealtimeParkingSiteInput:
)


@validataclass
class ExternalIdentifier(ValidataclassMixin):
type: ExternalIdentifierType = EnumValidator(ExternalIdentifierType)
value: str = StringValidator()


@validataclass
class KienzlerGeojsonFeaturePropertiesInput(ValidataclassMixin):
uid: str = StringValidator(min_length=1, max_length=256)
Expand All @@ -70,7 +65,19 @@ class KienzlerGeojsonFeaturePropertiesInput(ValidataclassMixin):
max_width: int = IntegerValidator(min_value=0)
max_depth: int = IntegerValidator(min_value=0)
park_and_ride_type: list[ParkAndRideType] = ListValidator(EnumValidator(ParkAndRideType))
external_identifiers: Optional[list[ExternalIdentifier]] = ListValidator(DataclassValidator(ExternalIdentifier))
external_identifiers: Optional[list[ExternalIdentifierInput]] = ListValidator(
DataclassValidator(
ExternalIdentifierInput,
),
)

def to_dict(self, **kwargs) -> dict[str, Any]:
result = super().to_dict(**kwargs)

# We want the original structure as we want to use it for updating StaticParkingSiteInputs
result['external_identifiers'] = self.external_identifiers

return result


@validataclass
Expand Down
6 changes: 3 additions & 3 deletions tests/converters/kienzler_geojson_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from parkapi_sources.converters import KienzlerBikeAndRidePullConverter
from parkapi_sources.converters.kienzler.models import KienzlerGeojsonFeatureInput
from parkapi_sources.models.enums import ParkAndRideType
from parkapi_sources.models.enums import ExternalIdentifierType, ParkAndRideType
from tests.converters.helper import validate_realtime_parking_site_inputs, validate_static_parking_site_inputs


Expand Down Expand Up @@ -101,8 +101,8 @@ def test_get_static_parking_sites_with_geojson(
assert static_parking_site_input.max_height == 1250
assert static_parking_site_input.max_width == 800
assert static_parking_site_input.park_and_ride_type == [ParkAndRideType.TRAIN]
assert static_parking_site_input.external_identifiers[0]['type'].value == 'DHID'
assert static_parking_site_input.external_identifiers[0]['value'] == 'de:08317:14500_Parent'
assert static_parking_site_input.external_identifiers[0].type == ExternalIdentifierType.DHID
assert static_parking_site_input.external_identifiers[0].value == 'de:08317:14500_Parent'
assert static_parking_site_input.lat == Decimal('48.475546')
assert static_parking_site_input.lon == Decimal('7.947474')

Expand Down

0 comments on commit 011ed3a

Please sign in to comment.