diff --git a/tests/databases/api_tests.py b/tests/databases/api_tests.py index be4e1e066018b..479a4dfd6c0ff 100644 --- a/tests/databases/api_tests.py +++ b/tests/databases/api_tests.py @@ -23,6 +23,7 @@ from io import BytesIO from unittest import mock from zipfile import is_zipfile, ZipFile +from operator import itemgetter import prison import pytest @@ -1674,38 +1675,74 @@ def test_validate_parameters_invalid_payload_schema(self): response = json.loads(rv.data.decode("utf-8")) assert rv.status_code == 422 - assert response == { - "errors": [ - { - "message": "Missing data for required field.", - "error_type": "INVALID_PAYLOAD_SCHEMA_ERROR", - "level": "error", - "extra": { - "invalid": ["engine"], - "issue_codes": [ - { - "code": 1020, - "message": "Issue 1020 - The submitted payload has the incorrect schema.", - } - ], + invalid_schema = response["errors"][0]["extra"]["invalid"][0] + # This is done because this array of errors does not have a deterministic order + if invalid_schema == "engine": + assert response == { + "errors": [ + { + "message": "Missing data for required field.", + "error_type": "INVALID_PAYLOAD_SCHEMA_ERROR", + "level": "error", + "extra": { + "invalid": ["engine"], + "issue_codes": [ + { + "code": 1020, + "message": "Issue 1020 - The submitted payload has the incorrect schema.", + } + ], + }, }, - }, - { - "message": "Missing data for required field.", - "error_type": "INVALID_PAYLOAD_SCHEMA_ERROR", - "level": "error", - "extra": { - "invalid": ["configuration_method"], - "issue_codes": [ - { - "code": 1020, - "message": "Issue 1020 - The submitted payload has the incorrect schema.", - } - ], + { + "message": "Missing data for required field.", + "error_type": "INVALID_PAYLOAD_SCHEMA_ERROR", + "level": "error", + "extra": { + "invalid": ["configuration_method"], + "issue_codes": [ + { + "code": 1020, + "message": "Issue 1020 - The submitted payload has the incorrect schema.", + } + ], + }, }, - }, - ] - } + ] + } + else: + assert response == { + "errors": [ + { + "message": "Missing data for required field.", + "error_type": "INVALID_PAYLOAD_SCHEMA_ERROR", + "level": "error", + "extra": { + "invalid": ["configuration_method"], + "issue_codes": [ + { + "code": 1020, + "message": "Issue 1020 - The submitted payload has the incorrect schema.", + } + ], + }, + }, + { + "message": "Missing data for required field.", + "error_type": "INVALID_PAYLOAD_SCHEMA_ERROR", + "level": "error", + "extra": { + "invalid": ["engine"], + "issue_codes": [ + { + "code": 1020, + "message": "Issue 1020 - The submitted payload has the incorrect schema.", + } + ], + }, + }, + ] + } def test_validate_parameters_missing_fields(self): self.login(username="admin")