loko/streetup/authorizations/tests.py
2026-07-22 14:48:40 +02:00

49 lines
1.8 KiB
Python

from django.test import TestCase
from django.utils import timezone
from django.contrib.gis.geos import MultiPolygon, Polygon
from datetime import datetime
from authorizations.models import RoadAuthorization, RoadAuthorizationDate
class RoadAuthorizationDateTest(TestCase):
def setUp(self):
# Create a simple MultiPolygon
poly = Polygon(((0, 0), (0, 1), (1, 1), (1, 0), (0, 0)))
multipoly = MultiPolygon(poly, srid=4326)
self.auth = RoadAuthorization.objects.create(
type=2,
description="Test authorization",
applicant_name="John Doe",
applicant_email="john@example.com",
applicant_address="123 Main St",
location="Brussels",
geom=multipoly
)
def test_str_representation_both_dates(self):
begin = timezone.make_aware(datetime(2026, 6, 29, 10, 0))
end = timezone.make_aware(datetime(2026, 6, 29, 18, 0))
auth_date = RoadAuthorizationDate(
authorization=self.auth,
begin_date=begin,
end_date=end
)
self.assertEqual(str(auth_date), "29/06/2026 10:00 → 29/06/2026 18:00")
def test_str_representation_null_end_date(self):
begin = timezone.make_aware(datetime(2026, 6, 29, 10, 0))
auth_date = RoadAuthorizationDate(
authorization=self.auth,
begin_date=begin,
end_date=None
)
self.assertEqual(str(auth_date), "29/06/2026 10:00 → —")
def test_str_representation_null_begin_date(self):
end = timezone.make_aware(datetime(2026, 6, 29, 18, 0))
auth_date = RoadAuthorizationDate(
authorization=self.auth,
begin_date=None,
end_date=end
)
self.assertEqual(str(auth_date), "— → 29/06/2026 18:00")