Skip to content

Commit 6173e17

Browse files
committed
Cleanup error messages
1 parent bcc6be8 commit 6173e17

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

azure/templates/post-deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ steps:
206206

207207
displayName: Run full batch test suite
208208
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)/$(SERVICE_ARTIFACT_NAME)/e2e_batch"
209-
enabled: false
209+
condition: eq(1, 2) # Disable task but make this step visible in the pipeline
210210

211211
- task: PublishTestResults@2
212212
displayName: 'Publish test results'

e2e/utils/base_test.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,17 @@ def tearDownClass(cls):
103103
# It’s used to clean up resources that were initialized specifically for a single test,
104104
# such as temporary files or mock objects.
105105
def tearDown(cls):
106-
for api in cls.imms_apis:
107-
if api.generated_test_records:
108-
imms_deleted = delete_imms_records(api.generated_test_records)
109-
print(imms_deleted)
110-
api.generated_test_records.clear()
106+
for api_client in cls.imms_apis:
107+
if api_client.generated_test_records:
108+
result = delete_imms_records(api_client.generated_test_records)
109+
110+
if result.get("failure_count", 0) > 0:
111+
print(
112+
f"[teardown warning] Deleted {result.get('success_count', 0)} records out of "
113+
f"{len(api_client.generated_test_records)}, failed to delete {result['failure_count']}"
114+
)
115+
116+
api_client.generated_test_records.clear()
111117

112118
@staticmethod
113119
def create_immunization_resource(imms_api: ImmunisationApi, resource: dict = None) -> str:

e2e/utils/resource.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from mypy_boto3_dynamodb.service_resource import DynamoDBServiceResource, Table
99
from botocore.config import Config
1010
from .mappings import vaccine_type_mappings, VaccineTypes
11-
from functools import lru_cache
1211
from .constants import valid_nhs_number1
1312

1413
current_directory = os.path.dirname(os.path.realpath(__file__))
@@ -138,31 +137,32 @@ def get_full_row_from_identifier(identifier: str) -> dict:
138137
return table.get_item(Key={"PK": f"Immunization#{identifier}"}).get("Item")
139138

140139

141-
@lru_cache()
142140
def get_dynamodb_table() -> Table:
143141
config = Config(connect_timeout=2, read_timeout=2, retries={"max_attempts": 1})
144142
db: DynamoDBServiceResource = boto3.resource("dynamodb", region_name="eu-west-2", config=config)
145143
return db.Table(os.getenv("DYNAMODB_TABLE_NAME"))
146144

147145

148146
def delete_imms_records(identifiers: list[str]) -> dict:
149-
"""Batch delete immunization records from the DynamoDB table."""
147+
"""Batch delete immunization records from the DynamoDB table.
148+
Returns counts of successful and failed deletions.
149+
"""
150150
table = get_dynamodb_table()
151-
deleted = []
152-
errors = []
151+
success_count = 0
152+
failure_count = 0
153153

154154
try:
155155
with table.batch_writer(overwrite_by_pkeys=["PK"]) as batch:
156156
for identifier in identifiers:
157157
key = {"PK": f"Immunization#{identifier}"}
158158
try:
159159
batch.delete_item(Key=key)
160-
deleted.append(identifier)
160+
success_count += 1
161161
except Exception as e:
162162
print(f"Failed to delete record with key {key}: {e}")
163-
errors.append({"identifier": identifier, "error": str(e)})
163+
failure_count += 1
164164
except Exception as e:
165165
print(f"Batch writer failed: {e}")
166-
return {"Error": str(e), "Deleted": deleted, "Failures": errors}
166+
return {"success_count": success_count, "failure_count": len(identifiers)}
167167

168-
return {"Deleted": deleted, "Failures": errors}
168+
return {"success_count": success_count, "failure_count": failure_count}

0 commit comments

Comments
 (0)