Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mhieta committed Dec 14, 2023
2 parents 4d6e3a3 + ff3ef42 commit d25331f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
10 changes: 7 additions & 3 deletions parking_permits/services/dvv.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,14 @@ def format_address(address_data) -> DvvAddressInfo:
street_name, street_number, apartment = parse_street_data(
address_data["LahiosoiteS"]
)
street_name_sv, street_number, apartment_sv = parse_street_data(
address_data["LahiosoiteR"]
)

if swedish_address := address_data.get("LahiosoiteR"):
street_name_sv, __, apartment_sv = parse_street_data(swedish_address)
else:
street_name_sv, apartment_sv = "", ""

address_detail = get_address_details(street_name, street_number)

try:
zone = ParkingZone.objects.get_for_location(address_detail["location"])
except ParkingZone.DoesNotExist:
Expand Down
20 changes: 20 additions & 0 deletions parking_permits/tests/services/test_dvv.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ def test_get_customer_info_addresses_not_in_helsinki(
self.assertEqual(customer["other_address"], None)
self.assertEqual(customer["other_address_apartment"], "")

@patch("parking_permits.services.dvv.get_address_details")
@patch("requests.post")
def test_mock_customer_info_null_swedish_address(
self, mock_post, mock_get_address_details
):
mock_info = self.get_mock_info()
mock_info["Henkilo"]["VakinainenKotimainenLahiosoite"]["LahiosoiteR"] = None

mock_post.return_value = self.MockResponse(data=mock_info)
mock_get_address_details.return_value = {"location": generate_multi_polygon()}
customer = get_person_info("12345")
self.assertEqual(customer["first_name"], "Heikki")
self.assertEqual(customer["last_name"], "Häkkinen")
self.assertEqual(customer["primary_address"]["street_name"], "Käsivoide")
self.assertEqual(customer["primary_address"]["street_name_sv"], "")
self.assertEqual(customer["primary_address"]["street_number"], "1")
self.assertEqual(customer["primary_address"]["postal_code"], "10001")
self.assertEqual(customer["primary_address"]["city"], "Helsinki")
self.assertEqual(customer["primary_address_apartment"], "A6")

def get_mock_info(self, **kwargs):
return {
"Henkilo": {
Expand Down

0 comments on commit d25331f

Please sign in to comment.