-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ [#4650] Add tests for optional ownership check
* Added tests for configuration validation * Added tests for runtime behaviour
- Loading branch information
1 parent
671145c
commit b8d142b
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/openforms/prefill/contrib/objects_api/tests/test_options_validation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import uuid | ||
|
||
from rest_framework.test import APITestCase | ||
|
||
from openforms.contrib.objects_api.tests.factories import ObjectsAPIGroupConfigFactory | ||
|
||
from ..api.serializers import ObjectsAPIOptionsSerializer | ||
|
||
|
||
class OptionValidationTests(APITestCase): | ||
""" | ||
Test the serializer used for options validation. | ||
""" | ||
|
||
def test_auth_attribute_not_required(self): | ||
api_group = ObjectsAPIGroupConfigFactory.create() | ||
data = { | ||
"objects_api_group": api_group.pk, | ||
"objecttype_uuid": uuid.uuid4(), | ||
"objecttype_version": 3, | ||
"skip_ownership_check": True, | ||
"auth_attribute_path": [], | ||
"variables_mapping": [], | ||
} | ||
serializer = ObjectsAPIOptionsSerializer(data=data) | ||
|
||
is_valid = serializer.is_valid() | ||
|
||
self.assertTrue(is_valid) | ||
|
||
def test_auth_attribute_required(self): | ||
api_group = ObjectsAPIGroupConfigFactory.create() | ||
data = { | ||
"objects_api_group": api_group.pk, | ||
"objecttype_uuid": uuid.uuid4(), | ||
"objecttype_version": 3, | ||
"skip_ownership_check": False, | ||
"auth_attribute_path": [], | ||
"variables_mapping": [], | ||
} | ||
serializer = ObjectsAPIOptionsSerializer(data=data) | ||
|
||
is_valid = serializer.is_valid() | ||
|
||
self.assertFalse(is_valid) | ||
error = serializer.errors["auth_attribute_path"][0] | ||
self.assertEqual(error.code, "empty") |