From 08f52d7620768956393e79d1b5208cfdd64f56ca Mon Sep 17 00:00:00 2001 From: jhartmann Date: Tue, 28 May 2024 08:56:40 +0200 Subject: [PATCH] chore(tavern):[#503] fix failing ess tests --- .../api-tests/irs-api-tests.tavern.yaml | 12 +++- local/testing/api-tests/tavern_helpers.py | 58 +++++++++++++------ 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/local/testing/api-tests/irs-api-tests.tavern.yaml b/local/testing/api-tests/irs-api-tests.tavern.yaml index fe922ff24c..6601c79381 100644 --- a/local/testing/api-tests/irs-api-tests.tavern.yaml +++ b/local/testing/api-tests/irs-api-tests.tavern.yaml @@ -507,9 +507,15 @@ stages: - function: local.testing.api-tests.tavern_helpers:supplyChainImpacted_is_as_expected extra_kwargs: expectedSupplyChainImpacted: "Unknown" - - function: local.testing.api-tests.tavern_helpers:tombstone_for_EssValidation_are_correct + - function: local.testing.api-tests.tavern_helpers:tombstones_have_size + extra_kwargs: + number_of_tombstones: 2 + - function: local.testing.api-tests.tavern_helpers:tombstone_for_submodel_validation_is_correct + extra_kwargs: + expected_error_detail: "Submodel payload validation failed. $.sites[0]: required property 'catenaXsiteId' not found." + - function: local.testing.api-tests.tavern_helpers:tombstone_for_ess_validation_is_correct extra_kwargs: - expectedTombstone: "'PartSiteInformationAsPlanned' exists, but catenaXSiteId could not be found." + expected_error_detail: "AspectType 'PartSiteInformationAsPlanned' not found in Job." headers: content-type: application/json @@ -749,7 +755,7 @@ stages: - function: local.testing.api-tests.tavern_helpers:ESS_job_parameter_are_as_requested - function: local.testing.api-tests.tavern_helpers:supplyChainFirstLevelBpn_is_as_expected extra_kwargs: - expectedBpnl: BPNL00ARBITRARY10 + expectedBpnl: BPNL0ARBITRARY10 headers: content-type: application/json diff --git a/local/testing/api-tests/tavern_helpers.py b/local/testing/api-tests/tavern_helpers.py index 2b218b5598..44b0963b04 100644 --- a/local/testing/api-tests/tavern_helpers.py +++ b/local/testing/api-tests/tavern_helpers.py @@ -54,25 +54,39 @@ def ESS_job_parameter_are_as_requested(response): assert 'urn:samm:io.catenax.part_as_planned:1.0.1#PartAsPlanned' in aspects_list -def tombstone_for_EssValidation_are_correct(response, expectedTombstone): - error_list = response.json().get("tombstones") +def tombstone_for_ess_validation_is_correct(response, expected_error_detail): + response_contains_expected_error(response, expected_error_detail, 'EssValidation') - for i in error_list: - print("Given tombstone: ", i) - catenaXId = i.get("catenaXId") - print("Given catenaXID: ", catenaXId) - processingErrorStep = i.get("processingError").get("processStep") - print("Processstep in ProcessingError: ", processingErrorStep) - processingErrorDetail = i.get("processingError").get("errorDetail") - print("ErrorMessage: ", processingErrorDetail) - processingErrorLastAttempt = i.get("processingError").get("lastAttempt") - print("LastAttempt: ", processingErrorLastAttempt) - processingErrorRetryCounter = i.get("processingError").get("retryCounter") - print("RetryCounter: ", processingErrorRetryCounter) - assert 'EssValidation' in processingErrorStep - assert expectedTombstone in processingErrorDetail - assert processingErrorLastAttempt is not None - assert 0 is processingErrorRetryCounter + +def tombstone_for_submodel_validation_is_correct(response, expected_error_detail): + response_contains_expected_error(response, expected_error_detail, 'SchemaValidation') + + +def check_tombstones(tombstones, criteria): + for tombstone in tombstones: + for criterion in criteria: + if (tombstone.get("processingError").get("processStep") == criterion.get("processStep") and + tombstone.get("processingError").get("errorDetail") == criterion.get("errorDetail")): + return True + return False + + +def response_contains_expected_error(response, expected_error_detail, expected_process_step): + error_list = response.json().get("tombstones") + criteria = [ + { + "processStep": expected_process_step, + "errorDetail": expected_error_detail + } + ] + check_tombstones(error_list, criteria) + for tombstone in error_list: + processing_error_last_attempt = tombstone.get("processingError").get("lastAttempt") + print("LastAttempt: ", processing_error_last_attempt) + processing_error_retry_counter = tombstone.get("processingError").get("retryCounter") + print("RetryCounter: ", processing_error_retry_counter) + assert processing_error_last_attempt is not None + assert 0 == processing_error_retry_counter ############################## /\ ESS helpers /\ ############################## @@ -90,6 +104,12 @@ def tombstones_are_empty(response): assert len(response.json().get("tombstones")) == 0 +def tombstones_have_size(response, number_of_tombstones): + print(response.json().get("tombstones")) + print("Check if tombstones have expected number of elements: ", number_of_tombstones) + assert len(response.json().get("tombstones")) == number_of_tombstones + + def tombstones_are_not_empty(response): print(response.json().get("tombstones")) print("Check if tombstones are not empty number:", len(response.json().get("tombstones"))) @@ -163,7 +183,7 @@ def errors_for_unknown_globalAssetId_are_correct(response): assert 'DigitalTwinRequest' in processingErrorStep #assert 'Shell for identifier urn:uuid:cce14502-958a-42e1-8bb7-f4f41aaaaaaa not found' in processingErrorDetail #commented out since this error message is not possible currently after DTR changes assert processingErrorLastAttempt is not None - assert 3 is processingErrorRetryCounter + assert 3 == processingErrorRetryCounter def status_of_jobs_are_as_expected(response, expected_status):