diff --git a/src/dapla_metadata/variable_definitions/exceptions.py b/src/dapla_metadata/variable_definitions/exceptions.py index 26250ef..dbbcbd9 100644 --- a/src/dapla_metadata/variable_definitions/exceptions.py +++ b/src/dapla_metadata/variable_definitions/exceptions.py @@ -39,10 +39,10 @@ def __init__(self, response_body: str) -> None: self.status = data.get("status", "Unknown status") if data.get("title") == "Constraint Violation": violations = data.get("violations", []) - self.detail = [ - f"{violation.get('field', 'Unknown field')}: {violation.get('message', 'No message provided')}" + self.detail = "".join( + f"\n{violation.get('field', 'Unknown field')}: {violation.get('message', 'No message provided')}" for violation in violations - ] + ) else: self.detail = data.get("detail", "No detail provided") diff --git a/src/dapla_metadata/variable_definitions/vardef.py b/src/dapla_metadata/variable_definitions/vardef.py index e1f9543..cc12fd5 100644 --- a/src/dapla_metadata/variable_definitions/vardef.py +++ b/src/dapla_metadata/variable_definitions/vardef.py @@ -12,9 +12,6 @@ from dapla_metadata.variable_definitions.generated.vardef_client.api.variable_definitions_api import ( VariableDefinitionsApi, ) -from dapla_metadata.variable_definitions.generated.vardef_client.models.contact import ( - Contact, -) from dapla_metadata.variable_definitions.generated.vardef_client.models.draft import ( Draft, ) @@ -173,19 +170,3 @@ def get_variable_definition( date_of_validity=date_of_validity, ), ) - - draft = Draft( - name={"nb": "testing"}, - short_name="test", - definition={"nb": "def testing"}, - classification_reference="91", - unit_types=["haha"], - subject_fields=["a"], - contains_sensitive_personal_information=True, - measurement_type="01", - valid_from=date(2024, 11, 1), - external_reference_uri="http://www.example.com", - comment=None, - related_variable_definition_uris=["http://www.example.com"], - contact=Contact(title={"nb": "title"}, email="cbi@ssb.no"), - ) diff --git a/tests/utils/constants.py b/tests/utils/constants.py index 23fd307..6fd1814 100644 --- a/tests/utils/constants.py +++ b/tests/utils/constants.py @@ -81,7 +81,6 @@ "message": "Invalid Dapla team" }, { - "field": "updateVariableDefinitionById.updateDraft.owner.team", "message": "must not be empty" } ] diff --git a/tests/variable_definitions/vardef_client/test_exceptions.py b/tests/variable_definitions/vardef_client/test_exceptions.py index 9c12b8c..b41c4a9 100644 --- a/tests/variable_definitions/vardef_client/test_exceptions.py +++ b/tests/variable_definitions/vardef_client/test_exceptions.py @@ -50,9 +50,9 @@ def test_constraint_violation(): response_body = CONSTRAINT_VIOLATION_BODY exc = VardefClientException(response_body) assert exc.status == BAD_REQUEST_STATUS - assert ( - exc.detail[0] - == "updateVariableDefinitionById.updateDraft.owner.team: Invalid Dapla team" + assert exc.detail == ( + "\nupdateVariableDefinitionById.updateDraft.owner.team: Invalid Dapla team" + "\nupdateVariableDefinitionById.updateDraft.owner.team: must not be empty" ) @@ -60,9 +60,9 @@ def test_constraint_violation_missing_messages(): response_body = CONSTRAINT_VIOLATION_BODY_MISSING_MESSAGES exc = VardefClientException(response_body) assert exc.status == BAD_REQUEST_STATUS - assert ( - exc.detail[0] - == "updateVariableDefinitionById.updateDraft.owner.team: No message provided" + assert exc.detail == ( + "\nupdateVariableDefinitionById.updateDraft.owner.team: No message provided" + "\nupdateVariableDefinitionById.updateDraft.owner.team: No message provided" ) @@ -70,14 +70,13 @@ def test_constraint_violation_empty_violations(): response_body = CONSTRAINT_VIOLATION_BODY_MISSING_VIOLATIONS exc = VardefClientException(response_body) assert exc.status == BAD_REQUEST_STATUS - assert str(exc) == "Status 400: []" + assert str(exc) == "Status 400: " def test_constraint_violation_empty_field(): response_body = CONSTRAINT_VIOLATION_BODY_MISSING_FIELD exc = VardefClientException(response_body) assert exc.status == BAD_REQUEST_STATUS - assert exc.detail == [ - "Unknown field: Invalid Dapla team", - "updateVariableDefinitionById.updateDraft.owner.team: must not be empty", - ] + assert exc.detail == ( + "\nUnknown field: Invalid Dapla team\nUnknown field: must not be empty" + )