Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/import ice track maintenance history #389

Open
wants to merge 78 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
4eeb501
Copied street maintenance model
juuso-j Sep 17, 2024
6b8cf19
Add maintenance to installed apps
juuso-j Sep 17, 2024
8bf546b
Delete as move to maintenace application
juuso-j Sep 17, 2024
7818d81
Fix import
juuso-j Sep 17, 2024
14e1c53
Delete, moved to maintenance app
juuso-j Sep 17, 2024
2a8ae44
Copy tests from street_maintenance app
juuso-j Sep 17, 2024
f61b526
Delete, moved to maintenance applicaiton
juuso-j Sep 18, 2024
1534e76
Delete, moved to maintenance app
juuso-j Sep 18, 2024
f10ca1c
Change street_maintenance to maintenance in DOC_ENDPOINTS
juuso-j Sep 18, 2024
1ff9f2a
Add tests from street_maintenance application
juuso-j Sep 18, 2024
8a6f9e2
Add __init__.py
juuso-j Sep 18, 2024
bd1d664
Add __init__.py
juuso-j Sep 18, 2024
9e4f796
Add tasks.py from street_maintenance application
juuso-j Sep 18, 2024
d52b36e
Add maintenance AppConfig
juuso-j Sep 18, 2024
1f34e1d
Delete all street_maintenance application tables
juuso-j Sep 18, 2024
27ba44b
Add constants.py from street_maintenance
juuso-j Sep 18, 2024
6111a72
Add models from street_maintenance application
juuso-j Sep 18, 2024
fec6ada
Add API from street_maintenace application
juuso-j Sep 18, 2024
0e261ba
Add admin from street_maintenance
juuso-j Sep 18, 2024
e59ba1b
Add street_maintenance urls for backward compatibility
juuso-j Sep 18, 2024
136d5fd
Add maintenance urls
juuso-j Sep 18, 2024
658c34a
Replace street_maintenance logger settings with maintenance
juuso-j Sep 18, 2024
875ba9e
Add README from street_maintenance
juuso-j Sep 18, 2024
76eb781
Add utils.py from street_maintenance applicaiton
juuso-j Sep 18, 2024
177ad0e
Add management commands from street_maintenance application
juuso-j Sep 18, 2024
c728fec
Add specifications
juuso-j Sep 18, 2024
b6d615b
Delete, as moved to maintenance application
juuso-j Sep 18, 2024
a75d5ba
Fix maintenance urls prefix
juuso-j Sep 19, 2024
23670b8
Merge branch 'feature/replace-street-maintenance-app-with-maintenance…
juuso-j Sep 19, 2024
121e21d
Rename file
juuso-j Sep 24, 2024
1993b3a
Add function get_data_layer
juuso-j Sep 25, 2024
5d2f976
Add importer for ski trails
juuso-j Sep 25, 2024
1b707db
Add task to import ski trails
juuso-j Sep 25, 2024
49dd07b
Add fixture data for testing importing of ski trails
juuso-j Sep 25, 2024
f9f39ac
Add ski trails importer tests
juuso-j Sep 25, 2024
145d5cb
Add function to get fixture GDAL data layer
juuso-j Sep 26, 2024
c77fcaf
Add UnitMaintenanceGeometry fixture
juuso-j Sep 26, 2024
1782b2d
Add models for storing Unit maintenance history
juuso-j Sep 26, 2024
d433930
Add Unit fixture
juuso-j Sep 26, 2024
702ea7e
Add ski trails maintenance history importer
juuso-j Sep 26, 2024
039e6ce
Add ski_trails_maintenance_history_mock_data
juuso-j Sep 26, 2024
8bda877
Add ski trail maintenance history importer tests
juuso-j Sep 26, 2024
f6a1287
Add import_ski_trails_maintenance_history task
juuso-j Sep 26, 2024
73b4e98
Add view for UnitMaintenance model
juuso-j Sep 27, 2024
39df1c9
Add fixture now
juuso-j Sep 27, 2024
249da09
Add units fixture
juuso-j Sep 27, 2024
91345a5
Add unit_maintenance_geometries fixture
juuso-j Sep 27, 2024
a2d2af5
Add SKI_TRAILS_DATE_FIELD_FORMAT constants
juuso-j Sep 27, 2024
3cd24f5
Add UnitMaintenance fixtures
juuso-j Sep 27, 2024
c1017a2
Add viewset for UnitMaintenanceGeometry
juuso-j Sep 27, 2024
12277a4
Add serializers for UnitMaintenance and UnitMaintenanceGeometry
juuso-j Sep 27, 2024
676d8c4
Add tests for UnitMaintenanceViewSet
juuso-j Sep 27, 2024
c905115
Add unit_maintenance/ to DOC_ENDPOINTS
juuso-j Sep 27, 2024
e8bc406
Add UnitMaintenance and UnitMaintenanceGeometry
juuso-j Sep 27, 2024
4d79211
Test UnitMaintenanceGeometryViewSet
juuso-j Sep 27, 2024
7436e3a
Add information about ski trails
juuso-j Sep 27, 2024
cabb95f
Conditionally serialize maintenance information to units
juuso-j Sep 27, 2024
e2ab6e0
Serialize maintance information by default
juuso-j Sep 27, 2024
f3d5d2f
Fix SKITRAIL_TO_UNIT_ID_MAPPINGS
juuso-j Sep 30, 2024
6b15e4a
Change STREET_MAINTENANCE_LOG_LEVEL to MAINTENANCE_LOG_LEVEL
juuso-j Oct 1, 2024
acfc917
Merge branch 'feature/replace-street-maintenance-app-with-maintenance…
juuso-j Oct 1, 2024
9ace48f
Fix comment
juuso-j Oct 1, 2024
b56a5c3
Merge branch 'feature/replace-street-maintenance-app-with-maintenance…
juuso-j Oct 1, 2024
b7558aa
Add SKI_TRAILS_URL environment variable
juuso-j Oct 2, 2024
889932a
Add SKI_TRAILS_MAINTENANCE_HISTORY_URL environment variable
juuso-j Oct 2, 2024
21aeab0
Test ski trails geometry change
juuso-j Oct 2, 2024
028788b
Set unit_maintenance deletion to CASCADE
juuso-j Oct 2, 2024
a6c612f
Remove ueless line of code
juuso-j Oct 2, 2024
161b322
Handle geometry change
juuso-j Oct 2, 2024
5dd7cef
Add ICE_TRACKS_MAINTENANCE_HISTORY_URL
juuso-j Oct 10, 2024
7c59085
Set UnitMaintenance maintained_at to nullable
juuso-j Oct 10, 2024
0379060
Add function get_unit_maintenance_instance
juuso-j Oct 10, 2024
5464e44
Add importer for ice tracks maintenance history
juuso-j Oct 10, 2024
e5c71ec
Add task to import ice tracks maintenance history
juuso-j Oct 10, 2024
bb68a69
Add ice tracks maintenance history info
juuso-j Oct 10, 2024
c7e7735
Add caching
juuso-j Oct 10, 2024
1fb8a99
Add fixture data for test import ice tracks maintenance history
juuso-j Oct 10, 2024
a503feb
Test import_ice_tracks_maintenance_history
juuso-j Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Copy tests from street_maintenance app
  • Loading branch information
