Skip to content

Commit dd57c7e

Browse files
committed
VED-492: Fix lint errors.
1 parent 418ca7a commit dd57c7e

File tree

5 files changed

+37
-40
lines changed

5 files changed

+37
-40
lines changed

filenameprocessor/src/elasticache.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import json
22
from clients import redis_client
3-
from constants import VACCINE_TYPE_TO_DISEASES_HASH_KEY, SUPPLIER_PERMISSIONS_HASH_KEY, \
3+
from constants import (
4+
VACCINE_TYPE_TO_DISEASES_HASH_KEY,
5+
SUPPLIER_PERMISSIONS_HASH_KEY,
46
ODS_CODE_TO_SUPPLIER_SYSTEM_HASH_KEY
7+
)
58

69

710
def get_supplier_permissions_from_cache(supplier_system: str) -> list[str]:
@@ -13,5 +16,6 @@ def get_supplier_permissions_from_cache(supplier_system: str) -> list[str]:
1316
def get_valid_vaccine_types_from_cache() -> list[str]:
1417
return redis_client.hkeys(VACCINE_TYPE_TO_DISEASES_HASH_KEY)
1518

19+
1620
def get_supplier_system_from_cache(ods_code: str) -> str:
1721
return redis_client.hget(ODS_CODE_TO_SUPPLIER_SYSTEM_HASH_KEY, ods_code)

filenameprocessor/src/utils_for_filenameprocessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Utils for filenameprocessor lambda"""
22

33
import json
4-
from constants import Constants, SOURCE_BUCKET_NAME, FILE_NAME_PROC_LAMBDA_NAME
4+
from constants import SOURCE_BUCKET_NAME, FILE_NAME_PROC_LAMBDA_NAME
55
from clients import s3_client, logger, lambda_client
66

77

filenameprocessor/tests/test_lambda_handler.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@
3939
f"{vaccine_type}.CRUDS" for vaccine_type in all_vaccine_types_in_this_test_file
4040
]
4141

42-
mock_permissions_map = {
43-
supplier: json.dumps(all_permissions_in_this_test_file)
44-
for supplier in all_suppliers_in_this_test_file
45-
}
4642

4743
@patch.dict("os.environ", MOCK_ENVIRONMENT_DICT)
4844
@mock_s3
@@ -58,7 +54,11 @@ def run(self, result=None):
5854
class. Using ExitStack allows multiple patches to be applied, whilst ensuring that the mocks are cleaned up
5955
after the test has run.
6056
"""
61-
mock_hget = lambda key, field: create_mock_hget(key, field, mock_permissions_map, MOCK_ODS_CODE_TO_SUPPLIER)
57+
mock_permissions_map = {
58+
supplier: json.dumps(all_permissions_in_this_test_file)
59+
for supplier in all_suppliers_in_this_test_file
60+
}
61+
mock_hget = create_mock_hget(MOCK_ODS_CODE_TO_SUPPLIER, mock_permissions_map)
6262

