|
| 1 | +import uuid |
| 2 | + |
| 3 | +from rest_framework.test import APITestCase |
| 4 | + |
| 5 | +from openforms.contrib.objects_api.tests.factories import ObjectsAPIGroupConfigFactory |
| 6 | + |
| 7 | +from ..api.serializers import ObjectsAPIOptionsSerializer |
| 8 | + |
| 9 | + |
| 10 | +class OptionValidationTests(APITestCase): |
| 11 | + """ |
| 12 | + Test the serializer used for options validation. |
| 13 | + """ |
| 14 | + |
| 15 | + def test_auth_attribute_not_required(self): |
| 16 | + api_group = ObjectsAPIGroupConfigFactory.create() |
| 17 | + data = { |
| 18 | + "objects_api_group": api_group.pk, |
| 19 | + "objecttype_uuid": uuid.uuid4(), |
| 20 | + "objecttype_version": 3, |
| 21 | + "skip_ownership_check": True, |
| 22 | + "auth_attribute_path": [], |
| 23 | + "variables_mapping": [], |
| 24 | + } |
| 25 | + serializer = ObjectsAPIOptionsSerializer(data=data) |
| 26 | + |
| 27 | + is_valid = serializer.is_valid() |
| 28 | + |
| 29 | + self.assertTrue(is_valid) |
| 30 | + |
| 31 | + def test_auth_attribute_required(self): |
| 32 | + api_group = ObjectsAPIGroupConfigFactory.create() |
| 33 | + data = { |
| 34 | + "objects_api_group": api_group.pk, |
| 35 | + "objecttype_uuid": uuid.uuid4(), |
| 36 | + "objecttype_version": 3, |
| 37 | + "skip_ownership_check": False, |
| 38 | + "auth_attribute_path": [], |
| 39 | + "variables_mapping": [], |
| 40 | + } |
| 41 | + serializer = ObjectsAPIOptionsSerializer(data=data) |
| 42 | + |
| 43 | + is_valid = serializer.is_valid() |
| 44 | + |
| 45 | + self.assertFalse(is_valid) |
| 46 | + error = serializer.errors["auth_attribute_path"][0] |
| 47 | + self.assertEqual(error.code, "empty") |
0 commit comments