Skip to content

Commit

Permalink
Update type hints and use context manager for test
Browse files Browse the repository at this point in the history
  • Loading branch information
VirajP1002 committed Dec 20, 2024
1 parent 9384e06 commit 22325ca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/services/supplementary_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def validate_supplementary_data(
identifier: str,
survey_id: str,
sds_schema_version: str | None = None,
) -> dict:
) -> dict[str, str | dict | int | list]:
try:
return validate_supplementary_data_v1(
supplementary_data=supplementary_data,
Expand Down
2 changes: 1 addition & 1 deletion app/utilities/supplementary_data_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def validate_supplementary_data_v1(
identifier: str,
survey_id: str,
sds_schema_version: str | None = None,
) -> dict:
) -> dict[str, str | dict | int | list]:
"""Validate claims required for supplementary data"""
supplementary_data_metadata_schema = SupplementaryDataMetadataSchema(
unknown=INCLUDE
Expand Down
27 changes: 19 additions & 8 deletions tests/app/parser/test_supplementary_data_parser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from contextlib import contextmanager
from copy import deepcopy

import pytest
Expand All @@ -6,6 +7,15 @@
from app.services.supplementary_data import validate_supplementary_data
from app.utilities.supplementary_data_parser import validate_supplementary_data_v1


@contextmanager
def not_raises(exception):
try:
yield
except exception as validation_error:
raise pytest.fail(f"{validation_error} RAISED")


SUPPLEMENTARY_DATA_PAYLOAD = {
"dataset_id": "44f1b432-9421-49e5-bd26-e63e18a30b69",
"survey_id": "123",
Expand Down Expand Up @@ -70,14 +80,15 @@ def test_invalid_supplementary_dataset_version_raises_error():
)


def test_valid_supplementary_dataset_version():
validated_payload = validate_supplementary_data_v1(
supplementary_data=SUPPLEMENTARY_DATA_PAYLOAD,
dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69",
identifier="12345678901",
survey_id="123",
sds_schema_version="v1",
)
def test_valid_supplementary_dataset_version_does_not_raise_error():
with not_raises(ValidationError):
validated_payload = validate_supplementary_data_v1(
supplementary_data=SUPPLEMENTARY_DATA_PAYLOAD,
dataset_id="44f1b432-9421-49e5-bd26-e63e18a30b69",
identifier="12345678901",
survey_id="123",
sds_schema_version="v1",
)

assert validated_payload == SUPPLEMENTARY_DATA_PAYLOAD

Expand Down

0 comments on commit 22325ca

Please sign in to comment.