juuso-j committed Sep 17, 2024
commit 2a8ae446321720e7a53bb1390574501944b0ea1b
Empty file added maintenance/tests/__init__.py
Empty file.
97 changes: 97 additions & 0 deletions maintenance/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from datetime import datetime, timedelta

import pytest
import pytz
from django.contrib.gis.geos import GEOSGeometry, LineString
from munigeo.models import (
AdministrativeDivision,
AdministrativeDivisionGeometry,
AdministrativeDivisionType,
)
from rest_framework.test import APIClient

from mobility_data.tests.conftest import TURKU_WKT
from maintenance.management.commands.constants import (
AURAUS,
INFRAROAD,
KUNTEC,
LIUKKAUDENTORJUNTA,
)
from maintenance.models import DEFAULT_SRID, GeometryHistory

UTC_TIMEZONE = pytz.timezone("UTC")


@pytest.fixture
def api_client():
return APIClient()


@pytest.mark.django_db
@pytest.fixture
def geometry_historys():
now = datetime.now(UTC_TIMEZONE)
geometry = LineString((0, 0), (0, 50), (50, 50), (50, 0), (0, 0), sird=DEFAULT_SRID)
GeometryHistory.objects.create(
timestamp=now,
geometry=geometry,
coordinates=geometry.coords,
provider=INFRAROAD,
events=[AURAUS],
)
GeometryHistory.objects.create(
timestamp=now - timedelta(days=1),
geometry=geometry,
coordinates=geometry.coords,
provider=INFRAROAD,
events=[AURAUS],
)
GeometryHistory.objects.create(
timestamp=now - timedelta(days=2),
geometry=geometry,
coordinates=geometry.coords,
provider=INFRAROAD,
events=[LIUKKAUDENTORJUNTA],
)
GeometryHistory.objects.create(
timestamp=now - timedelta(days=1),
geometry=geometry,
coordinates=geometry.coords,
provider=KUNTEC,
events=[AURAUS],
)
GeometryHistory.objects.create(
timestamp=now - timedelta(days=2),
geometry=geometry,
coordinates=geometry.coords,
provider=KUNTEC,
events=[AURAUS, LIUKKAUDENTORJUNTA],
)
return GeometryHistory.objects.all()

