Skip to content
Snippets Groups Projects

Add tests on json export

1 file
+ 19
0
Compare changes
  • Side-by-side
  • Inline
+ 19
0
@@ -377,6 +377,7 @@ class JSONExportTest(TestCase):
@classmethod
def setUpTestData(cls):
"""Shared set up by initializing admin user."""
cls.admin_user = get_user_model().objects.create(
username="Test Admin User",
email="testadmin@example.com",
@@ -387,6 +388,7 @@ class JSONExportTest(TestCase):
)
def setUp(self):
"""Set up by retrieving json export and initializing data."""
self.client.force_login(self.admin_user)
export_url = reverse(
"admin:ak_json_export", kwargs={"event_slug": self.event_slug}
@@ -416,6 +418,7 @@ class JSONExportTest(TestCase):
self.event = Event.get_by_slug(self.event_slug)
def test_all_aks_exported(self):
"""Test if exported AKs match AKSlots of Event."""
self.assertEqual(
{str(slot.pk) for slot in self.ak_slots},
self.export_aks.keys(),
@@ -423,6 +426,7 @@ class JSONExportTest(TestCase):
)
def test_conformity_to_spec(self):
"""Test if JSON structure and types conform to standard."""
def _check_uniqueness(lst, name: str, key: str | None = "id"):
if key is not None:
lst = [entry[key] for entry in lst]
@@ -579,6 +583,7 @@ class JSONExportTest(TestCase):
)
def test_ak_durations(self):
"""Test if all AK durations are correct."""
for slot in self.ak_slots:
ak = self.export_aks[str(slot.pk)]
@@ -601,6 +606,7 @@ class JSONExportTest(TestCase):
)
def test_ak_conflicts(self):
"""Test if all AK conflicts are correct."""
for slot in self.ak_slots:
ak = self.export_aks[str(slot.pk)]
conflict_slots = self.ak_slots.filter(
@@ -619,6 +625,7 @@ class JSONExportTest(TestCase):
)
def test_ak_depenedencies(self):
"""Test if all AK dependencies are correct."""
for slot in self.ak_slots:
ak = self.export_aks[str(slot.pk)]
dependency_slots = self.ak_slots.filter(
@@ -632,12 +639,14 @@ class JSONExportTest(TestCase):
)
def test_ak_reso(self):
"""Test if resolution intent of AKs is correctly exported."""
for slot in self.ak_slots:
ak = self.export_aks[str(slot.pk)]
self.assertEqual(slot.ak.reso, ak["info"]["reso"])
self.assertEqual(slot.ak.reso, "resolution" in ak["time_constraints"])
def test_ak_info(self):
"""Test if contents of AK info dict is correct."""
for slot in self.ak_slots:
ak = self.export_aks[str(slot.pk)]
self.assertEqual(ak["info"]["name"], slot.ak.name)
@@ -647,6 +656,7 @@ class JSONExportTest(TestCase):
self.assertEqual(ak["info"]["description"], slot.ak.description)
def test_ak_room_constraints(self):
"""Test if AK room constraints are exported as expected."""
for slot in self.ak_slots:
ak = self.export_aks[str(slot.pk)]
requirements = list(slot.ak.requirements.values_list("name", flat=True))
@@ -666,6 +676,7 @@ class JSONExportTest(TestCase):
)
def test_ak_time_constraints(self):
"""Test if AK time constraints are exported as expected."""
for slot in self.ak_slots:
time_constraints = set()
@@ -700,6 +711,7 @@ class JSONExportTest(TestCase):
)
def test_all_rooms_exported(self):
"""Test if exported Rooms match the rooms of Event."""
self.assertEqual(
{str(room.pk) for room in self.rooms},
self.export_rooms.keys(),
@@ -707,16 +719,19 @@ class JSONExportTest(TestCase):
)
def test_room_capacity(self):
"""Test if room capacity is exported correctly."""
for room in self.rooms:
export_room = self.export_rooms[str(room.pk)]
self.assertEqual(room.capacity, export_room["capacity"])
def test_room_info(self):
"""Test if contents of Room info dict is correct."""
for room in self.rooms:
export_room = self.export_rooms[str(room.pk)]
self.assertEqual(room.name, export_room["info"]["name"])
def test_room_timeconstraints(self):
"""Test if Room time constraints are exported as expected."""
for room in self.rooms:
time_constraints = set()
@@ -728,6 +743,7 @@ class JSONExportTest(TestCase):
self.assertEqual(time_constraints, set(export_room["time_constraints"]))
def test_room_fulfilledroomconstraints(self):
"""Test if room constraints fulfilled by Room are correct."""
for room in self.rooms:
# room properties
fulfilled_room_constraints = set(
@@ -809,6 +825,7 @@ class JSONExportTest(TestCase):
return {cat_name: [event_avail] for cat_name in self.category_names}
def test_timeslots_consecutive(self):
"""Test if consecutive timeslots in JSON are in fact consecutive."""
prev_end = None
for timeslot in chain.from_iterable(self.export_dict["timeslots"]["blocks"]):
start, end = self._get_timeslot_start_end(timeslot)
@@ -824,6 +841,7 @@ class JSONExportTest(TestCase):
prev_end = end
def test_block_cover_categories(self):
"""Test if blocks covers all default slot resp. whole event per category."""
export_cat_avails = self._get_cat_availability_in_export()
cat_avails = self._get_cat_availability()
@@ -859,6 +877,7 @@ class JSONExportTest(TestCase):
return timeslot_avail.overlaps(ak_slot_avail, strict=True)
def test_timeslot_fulfilledconstraints(self):
"""Test if fulfilled time constraints by timeslot are as expected."""
cat_avails = self._get_cat_availability()
for timeslot in chain.from_iterable(self.export_dict["timeslots"]["blocks"]):
start, end = self._get_timeslot_start_end(timeslot)
Loading