Skip to content

Commit

Permalink
Add parking garage importer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juuso-j committed May 3, 2024
1 parent 37103a7 commit d912edb
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mobility_data/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ def streets():
name_sv="Bangårdsgatan",
municipality_id="turku",
)
Street.objects.create(
name="Juhana Herttuan puistokatu",
name_fi="Juhana Herttuan puistokatu",
name_sv="Hertig Johans parkgata",
name_en="Juhana Herttuan puistokatu",
municipality_id="turku",
)
return Street.objects.all()


Expand Down
3 changes: 3 additions & 0 deletions mobility_data/tests/data/parkkihallit_fixtures.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Nimi;Osoite;N;E;Pysäköintipaikat;Invapaikat;Sähkölatauspaikat;Palvelut;Palvelut (ru);Palvelut (eng);Huom;Huom (ru);Huom (eng);Linkki sivuille
Auriga;Juhana Herttuan puistokatu 21;6703305;23457449;330;2;2 x Type 2 22 kW;Apuvirta, hissi, liikkumisesteisen pysäköintipaikka, sähköauton latauspiste;Elbilsladdning, hiss, parkeringsplats för funktionshindrade, startkablar;Disabled parking, elevator, EV charging, jump leads;;;;https://www.aimopark.fi/kaupungit/turku/auriga-/
Hansakortteli;Kristiinankatu 11;6704479;23459433;162;2;2 x Type 2 11kW, 2 x CSS 90kW;Apuvirta, hissi, kameratunnistus, kengänkiillotin, liikkumisesteisen pysäköintipaikka, ostoskärryt, rengaspumppu, sateenvarjon lainaus, sähköauton latauspiste, videovalvonta, yövartiointi;Elbilsladdning, hiss, kameraparkering, kameraövervakat, kundvagnar, nattlig övervakning, paraply, parkeringsplats för funktionshindrade, skoputs, startkablar, tryckluft;Automatic number-plate recognition (ANPR), CCTV, disabled parking, elevator, EV charging, jump leads, shoe polisher, shopping trolley, surveillance at night, tyre pump, umbrella hire;Parkkihallin omalla sivulla ja aimoparkin latausverkostokartalla eriävää tietoa latauspisteistä;Information angående elbilsladdning på parkeringshusets hemsida strider mot informationen på aimoparks laddningsnätverk karta;Information regarding EV charging on the parking garage's website conflicts with the information on aimopark's charging network map;https://www.aimopark.fi/kaupungit/turku/hansakortteli/
69 changes: 69 additions & 0 deletions mobility_data/tests/test_import_parking_garages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from unittest.mock import patch

import pytest

from mobility_data.importers.utils import (
get_content_type_config,
get_or_create_content_type_from_config,
get_root_dir,
save_to_database,
)
from mobility_data.models import ContentType, MobileUnit


@pytest.mark.django_db
@patch("mobility_data.importers.parking_garages.get_full_csv_file_name")
def test_import_parking_garages(
get_full_csv_file_name_mock,
municipalities,
administrative_division_type,
administrative_division,
administrative_division_geometry,
streets,
address,
):
from mobility_data.importers.parking_garages import (
CONTENT_TYPE_NAME,
get_parking_garage_objects,
)

file_name = f"{get_root_dir()}/mobility_data/tests/data/parkkihallit_fixtures.csv"
get_full_csv_file_name_mock.return_value = file_name
content_type = get_or_create_content_type_from_config(CONTENT_TYPE_NAME)
objects = get_parking_garage_objects()
num_created, num_deleted = save_to_database(objects, content_type)
assert num_created == 2
assert num_deleted == 0
assert ContentType.objects.filter(type_name=CONTENT_TYPE_NAME).count() == 1
assert (
MobileUnit.objects.filter(content_types__type_name=CONTENT_TYPE_NAME).count()
== 2
)
config = get_content_type_config(CONTENT_TYPE_NAME)
content_type = ContentType.objects.get(type_name=CONTENT_TYPE_NAME)
content_type.name_fi = config["name"]["fi"]
content_type.name_sv = config["name"]["sv"]
content_type.name_en = config["name"]["en"]

auriga = MobileUnit.objects.get(name="Auriga")
assert auriga.name_sv == "Auriga"
assert auriga.name_en == "Auriga"
assert auriga.address_fi == "Juhana Herttuan puistokatu 21"
assert auriga.address_sv == "Hertig Johans parkgata 21"
assert auriga.address_en == "Juhana Herttuan puistokatu 21"
assert auriga.municipality.name == "Turku"
assert auriga.extra["parking_spaces"] == 330
assert auriga.extra["disabled_spaces"] == 2
assert auriga.extra["charging_stations"] == "2 x Type 2 22 kW"
assert (
auriga.extra["services"]["fi"]
== "Apuvirta, hissi, liikkumisesteisen pysäköintipaikka, sähköauton latauspiste"
)
assert (
auriga.extra["services"]["sv"]
== "Elbilsladdning, hiss, parkeringsplats för funktionshindrade, startkablar"
)
assert (
auriga.extra["services"]["en"]
== "Disabled parking, elevator, EV charging, jump leads"
)

0 comments on commit d912edb

Please sign in to comment.