diff --git a/AKModel/tests/test_json_export.py b/AKModel/tests/test_json_export.py index e8aac8fed36ba4f6917c3e22e87ae2ebec739775..3e14735a6c44220bba64325e941d62dc1599d2bb 100644 --- a/AKModel/tests/test_json_export.py +++ b/AKModel/tests/test_json_export.py @@ -1,26 +1,22 @@ import json import math - from collections import defaultdict from collections.abc import Iterable from datetime import datetime, timedelta from itertools import chain +from pathlib import Path from bs4 import BeautifulSoup from django.contrib.auth import get_user_model from django.test import TestCase from django.urls import reverse +from jsonschema import Draft202012Validator +from jsonschema.exceptions import best_match +from referencing import Registry, Resource from AKModel.availability.models import Availability -from AKModel.models import ( - Event, - AKOwner, - AKCategory, - AK, - Room, - AKSlot, - DefaultSlot, -) +from AKModel.models import AK, AKCategory, AKOwner, AKSlot, DefaultSlot, Event, Room +from AKPlanning import settings class JSONExportTest(TestCase): @@ -44,6 +40,19 @@ class JSONExportTest(TestCase): is_active=True, ) + schema_base_path = Path(settings.BASE_DIR) / "schemas" + resources = [] + for schema_path in schema_base_path.glob("**/*.schema.json"): + with schema_path.open("r") as ff: + res = Resource.from_contents(json.load(ff)) + resources.append((res.id(), res)) + registry = Registry().with_resources(resources) + with (schema_base_path / "solver-input.json").open("r") as ff: + schema = json.load(ff) + cls.json_export_validator = Draft202012Validator( + schema=schema, registry=registry + ) + def setUp(self): self.client.force_login(self.admin_user) self.export_dict = {}