Skip to content
Snippets Groups Projects
Commit 841bae3b authored by I. Nüske's avatar I. Nüske
Browse files

BUG: Create and use jsonschema files that match test data layout

parent 6cdd4f20
Branches
Tags
2 merge requests!138Release 0.14.0,!129Enable validation in table_json_conversion.convert.to_dict for use in XLSX-converter
{
"type": "object",
"properties": {
"Wrapper": {
"type": "array",
"items": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Wrapper",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"Training": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Training",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"url": {
"type": "string",
"description": "The URL"
}
}
},
"Results": {
"description": "Results for a training",
"type": "array",
"items": {
"type": "object",
"required": [],
"additionalProperties": false,
"description": "Results for a training",
"title": "Results",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"year": {
"type": "integer"
},
"avg_score": {
"description": "The average score for the linked training.",
"type": "number"
}
}
}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema"
}
}
},
"required": [
"Wrapper"
],
"additionalProperties": false,
"$schema": "https://json-schema.org/draft/2020-12/schema"
}
{
"type": "object",
"properties": {
"Training": {
"type": "array",
"items": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Training",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"date": {
"description": "The date of the training.",
"anyOf": [
{
"type": "string",
"format": "date"
},
{
"type": "string",
"format": "date-time"
}
]
},
"skills": {
"description": "Skills that are trained.",
"type": "array",
"items": {
"enum": [
"Planning",
"Communication",
"Evaluation"
]
},
"uniqueItems": true
},
"exam_types": {
"type": "array",
"items": {
"enum": [
"Oral",
"Written"
]
},
"uniqueItems": true
}
}
}
}
},
"required": [
"Training"
],
"additionalProperties": false,
"$schema": "https://json-schema.org/draft/2020-12/schema"
}
{
"type": "object",
"properties": {
"Training": {
"type": "array",
"items": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Training",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"date": {
"description": "The date of the training.",
"anyOf": [
{
"type": "string",
"format": "date"
},
{
"type": "string",
"format": "date-time"
}
]
},
"url": {
"type": "string",
"description": "The URL"
},
"trainer": {
"type": "array",
"items": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "trainer",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
}
}
}
},
"participant": {
"type": "array",
"items": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "participant",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
}
}
}
},
"supervisor": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "supervisor",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
}
}
},
"responsible": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "responsible",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
}
}
},
"Organisation": {
"type": "array",
"items": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Organisation",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"Country": {
"type": "string"
},
"Person": {
"type": "array",
"items": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Person",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
}
}
}
}
}
}
},
"supervisor_inherit": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "supervisor_inherit",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
}
}
},
"responsible_inherit": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "responsible_inherit",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
}
}
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema"
}
},
"Person": {
"type": "array",
"items": {
"type": "object",
"required": [],
"additionalProperties": false,
"title": "Person",
"properties": {
"name": {
"type": "string",
"description": "The name of the Record to be created"
},
"full_name": {
"type": "string"
},
"email": {
"type": "string"
}
},
"$schema": "https://json-schema.org/draft/2020-12/schema"
}
}
},
"required": [],
"additionalProperties": false,
"$schema": "https://json-schema.org/draft/2020-12/schema"
}
......@@ -66,33 +66,33 @@ json: dict
def test_conversions():
"""Test conversion from XLSX to JSON."""
convert_and_compare(xlsx_file=rfp("data/simple_data.xlsx"),
schema_file=rfp("data/simple_schema.json"),
schema_file=rfp("data/simple_data_schema.json"),
known_good_file=rfp("data/simple_data.json"))
convert_and_compare(xlsx_file=rfp("data/multiple_refs_data.xlsx"),
schema_file=rfp("data/multiple_refs_schema.json"),
schema_file=rfp("data/multiple_refs_data_schema.json"),
known_good_file=rfp("data/multiple_refs_data.json"))
convert_and_compare(xlsx_file=rfp("data/indirect_data.xlsx"),
schema_file=rfp("data/indirect_schema.json"),
schema_file=rfp("data/indirect_data_schema.json"),
known_good_file=rfp("data/indirect_data.json"))
convert_and_compare(xlsx_file=rfp("data/multiple_choice_data.xlsx"),
schema_file=rfp("data/multiple_choice_schema.json"),
schema_file=rfp("data/multiple_choice_data_schema.json"),
known_good_file=rfp("data/multiple_choice_data.json"),
strict=True)
convert_and_compare(xlsx_file=rfp("data/simple_data_booleans.xlsx"),
schema_file=rfp("data/simple_schema.json"),
schema_file=rfp("data/simple_data_schema.json"),
known_good_file=rfp("data/simple_data_booleans.json"))
with open(rfp("data/simple_data.json"), encoding="utf-8") as myfile:
expected_datetime = json.load(myfile)
expected_datetime["Training"][0]["date"] = datetime.datetime(2023, 1, 1, 0, 0)
convert_and_compare(xlsx_file=rfp("data/simple_data_datetime.xlsx"),
schema_file=rfp("data/simple_schema.json"),
schema_file=rfp("data/simple_data_schema.json"),
known_good_file="", known_good_data=expected_datetime)
# Data loss when saving as xlsx
with pytest.raises(AssertionError) as err:
convert_and_compare(xlsx_file=rfp("data/simple_data_ascii_chars.xlsx"),
schema_file=rfp("data/simple_schema.json"),
schema_file=rfp("data/simple_data_schema.json"),
known_good_file=rfp("data/simple_data_ascii_chars.json"))
assert str(err.value).startswith("Values at path ['Training', 0, ")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment