11import json
22
33import pytest
4- from domain .core .enum import Status
5- from domain .core .questionnaire .v3 import Questionnaire
4+ from domain .core .questionnaire .v3 import (
5+ Questionnaire ,
6+ QuestionnaireResponseMissingValue ,
7+ QuestionnaireResponseValidationError ,
8+ )
69from domain .core .timestamp import now
7- from jsonschema import ValidationError as JsonSchemaValidationError
8- from pydantic import ValidationError as PydanticValidationError
10+ from pydantic import ValidationError
911
1012VALID_SCHEMA = {
1113 "$schema" : "http://json-schema.org/draft-07/schema#" ,
@@ -51,13 +53,10 @@ def test_schema_validation_pass(data):
5153 name = "foo" , version = "1" , json_schema = json .dumps (VALID_SCHEMA )
5254 )
5355 response = questionnaire .validate (data = data )
54- assert response .name == "foo"
55- assert response .version == "1"
56+ assert response .questionnaire_name == "foo"
57+ assert response .questionnaire_version == "1"
5658 assert response .data == data
57- assert response .status is Status .ACTIVE
5859 assert response .created_on .date () == now ().date ()
59- assert response .updated_on is None
60- assert response .deleted_on is None
6160
6261
6362@pytest .mark .parametrize (
@@ -77,17 +76,31 @@ def test_schema_validation_fail(data):
7776 questionnaire = Questionnaire (
7877 name = "foo" , version = "1" , json_schema = json .dumps (VALID_SCHEMA )
7978 )
80- with pytest .raises (JsonSchemaValidationError ):
79+ with pytest .raises (QuestionnaireResponseValidationError ):
80+ questionnaire .validate (data = data )
81+
82+
83+ @pytest .mark .parametrize (
84+ "data" ,
85+ [
86+ {"size" : 1 },
87+ {"colour" : "white" },
88+ ],
89+ )
90+ def test_schema_validation_missing_fail (data ):
91+ questionnaire = Questionnaire (
92+ name = "foo" , version = "1" , json_schema = json .dumps (VALID_SCHEMA )
93+ )
94+ with pytest .raises (QuestionnaireResponseMissingValue ):
8195 questionnaire .validate (data = data )
8296
8397
8498@pytest .mark .parametrize (
8599 "schema" ,
86100 [
87- {},
88101 INVALID_SCHEMA ,
89102 ],
90103)
91104def test_invalid_schema (schema ):
92- with pytest .raises (PydanticValidationError ):
105+ with pytest .raises (ValidationError ):
93106 Questionnaire (name = "name" , version = "123" , json_schema = json .dumps (schema ))
0 commit comments