Skip to content

Commit 2ebff30

Browse files
committed
lint
1 parent 3ca621d commit 2ebff30

File tree

10 files changed

+69
-44
lines changed

10 files changed

+69
-44
lines changed

lambdas/ack_backend/src/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44

55
AUDIT_TABLE_NAME = os.getenv("AUDIT_TABLE_NAME")
66

7+
78
def get_source_bucket_name() -> str:
89
"""Get the SOURCE_BUCKET_NAME environment from environment variables."""
910
return os.getenv("SOURCE_BUCKET_NAME")
1011

12+
1113
def get_ack_bucket_name() -> str:
1214
"""Get the ACK_BUCKET_NAME environment from environment variables."""
1315
return os.getenv("ACK_BUCKET_NAME")
1416

17+
1518
class FileStatus:
1619
"""File status constants"""
1720

lambdas/ack_backend/tests/test_ack_processor.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,13 @@ def test_lambda_handler_main_multiple_records(self):
113113
response = lambda_handler(event=event, context={})
114114

115115
self.assertEqual(response, EXPECTED_ACK_LAMBDA_RESPONSE_FOR_SUCCESS)
116-
validate_ack_file_content(self.s3_client,
117-
[*array_of_success_messages, *array_of_failure_messages, *array_of_mixed_success_and_failure_messages],
116+
validate_ack_file_content(
117+
self.s3_client,
118+
[
119+
*array_of_success_messages,
120+
*array_of_failure_messages,
121+
*array_of_mixed_success_and_failure_messages
122+
],
118123
existing_file_content=ValidValues.ack_headers,
119124
)
120125

@@ -169,7 +174,10 @@ def test_lambda_handler_main(self):
169174
# TODO: None of the test cases have any existing ack file content?
170175
with self.subTest(msg=f"Existing ack file: {test_case['description']}"):
171176
existing_ack_file_content = test_case.get("existing_ack_file_content", "")
172-
setup_existing_ack_file(MOCK_MESSAGE_DETAILS.temp_ack_file_key, existing_ack_file_content, self.s3_client)
177+
setup_existing_ack_file(
178+
MOCK_MESSAGE_DETAILS.temp_ack_file_key,
179+
existing_ack_file_content, self.s3_client
180+
)
173181
response = lambda_handler(event=self.generate_event(test_case["messages"]), context={})
174182
self.assertEqual(response, EXPECTED_ACK_LAMBDA_RESPONSE_FOR_SUCCESS)
175183
validate_ack_file_content(self.s3_client, test_case["messages"], existing_ack_file_content)

lambdas/ack_backend/tests/test_audit_table.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import unittest
2-
from unittest.mock import patch, MagicMock
2+
from unittest.mock import patch
33
import audit_table
44
from common.models.errors import UnhandledAuditTableError
55

6+
67
class TestAuditTable(unittest.TestCase):
78

89
def setUp(self):

lambdas/ack_backend/tests/test_logging_decorators.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import unittest
2-
from unittest.mock import patch, MagicMock, call
2+
from unittest.mock import patch
33
import logging_decorators
4-
import json
54
import time
65

6+
77
class TestLoggingDecorators(unittest.TestCase):
88
def setUp(self):
99
# Patch logger and firehose_client
@@ -127,5 +127,6 @@ def dummy_lambda(event, context):
127127
self.mock_logger.error.assert_called()
128128
self.mock_firehose.put_record.assert_called()
129129

130+
130131
if __name__ == "__main__":
131-
unittest.main()
132+
unittest.main()

lambdas/ack_backend/tests/test_splunk_logging.py

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ def test_splunk_logging_successful_rows(self):
104104
"""Tests a single object in the body of the event"""
105105

106106
for operation in ["CREATE", "UPDATE", "DELETE"]:
107-
with (
108-
patch("logging_decorators.send_log_to_firehose") as mock_send_log_to_firehose,
109-
patch("logging_decorators.logger") as mock_logger,
110-
):
107+
with ( # noqa: E999
108+
patch("logging_decorators.send_log_to_firehose") as mock_send_log_to_firehose, # noqa: E999
109+
patch("logging_decorators.logger") as mock_logger, # noqa: E999
110+
): # noqa: E999
111111
result = lambda_handler(event=generate_event([{"operation_requested": operation}]), context={})
112112

113113
self.assertEqual(result, {"statusCode": 200, "body": json.dumps("Lambda function executed successfully!")})
@@ -132,17 +132,18 @@ def test_splunk_logging_successful_rows(self):
132132
def test_splunk_logging_missing_data(self):
133133
"""Tests missing key values in the body of the event"""
134134

135-
with (
136-
patch("logging_decorators.send_log_to_firehose") as mock_send_log_to_firehose,
137-
patch("logging_decorators.logger") as mock_logger,
138-
):
135+
with ( # noqa: E999
136+
patch("logging_decorators.send_log_to_firehose") as mock_send_log_to_firehose, # noqa: E999
137+
patch("logging_decorators.logger") as mock_logger, # noqa: E999
138+
): # noqa: E999
139139
with self.assertRaises(Exception):
140140
lambda_handler(event={"Records": [{"body": json.dumps([{"": "456"}])}]}, context={})
141141

142142
expected_first_logger_info_data = {**InvalidValues.Logging_with_no_values}
143143

144144
expected_first_logger_error_data = self.expected_lambda_handler_logs(
145-
success=False, number_of_rows=1, ingestion_complete=False, diagnostics="'NoneType' object has no attribute 'replace'"
145+
success=False, number_of_rows=1, ingestion_complete=False,
146+
diagnostics="'NoneType' object has no attribute 'replace'"
146147
)
147148

148149
first_logger_info_call_args = json.loads(self.extract_all_call_args_for_logger_info(mock_logger)[0])
@@ -171,10 +172,10 @@ def test_splunk_logging_statuscode_diagnostics(
171172
]
172173

173174
for test_case in test_cases:
174-
with (
175-
patch("logging_decorators.send_log_to_firehose") as mock_send_log_to_firehose,
176-
patch("logging_decorators.logger") as mock_logger,
177-
):
175+
with ( # noqa: E999
176+
patch("logging_decorators.send_log_to_firehose") as mock_send_log_to_firehose, # noqa: E999
177+
patch("logging_decorators.logger") as mock_logger, # noqa: E999
178+
): # noqa: E999
178179
result = lambda_handler(event=generate_event([{"diagnostics": test_case["diagnostics"]}]), context={})
179180

180181
self.assertEqual(result, EXPECTED_ACK_LAMBDA_RESPONSE_FOR_SUCCESS)
@@ -202,10 +203,10 @@ def test_splunk_logging_multiple_rows(self):
202203
"""Tests logging for multiple objects in the body of the event"""
203204
messages = [{"row_id": "test1"}, {"row_id": "test2"}]
204205

205-
with (
206-
patch("logging_decorators.send_log_to_firehose") as mock_send_log_to_firehose,
207-
patch("logging_decorators.logger") as mock_logger,
208-
):
206+
with ( # noqa: E999
207+
patch("logging_decorators.send_log_to_firehose") as mock_send_log_to_firehose, # noqa: E999
208+
patch("logging_decorators.logger") as mock_logger, # noqa: E999
209+
): # noqa: E999
209210
result = lambda_handler(generate_event(messages), context={})
210211

211212
self.assertEqual(result, EXPECTED_ACK_LAMBDA_RESPONSE_FOR_SUCCESS)
@@ -252,10 +253,10 @@ def test_splunk_logging_multiple_with_diagnostics(
252253
{"row_id": "test3", "operation_requested": "DELETE", "diagnostics": DiagnosticsDictionaries.NO_PERMISSIONS},
253254
]
254255

255-
with (
256-
patch("logging_decorators.send_log_to_firehose") as mock_send_log_to_firehose,
257-
patch("logging_decorators.logger") as mock_logger,
258-
):
256+
with ( # noqa: E999
257+
patch("logging_decorators.send_log_to_firehose") as mock_send_log_to_firehose, # noqa: E999
258+
patch("logging_decorators.logger") as mock_logger, # noqa: E999
259+
): # noqa: E999
259260
result = lambda_handler(generate_event(messages), context={})
260261

261262
self.assertEqual(result, EXPECTED_ACK_LAMBDA_RESPONSE_FOR_SUCCESS)
@@ -317,11 +318,12 @@ def test_splunk_update_ack_file_not_logged(self):
317318
message_value = "test" + str(i)
318319
messages.append({"row_id": message_value})
319320

320-
with (
321-
patch("logging_decorators.send_log_to_firehose") as mock_send_log_to_firehose,
322-
patch("logging_decorators.logger") as mock_logger,
323-
patch("update_ack_file.change_audit_table_status_to_processed") as mock_change_audit_table_status_to_processed,
324-
):
321+
with ( # noqa: E999
322+
patch("logging_decorators.send_log_to_firehose") as mock_send_log_to_firehose, # noqa: E999
323+
patch("logging_decorators.logger") as mock_logger, # noqa: E999
324+
patch("update_ack_file.change_audit_table_status_to_processed")
325+
as mock_change_audit_table_status_to_processed, # noqa: E999
326+
): # noqa: E999
325327
result = lambda_handler(generate_event(messages), context={})
326328

327329
self.assertEqual(result, EXPECTED_ACK_LAMBDA_RESPONSE_FOR_SUCCESS)
@@ -347,7 +349,6 @@ def test_splunk_update_ack_file_not_logged(self):
347349
)
348350
mock_change_audit_table_status_to_processed.assert_not_called()
349351

