From 65b61514ae9e4f3950d7c39964a876a160722f12 Mon Sep 17 00:00:00 2001 From: Fang-Pen Lin Date: Tue, 4 Nov 2025 09:32:59 -0800 Subject: [PATCH] Fix all broken tests --- backend/bdd/features/pki/acme/order.feature | 4 ++-- backend/bdd/features/steps/pki_acme.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/backend/bdd/features/pki/acme/order.feature b/backend/bdd/features/pki/acme/order.feature index 2a85dc84c..046dcda55 100644 --- a/backend/bdd/features/pki/acme/order.feature +++ b/backend/bdd/features/pki/acme/order.feature @@ -19,7 +19,7 @@ Feature: Order Then the value order.body with jq ".status" should be equal to "pending" Then the value order.body with jq ".identifiers" should be equal to [{"type": "dns", "value": "localhost"}] Then the value order.body with jq ".finalize" should match pattern {BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/orders/(.+)/finalize - Then the value order.body with jq "all(.authorizations[]; startswith('{BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/authorizations/'))" should be equal to true + Then the value order.body with jq "all(.authorizations[]; startswith("{BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/authorizations/"))" should be equal to true Scenario: Create a new order with SANs Given I have an ACME cert profile as "acme_profile" @@ -71,4 +71,4 @@ Feature: Order Then the value fetched_order with jq ".status" should be equal to "pending" Then the value fetched_order with jq ".identifiers" should be equal to [{"type": "dns", "value": "localhost"}] Then the value fetched_order with jq ".finalize" should match pattern {BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/orders/(.+)/finalize - Then the value fetched_order with jq "all(.authorizations[]; startswith('{BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/authorizations/'))" should be equal to true + Then the value fetched_order with jq "all(.authorizations[]; startswith("{BASE_URL}/api/v1/pki/acme/profiles/{acme_profile.id}/authorizations/"))" should be equal to true diff --git a/backend/bdd/features/steps/pki_acme.py b/backend/bdd/features/steps/pki_acme.py index 30482c5b3..3441b851a 100644 --- a/backend/bdd/features/steps/pki_acme.py +++ b/backend/bdd/features/steps/pki_acme.py @@ -160,7 +160,10 @@ def step_impl(context: Context, method: str, url: str): ) context.vars["response"] = response logger.debug("Response status: %r", response.status_code) - logger.debug("Response JSON payload: %r", response.json()) + try: + logger.debug("Response JSON payload: %r", response.json()) + except json.decoder.JSONDecodeError: + pass @when('I send a {method} request to "{url}" with JSON payload') @@ -203,14 +206,14 @@ def step_impl(context: Context, url: str): @then('the response status code should be "{expected_status_code:d}"') def step_impl(context: Context, expected_status_code: int): - assert context.response.status_code == expected_status_code, ( - f"{context.response.status_code} != {expected_status_code}" + assert context.vars["response"].status_code == expected_status_code, ( + f"{context.vars['response'].status_code} != {expected_status_code}" ) @then('the response header "{header}" should contains non-empty value') def step_impl(context: Context, header: str): - header_value = context.response.headers.get(header) + header_value = context.vars["response"].headers.get(header) assert header_value is not None, f"Header {header} not found in response" assert header_value, ( f"Header {header} found in response, but value {header_value:!r} is empty" @@ -219,7 +222,7 @@ def step_impl(context: Context, header: str): @then("the response body should match JSON value") def step_impl(context: Context): - payload = context.response.json() + payload = context.vars["response"].json() expected = json.loads(context.text) replaced = replace_vars(expected, context.vars) assert payload == replaced, f"{payload} != {replaced}"