6363
# Set up common patches to be applied to all tests in the class (these can be overridden in individual tests.)
6464
common_patches = [
@@ -357,12 +357,7 @@ def test_lambda_invalid_permissions_other_files_in_queue(self):
357357
add_entry_to_table(queued_file_details, FileStatus.QUEUED)
358358

359359
# Mock the supplier permissions with a value which doesn't include the requested Flu permissions
360-
mock_hget = lambda key, field: create_mock_hget(
361-
key,
362-
field,
363-
{},
364-
{"X8E5B": "RAVS"}
365-
)
360+
mock_hget = create_mock_hget({"X8E5B": "RAVS"}, {})
366361
with ( # noqa: E999
367362
patch("file_name_processor.uuid4", return_value=file_details.message_id), # noqa: E999
368363
patch("elasticache.redis_client.hget", side_effect=mock_hget), # noqa: E999
@@ -472,7 +467,7 @@ def setUp(self):
472467
self.addCleanup(hkeys_patcher.stop)
473468
hkeys_patcher.start()
474469

475-
mock_hget = lambda key, field: create_mock_hget(key, field, {}, {"X8E5B": "RAVS"})
470+
mock_hget = create_mock_hget({"X8E5B": "RAVS"}, {})
476471
hget_patcher = patch("elasticache.redis_client.hget", side_effect=mock_hget)
477472
self.addCleanup(hget_patcher.stop)
478473
hget_patcher.start()

filenameprocessor/tests/test_logging_decorator.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,9 @@ def test_generate_and_send_logs(self):
141141
def test_logging_successful_validation(self):
142142
"""Tests that the correct logs are sent to cloudwatch and splunk when file validation is successful"""
143143
# Mock full permissions so that validation will pass
144-
mock_hget = lambda key, field: create_mock_hget(
145-
key,
146-
field,
147-
{"EMIS": json.dumps(["FLU.CRUDS"])},
148-
{"YGM41": "EMIS"}
144+
mock_hget = create_mock_hget(
145+
{"YGM41": "EMIS"},
146+
{"EMIS": json.dumps(["FLU.CRUDS"])}
149147
)
150148
with ( # noqa: E999
151149
patch("file_name_processor.uuid4", return_value=FILE_DETAILS.message_id), # noqa: E999
@@ -175,11 +173,9 @@ def test_logging_successful_validation(self):
175173
def test_logging_failed_validation(self):
176174
"""Tests that the correct logs are sent to cloudwatch and splunk when file validation fails"""
177175
# Set up permissions for COVID19 only (file is for FLU), so that validation will fail
178-
mock_hget = lambda key, field: create_mock_hget(
179-
key,
180-
field,
181-
{"EMIS": json.dumps(["COVID19.CRUDS"])},
182-
{"YGM41": "EMIS"}
176+
mock_hget = create_mock_hget(
177+
{"YGM41": "EMIS"},
178+
{"EMIS": json.dumps(["COVID19.CRUDS"])}
183179
)
184180
with ( # noqa: E999
185181
patch("file_name_processor.uuid4", return_value=FILE_DETAILS.message_id), # noqa: E999
@@ -214,11 +210,9 @@ def test_logging_throws_exception(self):
214210
operation_name="PutRecord"
215211
)
216212

217-
mock_hget = lambda key, field: create_mock_hget(
218-
key,
219-
field,
220-
{"EMIS": json.dumps(["FLU.CRUDS"])},
221-
{"YGM41": "EMIS"}
213+
mock_hget = create_mock_hget(
214+
{"YGM41": "EMIS"},
215+
{"EMIS": json.dumps(["FLU.CRUDS"])}
222216
)
223217
with (
224218
patch("file_name_processor.uuid4", return_value=FILE_DETAILS.message_id),

filenameprocessor/tests/utils_for_tests/utils_for_filenameprocessor_tests.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
"""Utils functions for filenameprocessor tests"""
2-
import json
32
from unittest.mock import patch
43
from io import StringIO
54
from boto3.dynamodb.types import TypeDeserializer
@@ -12,8 +11,13 @@
1211
with patch.dict("os.environ", MOCK_ENVIRONMENT_DICT):
1312
from clients import REGION_NAME
1413
from csv import DictReader
15-
from constants import AuditTableKeys, AUDIT_TABLE_NAME, FileStatus, SUPPLIER_PERMISSIONS_HASH_KEY, \
16-
ODS_CODE_TO_SUPPLIER_SYSTEM_HASH_KEY
14+
from constants import (
15+
AuditTableKeys,
16+
AUDIT_TABLE_NAME,
17+
FileStatus,
18+
SUPPLIER_PERMISSIONS_HASH_KEY,
19+
ODS_CODE_TO_SUPPLIER_SYSTEM_HASH_KEY
20+
)
1721

1822
MOCK_ODS_CODE_TO_SUPPLIER = {
1923
"YGM41": "EMIS",
@@ -53,13 +57,13 @@ def assert_audit_table_entry(file_details: FileDetails, expected_status: FileSta
5357

5458

5559
def create_mock_hget(
56-
key: str,
57-
field: str,
58-
mock_supplier_permissions: dict[str, str],
5960
mock_ods_code_to_supplier: dict[str, str],
61+
mock_supplier_permissions: dict[str, str],
6062
):
61-
if key == SUPPLIER_PERMISSIONS_HASH_KEY:
62-
return mock_supplier_permissions.get(field)
63-
if key == ODS_CODE_TO_SUPPLIER_SYSTEM_HASH_KEY:
64-
return mock_ods_code_to_supplier.get(field)
65-
return None
63+
def mock_hget(key, field):
64+
if key == ODS_CODE_TO_SUPPLIER_SYSTEM_HASH_KEY:
65+
return mock_ods_code_to_supplier.get(field)
66+
if key == SUPPLIER_PERMISSIONS_HASH_KEY:
67+
return mock_supplier_permissions.get(field)
68+
return None
69+
return mock_hget

0 commit comments

Comments
 (0)