Skip to content

Commit

Permalink
test that data type in manifest.json is a string
Browse files Browse the repository at this point in the history
  • Loading branch information
briehl committed Nov 14, 2024
1 parent 2d066f6 commit 1b3d8ad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
8 changes: 8 additions & 0 deletions staging_service/import_specifications/individual_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,5 +449,13 @@ def _parse_single_manifest_resource(resource: dict[str, Any], spcsrc: Specificat
)
)
datatype = instructions[_DTS_INSTRUCTIONS_DATATYPE_KEY]
if not isinstance(datatype, str):
raise _ParseException(
Error(
ErrorType.PARSE_FAIL,
"Data type must be a string",
spcsrc
)
)
parameters = frozendict(instructions[_DTS_INSTRUCTIONS_PARAMETERS_KEY])
return datatype, parameters
29 changes: 26 additions & 3 deletions tests/import_specifications/test_individual_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ def test_dts_manifest_file_is_directory(temp_dir: Generator[Path, None, None]):
[], 1, "nope", None
]
@mark.parametrize("bad_instruction", malformed_dict)
def test_dts_manifest_malformed_instructions(write_dts_manifest: Callable[[dict | list], Path], bad_instruction):
def test_dts_manifest_malformed_instructions(write_dts_manifest: Callable[[dict | list], Path], bad_instruction: list|int|str|None):
manifest_file = write_dts_manifest({
"resources": [{
"id": "some_id",
Expand All @@ -909,7 +909,7 @@ def test_dts_manifest_malformed_instructions(write_dts_manifest: Callable[[dict
)

@mark.parametrize("bad_parameters", malformed_dict)
def test_dts_manifest_malformed_parameters(write_dts_manifest: Callable[[dict | list], Path], bad_parameters):
def test_dts_manifest_malformed_parameters(write_dts_manifest: Callable[[dict | list], Path], bad_parameters: list|int|str|None):
manifest_file = write_dts_manifest({
"resources": [{
"id": "some_id",
Expand Down Expand Up @@ -937,7 +937,7 @@ def test_dts_manifest_malformed_parameters(write_dts_manifest: Callable[[dict |
["data_type", "parameters"]
]
@mark.parametrize("missing_keys", missing_key_cases)
def test_dts_manifest_missing_instruction_keys(write_dts_manifest: Callable[[dict | list], Path], missing_keys):
def test_dts_manifest_missing_instruction_keys(write_dts_manifest: Callable[[dict | list], Path], missing_keys: list[str]):
instructions = {
"data_type": "some_type",
"parameters": {
Expand Down Expand Up @@ -974,3 +974,26 @@ def test_dts_manifest_empty(write_dts_manifest: Callable[[dict | list], Path]):
SpecificationSource(manifest_file)
)]
)

@mark.parametrize("non_str", [{"a": "b"}, ["a", "b"], 1, None])
def test_dts_manifest_fail_data_type_not_str(write_dts_manifest: Callable[[dict | list], Path], non_str: dict|list|int|None):
manifest_file = write_dts_manifest({
"resources": [{
"id": "foo",
"name": "bar",
"path": "baz",
"format": "some_format",
"instructions": {
"data_type": non_str,
"parameters": {}
}
}]
})
_dts_manifest_parse_fail(
manifest_file,
[Error(
ErrorType.PARSE_FAIL,
"Data type must be a string",
SpecificationSource(manifest_file)
)]
)

0 comments on commit 1b3d8ad

Please sign in to comment.