Skip to content

Commit 1e94162

Browse files
committed
VED-372: Tidy up.
1 parent 0ebf783 commit 1e94162

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

filenameprocessor/tests/test_file_key_validation.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717

1818
class TestFileKeyValidation(TestCase):
1919
"""Tests for file_key_validation functions"""
20-
def setUp(self):
21-
redis_patcher = patch("clients.redis_client.hkeys", return_value=["FLU", "COVID19", "MMR", "RSV"])
22-
self.addCleanup(redis_patcher.stop)
23-
redis_patcher.start()
24-
2520
def test_is_valid_datetime(self):
2621
"Tests that is_valid_datetime returns True for valid datetimes, and false otherwise"
2722
# Test case tuples are stuctured as (date_time_string, expected_result)
@@ -43,7 +38,8 @@ def test_is_valid_datetime(self):
4338
with self.subTest():
4439
self.assertEqual(is_valid_datetime(date_time_string), expected_result)
4540

46-
def test_validate_file_key(self):
41+
@patch("elasticache.redis_client.hkeys", return_value=["FLU", "RSV"])
42+
def test_validate_file_key(self, _mock_hkeys):
4743
"""Tests that file_key_validation returns True if all elements pass validation, and False otherwise"""
4844
# Test case tuples are structured as (file_key, expected_result)
4945
test_cases_for_success_scenarios = [
@@ -60,6 +56,7 @@ def test_validate_file_key(self):
6056
for file_key, expected_result in test_cases_for_success_scenarios:
6157
with self.subTest(f"SubTest for file key: {file_key}"):
6258
self.assertEqual(validate_file_key(file_key), expected_result)
59+
_mock_hkeys.assert_called_with("vacc_to_diseases")
6360

6461
key_format_error_message = "Initial file validation failed: invalid file key format"
6562
invalid_file_key_error_message = "Initial file validation failed: invalid file key"
@@ -105,3 +102,4 @@ def test_validate_file_key(self):
105102
with self.assertRaises(InvalidFileKeyError) as context:
106103
validate_file_key(file_key)
107104
self.assertEqual(str(context.exception), expected_result)
105+
_mock_hkeys.assert_called_with("vacc_to_diseases")

filenameprocessor/tests/test_lambda_handler.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"""Tests for lambda_handler"""
2-
import json
32
import sys
43
from unittest.mock import patch
54
from unittest import TestCase
65
from json import loads as json_loads
76
from contextlib import ExitStack
87
from copy import deepcopy
8+
from constants import VACCINE_TYPE_TO_DISEASES_HASH_KEY
9+
from elasticache import get_valid_vaccine_types_from_cache
910
import fakeredis
1011
from boto3 import client as boto3_client
1112
from moto import mock_s3, mock_sqs, mock_firehose, mock_dynamodb
@@ -20,10 +21,6 @@
2021
from tests.utils_for_tests.mock_environment_variables import MOCK_ENVIRONMENT_DICT, BucketNames, Sqs
2122
from tests.utils_for_tests.values_for_tests import MOCK_CREATED_AT_FORMATTED_STRING, MockFileDetails
2223

23-
from constants import VACCINE_TYPE_TO_DISEASES_HASH_KEY
24-
25-
from elasticache import get_valid_vaccine_types_from_cache
26-
2724
# Ensure environment variables are mocked before importing from src files
2825
with patch.dict("os.environ", MOCK_ENVIRONMENT_DICT):
2926
from file_name_processor import lambda_handler, handle_record

filenameprocessor/tests/test_logging_decorator.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ def setUp(self):
4848
GenericSetUp(s3_client, firehose_client, sqs_client, dynamodb_client)
4949
s3_client.put_object(Bucket=BucketNames.SOURCE, Key=FILE_DETAILS.file_key)
5050

51-
redis_patcher = patch("clients.redis_client.hkeys", return_value=["FLU", "COVID19", "MMR", "RSV"])
52-
self.addCleanup(redis_patcher.stop)
53-
redis_patcher.start()
54-
5551
def tearDown(self):
5652
"""Clean the mock AWS environment"""
5753
GenericTearDown(s3_client, firehose_client, sqs_client, dynamodb_client)
@@ -77,6 +73,7 @@ def run(self, result=None):
7773
# Time is incremented by 1.0 for each call to time.time for ease of testing.
7874
# Range is set to a large number (100) due to many calls being made to time.time for some tests.
7975
patch("logging_decorator.time.time", side_effect=[0.0 + i for i in range(100)]),
76+
patch("clients.redis_client.hkeys", return_value=["FLU"])
8077
]
8178

8279
# Set up the ExitStack. Note that patches need to be explicitly started so that they will be applied even when

0 commit comments

Comments
 (0)