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

Remove tests covered by schema

parent 3c7873e5
Branches
No related tags found
1 merge request!268Merge fork for interoperability of KoMa solver
...@@ -128,204 +128,41 @@ class JSONExportTest(TestCase): ...@@ -128,204 +128,41 @@ class JSONExportTest(TestCase):
if contained_type in {str, int}: if contained_type in {str, int}:
self._check_uniqueness(lst, name, key=None) self._check_uniqueness(lst, name, key=None)
def test_ak_conformity_to_spec(self): def test_conformity_to_schema(self):
"""Test if AK JSON structure and types conform to standard.""" """Test if JSON structure and types conform to schema."""
for event in Event.objects.all(): for event in Event.objects.all():
with self.subTest(event=event): with self.subTest(event=event):
self.set_up_event(event=event) self.set_up_event(event=event)
self._check_uniqueness(self.export_dict["aks"], "AK") errors = list(self.json_export_validator.iter_errors(self.export_dict))
for ak in self.export_dict["aks"]: msg = "" if not errors else best_match(errors).message
item = f"AK {ak['id']}" self.assertFalse(errors, msg)
self.assertEqual(
ak.keys(),
{
"id",
"duration",
"properties",
"room_constraints",
"time_constraints",
"info",
},
f"{item} keys not as expected",
)
self.assertEqual(
ak["info"].keys(),
{
"name",
"head",
"description",
"reso",
"duration_in_hours",
"django_ak_id",
"types",
},
f"{item} info keys not as expected",
)
self.assertEqual(
ak["properties"].keys(),
{"conflicts", "dependencies"},
f"{item} properties keys not as expected",
)
self._check_type(ak["id"], int, "id", item=item)
self._check_type(ak["duration"], int, "duration", item=item)
self._check_type(ak["info"]["name"], str, "info/name", item=item)
self._check_type(ak["info"]["head"], str, "info/head", item=item)
self._check_type(
ak["info"]["description"], str, "info/description", item=item
)
self._check_type(ak["info"]["reso"], bool, "info/reso", item=item)
self._check_type(
ak["info"]["duration_in_hours"],
float,
"info/duration_in_hours",
item=item,
)
self._check_type(
ak["info"]["django_ak_id"],
int,
"info/django_ak_id",
item=item,
)
self._check_lst( def test_id_uniqueness(self):
ak["properties"]["conflicts"], """Test if objects are only exported once."""
"conflicts",
item=item,
contained_type=int,
)
self._check_lst(
ak["properties"]["dependencies"],
"dependencies",
item=item,
contained_type=int,
)
self._check_lst(
ak["time_constraints"], "time_constraints", item=item
)
self._check_lst(
ak["room_constraints"], "room_constraints", item=item
)
def test_room_conformity_to_spec(self):
"""Test if Room JSON structure and types conform to standard."""
for event in Event.objects.all(): for event in Event.objects.all():
with self.subTest(event=event): with self.subTest(event=event):
self.set_up_event(event=event) self.set_up_event(event=event)
self._check_uniqueness(self.export_dict["rooms"], "Room") self._check_uniqueness(self.export_dict["aks"], "AKs")
for room in self.export_dict["rooms"]: self._check_uniqueness(self.export_dict["rooms"], "Rooms")
item = f"Room {room['id']}" self._check_uniqueness(self.export_dict["participants"], "Participants")
self.assertEqual(
room.keys(),
{
"id",
"info",
"capacity",
"fulfilled_room_constraints",
"time_constraints",
},
f"{item} keys not as expected",
)
self.assertEqual(
room["info"].keys(),
{"name"},
f"{item} info keys not as expected",
)
self._check_type(room["id"], int, "id", item=item)
self._check_type(room["capacity"], int, "capacity", item=item)
self._check_type(room["info"]["name"], str, "info/name", item=item)
self.assertTrue(
room["capacity"] > 0 or room["capacity"] == -1,
"invalid room capacity",
)
self._check_lst(
room["time_constraints"], "time_constraints", item=item
)
self._check_lst(
room["fulfilled_room_constraints"],
"fulfilled_room_constraints",
item=item,
)
def test_timeslots_conformity_to_spec(self):
"""Test if Timeslots JSON structure and types conform to standard."""
for event in Event.objects.all():
with self.subTest(event=event):
self.set_up_event(event=event)
self._check_uniqueness( self._check_uniqueness(
chain.from_iterable(self.export_dict["timeslots"]["blocks"]), chain.from_iterable(self.export_dict["timeslots"]["blocks"]),
"Timeslots", "Timeslots",
) )
item = "timeslots"
self.assertEqual(
self.export_dict["timeslots"].keys(),
{"info", "blocks"},
"timeslot keys not as expected",
)
self.assertEqual(
self.export_dict["timeslots"]["info"].keys(),
{"duration", "blocknames"},
"timeslot info keys not as expected",
)
self._check_type(
self.export_dict["timeslots"]["info"]["duration"],
float,
"info/duration",
item=item,
)
self._check_lst(
self.export_dict["timeslots"]["info"]["blocknames"],
"info/blocknames",
item=item,
contained_type=list,
)
for blockname in self.export_dict["timeslots"]["info"]["blocknames"]:
self.assertEqual(len(blockname), 2)
self._check_lst(
blockname,
"info/blocknames/entry",
item=item,
contained_type=str,
)
self._check_lst( def test_timeslot_ids_consecutive(self):
self.export_dict["timeslots"]["blocks"], """Test if Timeslots ids are chronologically consecutive."""
"blocks", for event in Event.objects.all():
item=item, with self.subTest(event=event):
contained_type=list, self.set_up_event(event=event)
)
prev_id = None prev_id = None
for timeslot in chain.from_iterable( for timeslot in chain.from_iterable(
self.export_dict["timeslots"]["blocks"] self.export_dict["timeslots"]["blocks"]
): ):
item = f"timeslot {timeslot['id']}"
self.assertEqual(
timeslot.keys(),
{"id", "info", "fulfilled_time_constraints"},
f"{item} keys not as expected",
)
self.assertEqual(
timeslot["info"].keys(),
{"start", "end"},
f"{item} info keys not as expected",
)
self._check_type(timeslot["id"], int, "id", item=item)
self._check_type(
timeslot["info"]["start"], str, "info/start", item=item
)
self._check_lst(
timeslot["fulfilled_time_constraints"],
"fulfilled_time_constraints",
item=item,
)
if prev_id is not None: if prev_id is not None:
self.assertLess( self.assertLess(
prev_id, prev_id,
...@@ -360,8 +197,6 @@ class JSONExportTest(TestCase): ...@@ -360,8 +197,6 @@ class JSONExportTest(TestCase):
getattr(self.event, attr_field), self.export_dict["info"][attr] getattr(self.event, attr_field), self.export_dict["info"][attr]
) )
self._check_uniqueness(self.export_dict["participants"], "Participants")
def test_ak_durations(self): def test_ak_durations(self):
"""Test if all AK durations are correct.""" """Test if all AK durations are correct."""
for event in Event.objects.all(): for event in Event.objects.all():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment