Skip to content

Commit 0e68f7b

Browse files
committed
Set default settings to boto3 config when connecting to db
1 parent a2cdad0 commit 0e68f7b

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

e2e/test_delta_immunization.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
from datetime import datetime
22
from utils.base_test import ImmunizationBaseTest
33
from utils.immunisation_api import parse_location
4-
from utils.resource import generate_imms_resource
5-
from mypy_boto3_dynamodb.service_resource import DynamoDBServiceResource
4+
from utils.resource import generate_imms_resource, get_dynamodb_table
65
import time
76
import copy
8-
import boto3
9-
from botocore.config import Config
107
import os
118

129

@@ -17,14 +14,9 @@ class TestDeltaImmunization(ImmunizationBaseTest):
1714
DELETE_OPERATION = "DELETE"
1815
DPS_SOURCE = "DPS"
1916

20-
def get_delta_table(self):
21-
config = Config(connect_timeout=1, read_timeout=1, retries={"max_attempts": 1})
22-
db: DynamoDBServiceResource = boto3.resource("dynamodb", region_name="eu-west-2", config=config)
23-
return db.Table(os.getenv("IMMS_DELTA_TABLE_NAME"))
24-
2517
def test_create_delta_imms(self):
2618
"""Should create,update,delete FHIR Immunization resource causing those resources to be stored in Delta table"""
27-
imms_delta_table = self.get_delta_table()
19+
imms_delta_table = get_dynamodb_table(os.getenv("IMMS_DELTA_TABLE_NAME"))
2820
# Given
2921
start_timestamp = datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
3022
# Creating two Imms Event, one of them will be updated and second of them will be deleted afterwards

e2e/utils/resource.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,21 @@ def get_patient_postal_code(imms: dict):
132132

133133

134134
def get_full_row_from_identifier(identifier: str) -> dict:
135-
table = get_dynamodb_table()
136-
135+
table = get_dynamodb_table(os.getenv("DYNAMODB_TABLE_NAME"))
137136
return table.get_item(Key={"PK": f"Immunization#{identifier}"}).get("Item")
138137

139138

140-
def get_dynamodb_table() -> Table:
141-
config = Config(connect_timeout=5, read_timeout=5, retries={"max_attempts": 5})
139+
def get_dynamodb_table(table_name: str) -> Table:
140+
config = Config(connect_timeout=60, read_timeout=60, retries={"max_attempts": 3})
142141
db: DynamoDBServiceResource = boto3.resource("dynamodb", region_name="eu-west-2", config=config)
143-
return db.Table(os.getenv("DYNAMODB_TABLE_NAME"))
142+
return db.Table(table_name)
144143

145144

146145
def delete_imms_records(identifiers: list[str]) -> None:
147146
"""Batch delete immunization records from the DynamoDB table.
148147
Handles logging internally and does not return anything.
149148
"""
150-
table = get_dynamodb_table()
149+
table = get_dynamodb_table(os.getenv("DYNAMODB_TABLE_NAME"))
151150
success_count = 0
152151
failure_count = 0
153152
total = len(identifiers)

0 commit comments

Comments
 (0)