Skip to content

Commit

Permalink
✅ [#4980] Update tests
Browse files Browse the repository at this point in the history
In the JSON dump docker app, explicitly load the received data before sending again. This prevents the data from being interpreted as a string instead of a JSON object.
  • Loading branch information
viktorvanwijk committed Jan 22, 2025
1 parent 086a470 commit 3be5893
Show file tree
Hide file tree
Showing 26 changed files with 963 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def get_initial_value(
@staticmethod
def as_json_schema():
# NOTE: this has been made 'vague' on purpose, see the comment on AuthContext.
return {"title": "Authentication summary", "type": "object"}
return {
"title": "Authentication summary",
"type": "object",
"additionalProperties": True,
}


@register_static_variable("auth_type")
Expand Down Expand Up @@ -293,7 +297,7 @@ def as_json_schema():
"title": "Legal subject authentication type",
"description": (
"Authentication type of the legal subject (mandated to act on behalf "
"of the representee)",
"of the representee)"
),
"type": "string",
}
Expand All @@ -316,7 +320,7 @@ def as_json_schema():
"title": "Legal subject authentication identifier",
"description": (
"Authentication identifier of the legal subject (mandated to act on "
"behalf of the representee)",
"behalf of the representee)"
),
"type": "string",
}
Expand Down
102 changes: 102 additions & 0 deletions src/openforms/authentication/tests/test_static_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,28 @@

from django.test import TestCase

from jsonschema.validators import Draft202012Validator

from openforms.authentication.constants import AuthAttribute
from openforms.authentication.static_variables.static_variables import (
Auth,
AuthBSN,
AuthContext,
AuthContextActingSubjectIdentifier,
AuthContextActingSubjectIdentifierType,
AuthContextBranchNumber,
AuthContextLegalSubjectIdentifier,
AuthContextLegalSubjectIdentifierType,
AuthContextLOA,
AuthContextRepresenteeIdentifier,
AuthContextRepresenteeType,
AuthContextSource,
AuthKvK,
AuthPseudo,
AuthType,
LanguageCode,
SubmissionID,
)
from openforms.authentication.tests.factories import AuthInfoFactory
from openforms.submissions.tests.factories import SubmissionFactory
from openforms.variables.service import get_static_variables
Expand Down Expand Up @@ -134,3 +155,84 @@ def test_branch_number_variable(self):
}

self.assertEqual(static_data["auth_context_branch_number"], expected)


class StaticVariableValidJsonSchemaTests(TestCase):

validator = Draft202012Validator

def check_schema(self, properties):
schema = {
"$schema": self.validator.META_SCHEMA["$id"],
**properties,
}

self.validator.check_schema(schema)

def test_submission_id(self):
schema = SubmissionID.as_json_schema()
self.check_schema(schema)

def test_language_code(self):
schema = LanguageCode.as_json_schema()
self.check_schema(schema)

def test_auth(self):
schema = Auth.as_json_schema()
self.check_schema(schema)

def test_auth_type(self):
schema = AuthType.as_json_schema()
self.check_schema(schema)

def test_auth_bsn(self):
schema = AuthBSN.as_json_schema()
self.check_schema(schema)

def test_auth_kvk(self):
schema = AuthKvK.as_json_schema()
self.check_schema(schema)

def test_auth_pseudo(self):
schema = AuthPseudo.as_json_schema()
self.check_schema(schema)

def test_auth_context(self):
schema = AuthContext.as_json_schema()
self.check_schema(schema)

def test_auth_context_source(self):
schema = AuthContextSource.as_json_schema()
self.check_schema(schema)

def test_auth_context_loa(self):
schema = AuthContextLOA.as_json_schema()
self.check_schema(schema)

def test_auth_context_representee_type(self):
schema = AuthContextRepresenteeType.as_json_schema()
self.check_schema(schema)

def test_auth_context_representee_identifier(self):
schema = AuthContextRepresenteeIdentifier.as_json_schema()
self.check_schema(schema)

def test_auth_context_legal_subject_identifier_type(self):
schema = AuthContextLegalSubjectIdentifierType.as_json_schema()
self.check_schema(schema)

def test_auth_context_legal_subject_identifier(self):
schema = AuthContextLegalSubjectIdentifier.as_json_schema()
self.check_schema(schema)

def test_auth_context_branch_number(self):
schema = AuthContextBranchNumber.as_json_schema()
self.check_schema(schema)

