Skip to content
Snippets Groups Projects
Commit 3b3bdfe7 authored by Felix Blanke's avatar Felix Blanke
Browse files

Add docstrings

parent a359106b
No related branches found
No related tags found
1 merge request!11Add tests on json export
Pipeline #269735 failed
This commit is part of merge request !11. Comments created here will be created in the context of that merge request.
...@@ -377,6 +377,7 @@ class JSONExportTest(TestCase): ...@@ -377,6 +377,7 @@ class JSONExportTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
"""Shared set up by initializing admin user."""
cls.admin_user = get_user_model().objects.create( cls.admin_user = get_user_model().objects.create(
username="Test Admin User", username="Test Admin User",
email="testadmin@example.com", email="testadmin@example.com",
...@@ -387,6 +388,7 @@ class JSONExportTest(TestCase): ...@@ -387,6 +388,7 @@ class JSONExportTest(TestCase):
) )
def setUp(self): def setUp(self):
"""Set up by retrieving json export and initializing data."""
self.client.force_login(self.admin_user) self.client.force_login(self.admin_user)
export_url = reverse( export_url = reverse(
"admin:ak_json_export", kwargs={"event_slug": self.event_slug} "admin:ak_json_export", kwargs={"event_slug": self.event_slug}
...@@ -416,6 +418,7 @@ class JSONExportTest(TestCase): ...@@ -416,6 +418,7 @@ class JSONExportTest(TestCase):
self.event = Event.get_by_slug(self.event_slug) self.event = Event.get_by_slug(self.event_slug)
def test_all_aks_exported(self): def test_all_aks_exported(self):
"""Test if exported AKs match AKSlots of Event."""
self.assertEqual( self.assertEqual(
{str(slot.pk) for slot in self.ak_slots}, {str(slot.pk) for slot in self.ak_slots},
self.export_aks.keys(), self.export_aks.keys(),
...@@ -423,6 +426,7 @@ class JSONExportTest(TestCase): ...@@ -423,6 +426,7 @@ class JSONExportTest(TestCase):
) )
def test_conformity_to_spec(self): 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"): def _check_uniqueness(lst, name: str, key: str | None = "id"):
if key is not None: if key is not None:
lst = [entry[key] for entry in lst] lst = [entry[key] for entry in lst]
...@@ -579,6 +583,7 @@ class JSONExportTest(TestCase): ...@@ -579,6 +583,7 @@ class JSONExportTest(TestCase):
) )
def test_ak_durations(self): def test_ak_durations(self):
"""Test if all AK durations are correct."""
for slot in self.ak_slots: for slot in self.ak_slots:
ak = self.export_aks[str(slot.pk)] ak = self.export_aks[str(slot.pk)]
...@@ -601,6 +606,7 @@ class JSONExportTest(TestCase): ...@@ -601,6 +606,7 @@ class JSONExportTest(TestCase):
) )
def test_ak_conflicts(self): def test_ak_conflicts(self):
"""Test if all AK conflicts are correct."""
for slot in self.ak_slots: for slot in self.ak_slots:
ak = self.export_aks[str(slot.pk)] ak = self.export_aks[str(slot.pk)]
conflict_slots = self.ak_slots.filter( conflict_slots = self.ak_slots.filter(
...@@ -619,6 +625,7 @@ class JSONExportTest(TestCase): ...@@ -619,6 +625,7 @@ class JSONExportTest(TestCase):
) )
def test_ak_depenedencies(self): def test_ak_depenedencies(self):
"""Test if all AK dependencies are correct."""
for slot in self.ak_slots: for slot in self.ak_slots:
ak = self.export_aks[str(slot.pk)] ak = self.export_aks[str(slot.pk)]
dependency_slots = self.ak_slots.filter( dependency_slots = self.ak_slots.filter(
...@@ -632,12 +639,14 @@ class JSONExportTest(TestCase): ...@@ -632,12 +639,14 @@ class JSONExportTest(TestCase):
) )
def test_ak_reso(self): def test_ak_reso(self):
"""Test if resolution intent of AKs is correctly exported."""
for slot in self.ak_slots: for slot in self.ak_slots:
ak = self.export_aks[str(slot.pk)] ak = self.export_aks[str(slot.pk)]
self.assertEqual(slot.ak.reso, ak["info"]["reso"]) self.assertEqual(slot.ak.reso, ak["info"]["reso"])
self.assertEqual(slot.ak.reso, "resolution" in ak["time_constraints"]) self.assertEqual(slot.ak.reso, "resolution" in ak["time_constraints"])
def test_ak_info(self): def test_ak_info(self):
"""Test if contents of AK info dict is correct."""
for slot in self.ak_slots: for slot in self.ak_slots:
ak = self.export_aks[str(slot.pk)] ak = self.export_aks[str(slot.pk)]
self.assertEqual(ak["info"]["name"], slot.ak.name) self.assertEqual(ak["info"]["name"], slot.ak.name)
...@@ -647,6 +656,7 @@ class JSONExportTest(TestCase): ...@@ -647,6 +656,7 @@ class JSONExportTest(TestCase):
self.assertEqual(ak["info"]["description"], slot.ak.description) self.assertEqual(ak["info"]["description"], slot.ak.description)
def test_ak_room_constraints(self): def test_ak_room_constraints(self):
"""Test if AK room constraints are exported as expected."""
for slot in self.ak_slots: for slot in self.ak_slots:
ak = self.export_aks[str(slot.pk)] ak = self.export_aks[str(slot.pk)]
requirements = list(slot.ak.requirements.values_list("name", flat=True)) requirements = list(slot.ak.requirements.values_list("name", flat=True))
...@@ -666,6 +676,7 @@ class JSONExportTest(TestCase): ...@@ -666,6 +676,7 @@ class JSONExportTest(TestCase):
) )
def test_ak_time_constraints(self): def test_ak_time_constraints(self):
"""Test if AK time constraints are exported as expected."""
for slot in self.ak_slots: for slot in self.ak_slots:
time_constraints = set() time_constraints = set()
...@@ -700,6 +711,7 @@ class JSONExportTest(TestCase): ...@@ -700,6 +711,7 @@ class JSONExportTest(TestCase):
) )
def test_all_rooms_exported(self): def test_all_rooms_exported(self):
"""Test if exported Rooms match the rooms of Event."""
self.assertEqual( self.assertEqual(
{str(room.pk) for room in self.rooms}, {str(room.pk) for room in self.rooms},
self.export_rooms.keys(), self.export_rooms.keys(),
...@@ -707,16 +719,19 @@ class JSONExportTest(TestCase): ...@@ -707,16 +719,19 @@ class JSONExportTest(TestCase):
) )
def test_room_capacity(self): def test_room_capacity(self):
"""Test if room capacity is exported correctly."""
for room in self.rooms: for room in self.rooms:
export_room = self.export_rooms[str(room.pk)] export_room = self.export_rooms[str(room.pk)]
self.assertEqual(room.capacity, export_room["capacity"]) self.assertEqual(room.capacity, export_room["capacity"])
def test_room_info(self): def test_room_info(self):
"""Test if contents of Room info dict is correct."""
for room in self.rooms: for room in self.rooms:
export_room = self.export_rooms[str(room.pk)] export_room = self.export_rooms[str(room.pk)]
self.assertEqual(room.name, export_room["info"]["name"]) self.assertEqual(room.name, export_room["info"]["name"])
def test_room_timeconstraints(self): def test_room_timeconstraints(self):
"""Test if Room time constraints are exported as expected."""
for room in self.rooms: for room in self.rooms:
time_constraints = set() time_constraints = set()
...@@ -728,6 +743,7 @@ class JSONExportTest(TestCase): ...@@ -728,6 +743,7 @@ class JSONExportTest(TestCase):
self.assertEqual(time_constraints, set(export_room["time_constraints"])) self.assertEqual(time_constraints, set(export_room["time_constraints"]))
def test_room_fulfilledroomconstraints(self): def test_room_fulfilledroomconstraints(self):
"""Test if room constraints fulfilled by Room are correct."""
for room in self.rooms: for room in self.rooms:
# room properties # room properties
fulfilled_room_constraints = set( fulfilled_room_constraints = set(
...@@ -809,6 +825,7 @@ class JSONExportTest(TestCase): ...@@ -809,6 +825,7 @@ class JSONExportTest(TestCase):
return {cat_name: [event_avail] for cat_name in self.category_names} return {cat_name: [event_avail] for cat_name in self.category_names}
def test_timeslots_consecutive(self): def test_timeslots_consecutive(self):
"""Test if consecutive timeslots in JSON are in fact consecutive."""
prev_end = None prev_end = None
for timeslot in chain.from_iterable(self.export_dict["timeslots"]["blocks"]): for timeslot in chain.from_iterable(self.export_dict["timeslots"]["blocks"]):
start, end = self._get_timeslot_start_end(timeslot) start, end = self._get_timeslot_start_end(timeslot)
...@@ -824,6 +841,7 @@ class JSONExportTest(TestCase): ...@@ -824,6 +841,7 @@ class JSONExportTest(TestCase):
prev_end = end prev_end = end
def test_block_cover_categories(self): 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() export_cat_avails = self._get_cat_availability_in_export()
cat_avails = self._get_cat_availability() cat_avails = self._get_cat_availability()
...@@ -859,6 +877,7 @@ class JSONExportTest(TestCase): ...@@ -859,6 +877,7 @@ class JSONExportTest(TestCase):
return timeslot_avail.overlaps(ak_slot_avail, strict=True) return timeslot_avail.overlaps(ak_slot_avail, strict=True)
def test_timeslot_fulfilledconstraints(self): def test_timeslot_fulfilledconstraints(self):
"""Test if fulfilled time constraints by timeslot are as expected."""
cat_avails = self._get_cat_availability() cat_avails = self._get_cat_availability()
for timeslot in chain.from_iterable(self.export_dict["timeslots"]["blocks"]): for timeslot in chain.from_iterable(self.export_dict["timeslots"]["blocks"]):
start, end = self._get_timeslot_start_end(timeslot) start, end = self._get_timeslot_start_end(timeslot)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment