diff --git a/chord_metadata_service/chord/ingest/exceptions.py b/chord_metadata_service/chord/ingest/exceptions.py index 431e41242..954118629 100644 --- a/chord_metadata_service/chord/ingest/exceptions.py +++ b/chord_metadata_service/chord/ingest/exceptions.py @@ -94,7 +94,7 @@ def parse_schema_warnings(data: dict, schema: dict) -> Optional[List[dict]]: warnings = [] for (version, version_changes) in applicable_changes.items(): for (prop_name, changes) in version_changes.get("properties", {}).items(): - if property_warning:= parse_property_warnings(data, prop_name, changes): + if property_warning := parse_property_warnings(data, prop_name, changes): property_warning["version"] = version warnings.append(property_warning) return warnings if len(warnings) else None diff --git a/chord_metadata_service/chord/ingest/experiments.py b/chord_metadata_service/chord/ingest/experiments.py index 03a7aaf3c..df9713547 100644 --- a/chord_metadata_service/chord/ingest/experiments.py +++ b/chord_metadata_service/chord/ingest/experiments.py @@ -56,7 +56,7 @@ def create_experiment_result(er: dict) -> em.ExperimentResult: def validate_experiment(experiment_data, idx: Optional[int] = None) -> None: # Validate experiment data against experiments schema. - if val_errors:= schema_validation(experiment_data, EXPERIMENT_SCHEMA): + if val_errors := schema_validation(experiment_data, EXPERIMENT_SCHEMA): raise IngestError( data=experiment_data, schema=EXPERIMENT_SCHEMA, diff --git a/chord_metadata_service/chord/ingest/phenopackets.py b/chord_metadata_service/chord/ingest/phenopackets.py index 14b87f65c..133b71bf0 100644 --- a/chord_metadata_service/chord/ingest/phenopackets.py +++ b/chord_metadata_service/chord/ingest/phenopackets.py @@ -60,7 +60,7 @@ def validate_phenopacket(phenopacket_data: dict[str, Any], schema: dict = PHENOPACKET_SCHEMA, idx: Optional[int] = None) -> None: # Validate phenopacket data against phenopackets schema. - if val_errors:= schema_validation(phenopacket_data, schema): + if val_errors := schema_validation(phenopacket_data, schema): raise IngestError( data=phenopacket_data, schema=PHENOPACKET_SCHEMA, diff --git a/chord_metadata_service/chord/tests/test_api_ingest.py b/chord_metadata_service/chord/tests/test_api_ingest.py index 15cbb2f10..ced50a5c0 100644 --- a/chord_metadata_service/chord/tests/test_api_ingest.py +++ b/chord_metadata_service/chord/tests/test_api_ingest.py @@ -3,9 +3,8 @@ from django.urls import reverse from rest_framework import status from rest_framework.test import APITestCase -from chord_metadata_service.chord.tests.example_ingest import EXAMPLE_INGEST_EXPERIMENT, EXAMPLE_INGEST_INVALID_EXPERIMENT, EXAMPLE_INGEST_INVALID_PHENOPACKET, EXAMPLE_INGEST_PHENOPACKET - -from chord_metadata_service.restapi.tests.utils import load_local_json +from chord_metadata_service.chord.tests.example_ingest import EXAMPLE_INGEST_EXPERIMENT, \ + EXAMPLE_INGEST_INVALID_EXPERIMENT, EXAMPLE_INGEST_INVALID_PHENOPACKET, EXAMPLE_INGEST_PHENOPACKET from .constants import VALID_PROJECT_1, valid_dataset_1 from ..workflows.metadata import METADATA_WORKFLOWS @@ -88,7 +87,7 @@ def test_phenopackets_ingest(self): c = r.json() self.assertEqual(r.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR) self.assertEqual(c["success"], False) - self.assertEqual(len(c["errors"]), 1) # 1 required property + self.assertEqual(len(c["errors"]), 1) # 1 required property # Invalid phenopacket JSON validation r = self.client.post( @@ -113,7 +112,6 @@ def test_phenopackets_ingest(self): self.assertEqual(len(c["warnings"]), 0) self.assertEqual(r.status_code, status.HTTP_201_CREATED) - def test_experiments_ingest_failures(self): # Invalid workflow ID r = self.client.post( @@ -133,7 +131,7 @@ def test_experiments_ingest_failures(self): c = r.json() self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(c["success"], False) - self.assertEqual(len(c["errors"]), 2) # 2 required properties + self.assertEqual(len(c["errors"]), 2) # 2 required properties # Bad ingestion body JSON r = self.client.post( @@ -156,7 +154,7 @@ def test_experiments_ingest_failures(self): self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(c["success"], False) self.assertEqual(len(c["errors"]), 4) - + # Two of the errors concern experiment schema changes warnings = c["warnings"] self.assertEqual(len(warnings), 2) @@ -174,7 +172,7 @@ def test_experiments_ingest_failures(self): self.assertEqual(c["success"], False) self.assertEqual(len(c["errors"]), 1) self.assertEqual(r.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR) - + def test_experiment_ingest_success(self): # Create the required phenopacket with a biosample first r = self.client.post(