def test_auth_context_acting_subject_identifier_type(self):
schema = AuthContextActingSubjectIdentifierType.as_json_schema()
self.check_schema(schema)

def test_auth_context_acting_subject_identifier(self):
schema = AuthContextActingSubjectIdentifier.as_json_schema()
self.check_schema(schema)
1 change: 1 addition & 0 deletions src/openforms/formio/components/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from ..typing import Component


def _normalize_pattern(pattern: str) -> str:
"""
Normalize a regex pattern so that it matches from beginning to the end of the value.
Expand Down
36 changes: 23 additions & 13 deletions src/openforms/formio/tests/test_component_json_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from openforms.formio.typing import (
AddressNLComponent,
Component,
ContentComponent,
DateComponent,
DatetimeComponent,
EditGridComponent,
Expand All @@ -45,7 +46,7 @@
)


class ComponentValidJsonSchemaTestsMixin(TestCase):
class ComponentValidJsonSchemaTests(TestCase):
validator = Draft202012Validator

def check_schema(self, properties):
Expand Down Expand Up @@ -80,7 +81,7 @@ def test_checkbox(self):

def test_content(self):
component_class = Content
component = {
component: ContentComponent = {
"label": "Content",
"key": "content",
"html": "ASDF",
Expand Down Expand Up @@ -303,13 +304,14 @@ def test_postcode(self):
class RadioTests(TestCase):

def test_manual_data_source(self):
component = {
component: RadioComponent = {
"label": "Radio label",
"key": "radio",
"values": [
{"label": "A", "value": "a"},
{"label": "B", "value": "b"},
],
"type": "radio",
}

expected_schema = {
Expand All @@ -321,25 +323,25 @@ def test_manual_data_source(self):
self.assertEqual(expected_schema, schema)

def test_data_source_is_another_form_variable(self):
component = {
component: RadioComponent = {
"label": "Radio label",
"key": "radio",
"values": [
{"label": "", "value": ""},
],
"openForms": {"dataSrc": "variable"},
"type": "radio",
}

expected_schema = {"title": "Radio label", "type": "string"}
schema = Radio.as_json_schema(component)
self.assertEqual(expected_schema, schema)



class SelectTests(TestCase):

def test_manual_data_source(self):
component = {
component: SelectComponent = {
"label": "Select label",
"key": "select",
"data": {
Expand All @@ -353,7 +355,9 @@ def test_manual_data_source(self):

with self.subTest("single"):
expected_schema = {
"title": "Select label", "type": "string", "enum": ["a", "b", ""]
"title": "Select label",
"type": "string",
"enum": ["a", "b", ""],
}
schema = Select.as_json_schema(component)
self.assertEqual(schema, expected_schema)
Expand All @@ -369,7 +373,7 @@ def test_manual_data_source(self):
self.assertEqual(schema, expected_schema)

def test_data_source_is_another_form_variable(self):
component = {
component: SelectComponent = {
"label": "Select label",
"key": "select",
"data": {
Expand All @@ -389,21 +393,24 @@ def test_data_source_is_another_form_variable(self):
with self.subTest("multiple"):
component["multiple"] = True
expected_schema = {
"title": "Select label", "type": "array", "items": {"type": "string"}
"title": "Select label",
"type": "array",
"items": {"type": "string"},
}
schema = Select.as_json_schema(component)
self.assertEqual(schema, expected_schema)


class SelectBoxesTests(TestCase):
def test_manual_data_source(self):
component = {
component: SelectBoxesComponent = {
"label": "Select boxes label",
"key": "selectBoxes",
"values": [
{"label": "A", "value": "a"},
{"label": "B", "value": "b"},
]
],
"type": "selectboxes",
}

expected_schema = {
Expand All @@ -420,17 +427,20 @@ def test_manual_data_source(self):
self.assertEqual(schema, expected_schema)

def test_data_source_is_another_form_variable(self):
component = {
component: SelectBoxesComponent = {
"label": "Select boxes label",
"key": "selectBoxes",
"values": [
{"label": "", "value": ""},
],
"openForms": {"dataSrc": "variable"},
"type": "selectboxes",
}

expected_schema = {
"title": "Select boxes label", "type": "object", "additionalProperties": True
"title": "Select boxes label",
"type": "object",
"additionalProperties": True,
}
schema = SelectBoxes.as_json_schema(component)
self.assertEqual(schema, expected_schema)
Loading

0 comments on commit 3be5893

Please sign in to comment.