from django.test import TestCase from django.contrib.auth.models import User from django.contrib.gis.geos import Polygon, MultiPolygon from django.utils import timezone from assets.models import ParkingLocation, ParkingSpot, AssetInspection, ParkingSpotInspection, SignPole, SignPanel class ParkingSpotAndInspectionTest(TestCase): def setUp(self): self.user = User.objects.create_user(username="inspector_user", password="password123") poly = Polygon(((648000, 670000), (648010, 670000), (648010, 670010), (648000, 670010), (648000, 670000)), srid=3812) multi_poly = MultiPolygon(poly, srid=3812) self.parking_loc = ParkingLocation.objects.create( code="PARK-LOC-01", name_fr="Zone vélo Grand Place", geom=multi_poly ) self.spot = ParkingSpot.objects.create( code="SPOT-VELO-01", name_fr="Stationnement vélo Grand Place", location=self.parking_loc, spot_type="bicycle", standard_stand_count=3, cargo_stand_count=2, stand_type="mixed", has_scooter_drop_zone=True, scooter_capacity=10, geom=poly ) def test_parking_spot_creation_and_stand_counts(self): self.assertEqual(self.spot.standard_stand_count, 3) self.assertEqual(self.spot.cargo_stand_count, 2) self.assertEqual(self.spot.total_stand_count, 5) self.assertTrue(self.spot.has_scooter_drop_zone) self.assertTrue(self.spot.is_compliant) self.assertEqual(self.spot.inspection_status, "unknown") self.assertIsNotNone(self.spot.geojson) def test_parking_spot_inspection_updates_asset(self): # Using specialized ParkingSpotInspection model inspection = ParkingSpotInspection.objects.create( asset=self.spot, inspector=self.user, inspection_date=timezone.now(), result_status="updated", verified_standard_stand_count=4, verified_cargo_stand_count=3, verified_has_scooter_drop_zone=True, verified_marking_quality="good", apply_changes_to_asset=True, notes="Ajout récent de 1 arceau classique et 1 arceau cargo" ) self.spot.refresh_from_db() self.assertEqual(self.spot.standard_stand_count, 4) self.assertEqual(self.spot.cargo_stand_count, 3) self.assertEqual(self.spot.total_stand_count, 7) self.assertEqual(self.spot.validation_status, "validated") self.assertEqual(self.spot.inspection_status, "updated") self.assertIsNotNone(self.spot.last_inspection_date) self.assertTrue(self.spot.is_compliant) def test_generic_asset_inspection_non_compliance(self): # Generic inspection works for any asset inspection = AssetInspection.objects.create( asset=self.spot, inspector=self.user, inspection_date=timezone.now(), result_status="non_compliant", notes="Arceau cargo tordu suite à un choc de livraison", apply_changes_to_asset=True ) self.spot.refresh_from_db() self.assertFalse(self.spot.is_compliant) self.assertEqual(self.spot.inspection_status, "non_compliant") self.assertEqual(self.spot.non_compliance_reason, "Arceau cargo tordu suite à un choc de livraison")