@pytest.mark.django_db
@pytest.fixture
def administrative_division_type():
adm_div_type = AdministrativeDivisionType.objects.create(
id=1, type="muni", name="Municipality"
)
return adm_div_type


@pytest.mark.django_db
@pytest.fixture
def administrative_division(administrative_division_type):
adm_div = AdministrativeDivision.objects.get_or_create(
id=1, name="Turku", origin_id=853, type_id=1
)
return adm_div


@pytest.mark.django_db
@pytest.fixture
def administrative_division_geometry(administrative_division):
turku_multipoly = GEOSGeometry(TURKU_WKT, srid=3067)
adm_div_geom = AdministrativeDivisionGeometry.objects.create(
id=1, division_id=1, boundary=turku_multipoly
)
return adm_div_geom
70 changes: 70 additions & 0 deletions maintenance/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from datetime import timedelta

import pytest
from django.utils import timezone
from rest_framework.reverse import reverse

from maintenance.management.commands.constants import (
AURAUS,
INFRAROAD,
KUNTEC,
LIUKKAUDENTORJUNTA,
START_DATE_TIME_FORMAT,
)


@pytest.mark.django_db
def test_geometry_history_list(api_client, geometry_historys):
url = reverse("maintenance:geometry_history-list")
response = api_client.get(url)
breakpoint()
assert response.json()["count"] == 5


@pytest.mark.django_db
def test_geometry_history_list_provider_parameter(api_client, geometry_historys):
url = reverse("maintenance:geometry_history-list") + f"?provider={KUNTEC}"
response = api_client.get(url)
# Fixture data contains 2 KUNTEC GeometryHistroy rows
assert response.json()["count"] == 2


@pytest.mark.django_db
def test_geometry_history_list_event_parameter(api_client, geometry_historys):
url = reverse("maintenance:geometry_history-list") + f"?event={AURAUS}"
response = api_client.get(url)
# 3 INFRAROAD AURAUS events and 1 KUNTEC
assert response.json()["count"] == 4


@pytest.mark.django_db
def test_geometry_history_list_event_and_provider_parameter(
api_client, geometry_historys
):
url = (
reverse("maintenance:geometry_history-list")
+ f"?provider={KUNTEC}&event={LIUKKAUDENTORJUNTA}"
)
response = api_client.get(url)
assert response.json()["count"] == 1


@pytest.mark.django_db
def test_geometry_history_list_start_date_time_parameter(api_client, geometry_historys):
start_date_time = timezone.now() - timedelta(hours=1)
url = (
reverse("maintenance:geometry_history-list")
+ f"?start_date_time={start_date_time.strftime(START_DATE_TIME_FORMAT)}"
)
response = api_client.get(url)
assert response.json()["count"] == 1
geometry_history = response.json()["results"][0]
assert geometry_history["geometry_type"] == "LineString"
assert geometry_history["provider"] == INFRAROAD
start_date_time = timezone.now() - timedelta(days=1, hours=2)
url = (
reverse("maintenance:geometry_history-list")
+ f"?start_date_time={start_date_time.strftime(START_DATE_TIME_FORMAT)}"
)
response = api_client.get(url)
assert response.json()["count"] == 3
Loading