350-
351352
def test_splunk_update_ack_file_logged(self):
352353
"""Tests that update_ack_file is logged if we have sent acks for the whole file"""
353354
# send 99 messages
@@ -356,11 +357,12 @@ def test_splunk_update_ack_file_logged(self):
356357
message_value = "test" + str(i)
357358
messages.append({"row_id": message_value})
358359

359-
with (
360-
patch("logging_decorators.send_log_to_firehose") as mock_send_log_to_firehose,
361-
patch("logging_decorators.logger") as mock_logger,
362-
patch("update_ack_file.change_audit_table_status_to_processed") as mock_change_audit_table_status_to_processed,
363-
):
360+
with ( # noqa: E999
361+
patch("logging_decorators.send_log_to_firehose") as mock_send_log_to_firehose, # noqa: E999
362+
patch("logging_decorators.logger") as mock_logger, # noqa: E999
363+
patch("update_ack_file.change_audit_table_status_to_processed")
364+
as mock_change_audit_table_status_to_processed, # noqa: E999
365+
): # noqa: E999
364366
result = lambda_handler(generate_event(messages), context={})
365367

366368
self.assertEqual(result, EXPECTED_ACK_LAMBDA_RESPONSE_FOR_SUCCESS)
@@ -374,7 +376,9 @@ def test_splunk_update_ack_file_logged(self):
374376
"message_id": "test1",
375377
"time_taken": "1.0s"
376378
}
377-
expected_last_logger_info_data = self.expected_lambda_handler_logs(success=True, number_of_rows=99, ingestion_complete=True)
379+
expected_last_logger_info_data = self.expected_lambda_handler_logs(
380+
success=True, number_of_rows=99, ingestion_complete=True
381+
)
378382

379383
all_logger_info_call_args = self.extract_all_call_args_for_logger_info(mock_logger)
380384
thirdlast_logger_info_call_args = json.loads(all_logger_info_call_args[98])

lambdas/ack_backend/tests/test_update_ack_file.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,5 +207,6 @@ def test_obtain_current_ack_content_file_exists(self):
207207
result = obtain_current_ack_content(MOCK_MESSAGE_DETAILS.temp_ack_file_key)
208208
self.assertEqual(result.getvalue(), existing_content)
209209

210+
210211
if __name__ == "__main__":
211212
unittest.main()

lambdas/ack_backend/tests/test_update_ack_file_flow.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ def setUp(self):
1919
self.ack_bucket_patcher = patch('update_ack_file.get_ack_bucket_name', return_value=self.ack_bucket_name)
2020
self.mock_get_ack_bucket_name = self.ack_bucket_patcher.start()
2121

22-
self.source_bucket_patcher = patch('update_ack_file.get_source_bucket_name', return_value=self.source_bucket_name)
22+
self.source_bucket_patcher = patch(
23+
'update_ack_file.get_source_bucket_name',
24+
return_value=self.source_bucket_name
25+
)
2326
self.mock_get_source_bucket_name = self.source_bucket_patcher.start()
2427

2528
self.s3_client.create_bucket(

lambdas/ack_backend/tests/utils/utils_for_ack_backend_tests.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ def generate_expected_ack_content(
9292
return existing_content
9393

9494

95-
def validate_ack_file_content(s3_client,
96-
incoming_messages: list[dict], existing_file_content: str = ValidValues.ack_headers
95+
def validate_ack_file_content(
96+
s3_client,
97+
incoming_messages: list[dict],
98+
existing_file_content: str = ValidValues.ack_headers
9799
) -> None:
98100
"""
99101
Obtains the ack file content and ensures that it matches the expected content (expected content is based

lambdas/ack_backend/tests/utils/values_for_ack_backend_tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ class ValidValues:
246246
}
247247

248248

249-
250249
class InvalidValues:
251250
"""Invalid values for use in tests"""
252251

lambdas/shared/src/common/clients.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616

1717
# for lambdas which require a global s3_client
1818
global_s3_client = None
19+
20+
1921
def get_s3_client():
2022
global global_s3_client
2123
if global_s3_client is None:
2224
global_s3_client = boto3_client("s3", region_name=REGION_NAME)
2325
return global_s3_client
2426

27+
2528
firehose_client = boto3_client("firehose", region_name=REGION_NAME)
2629
secrets_manager_client = boto3_client("secretsmanager", region_name=REGION_NAME)
2730
dynamodb_client = boto3_client("dynamodb", region_name=REGION_NAME)

0 commit comments

Comments
 (0)