Skip to content

Commit 8b45b8e

Browse files
committed
Fixed lint issue
1 parent dcc1297 commit 8b45b8e

File tree

5 files changed

+49
-46
lines changed

5 files changed

+49
-46
lines changed

recordprocessor/tests/test_make_and_upload_ack_file.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
FILE_DETAILS = MockFileDetails.flu_emis
2121

22+
2223
@mock_s3
2324
@patch.dict("os.environ", MOCK_ENVIRONMENT_DICT)
2425
class TestMakeAndUploadAckFile(unittest.TestCase):
@@ -91,32 +92,32 @@ def test_make_ack_data(self):
9192
make_ack_data(
9293
self.message_id, validation_passed, message_delivered, self.created_at_formatted_string
9394
),
94-
expected_result,
95-
)
95+
expected_result,
96+
)
9697

9798
def test_upload_ack_file_success(self):
98-
"""Test that upload_ack_file successfully uploads the ack file"""
99-
99+
"""Test that upload_ack_file successfully uploads the ack file"""
100+
100101
upload_ack_file(
101102
file_key=FILE_DETAILS.file_key,
102103
ack_data=deepcopy(self.ack_data_validation_passed_and_message_delivered),
103104
created_at_formatted_string=FILE_DETAILS.created_at_formatted_string,
104105
)
105-
expected_result = [deepcopy(self.ack_data_validation_passed_and_message_delivered)]
106+
expected_result = [deepcopy(self.ack_data_validation_passed_and_message_delivered)]
106107
# Note that the data downloaded from the CSV will contain the bool as a string
107108
expected_result[0]["MESSAGE_DELIVERY"] = "True"
108109
csv_dict_reader = get_csv_file_dict_reader(s3_client, BucketNames.DESTINATION, FILE_DETAILS.inf_ack_file_key)
109110
self.assertEqual(list(csv_dict_reader), expected_result)
110111

111112
def test_upload_ack_file_failure(self):
112-
"""Test that upload_ack_file failed to upload the ack file"""
113-
113+
"""Test that upload_ack_file failed to upload the ack file"""
114+
114115
upload_ack_file(
115116
file_key=FILE_DETAILS.file_key,
116117
ack_data=deepcopy(self.ack_data_validation_passed_and_message_not_delivered),
117118
created_at_formatted_string=FILE_DETAILS.created_at_formatted_string,
118119
)
119-
expected_result = [deepcopy(self.ack_data_validation_passed_and_message_not_delivered)]
120+
expected_result = [deepcopy(self.ack_data_validation_passed_and_message_not_delivered)]
120121
# Note that the data downloaded from the CSV will contain the bool as a string
121122
expected_result[0]["MESSAGE_DELIVERY"] = "False"
122123
csv_dict_reader = get_csv_file_dict_reader(s3_client, BucketNames.DESTINATION, FILE_DETAILS.inf_ack_file_key)
@@ -138,7 +139,6 @@ def test_make_and_upload_ack_file_success(self):
138139
csv_dict_reader = get_csv_file_dict_reader(s3_client, BucketNames.DESTINATION, FILE_DETAILS.inf_ack_file_key)
139140
self.assertEqual(list(csv_dict_reader), expected_result)
140141

141-
142142
def test_make_and_upload_ack_file_failure(self):
143143
"""Test that make_and_upload_ack_file failed to upload an ack file containing the correct values"""
144144
make_and_upload_ack_file(

recordprocessor/tests/test_process_row.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
from decimal import Decimal
99

1010

11-
from tests.utils_for_recordprocessor_tests.values_for_recordprocessor_tests import (
11+
from tests.utils_for_recordprocessor_tests.values_for_recordprocessor_tests import (
1212
MockFieldDictionaries,
13-
MockFileRows,
1413
)
1514

1615
from tests.utils_for_recordprocessor_tests.utils_for_recordprocessor_tests import (
@@ -22,14 +21,14 @@
2221
with patch("os.environ", MOCK_ENVIRONMENT_DICT):
2322
# Do not attempt 'from src.mappings import Vaccine' as this imports a different instance of Vaccine
2423
# and tests will break
25-
from mappings import Vaccine
2624
from clients import REGION_NAME
2725
from src.process_row import process_row
2826

2927
s3_client = boto3_client("s3", region_name=REGION_NAME)
3028
ROW_DETAILS = MockFieldDictionaries.all_fields
3129
Allowed_Operations = {'CREATE', 'UPDATE', 'DELETE'}
3230

31+
3332
@mock_s3
3433
@patch.dict("os.environ", MOCK_ENVIRONMENT_DICT)
3534
class TestProcessRow(unittest.TestCase):
@@ -43,23 +42,26 @@ def tearDown(self) -> None:
4342

4443
def test_process_row_success(self):
4544
"""
46-
Test that process_row gives the expected output. These tests check that the row is valid and matches the expected output.
45+
Test that process_row gives the expected output.
46+
These tests check that the row is valid and matches the expected output.
4747
"""
48-
# set the expected output from 'process_row' in case of success
49-
expected_result = {'resourceType': 'Immunization', 'status': 'completed', 'protocolApplied': [{'targetDisease': [], 'doseNumberPositiveInt': 1}], 'reasonCode': [{'coding': [{'system': 'http://snomed.info/sct', 'code': '1037351000000105'}]}], 'recorded': '2024-09-04', 'identifier': [{'value': 'RSV_002', 'system': 'https://www.ravs.england.nhs.uk/'}], 'patient': {'reference': '#Patient1'}, 'contained': [{'id': 'Patient1', 'resourceType': 'Patient', 'birthDate': '2008-02-17', 'gender': 'male', 'address': [{'postalCode': 'WD25 0DZ'}], 'identifier': [{'system': 'https://fhir.nhs.uk/Id/nhs-number', 'value': '9732928395'}], 'name': [{'family': 'PEEL', 'given': ['PHYLIS']}]}, {'resourceType': 'Practitioner', 'id': 'Practitioner1', 'name': [{'family': "O'Reilly", 'given': ['Ellena']}]}], 'vaccineCode': {'coding': [{'system': 'http://snomed.info/sct', 'code': '42223111000001107', 'display': 'Quadrivalent influenza vaccine (split virion, inactivated)'}]}, 'manufacturer': {'display': 'Sanofi Pasteur'}, 'expirationDate': '2024-09-15', 'lotNumber': 'BN92478105653', 'extension': [{'url': 'https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationProcedure', 'valueCodeableConcept': {'coding': [{'system': 'http://snomed.info/sct', 'code': '956951000000104', 'display': 'RSV vaccination in pregnancy (procedure)'}]}}], 'occurrenceDateTime': '2024-09-04T18:33:25+00:00', 'primarySource': True, 'site': {'coding': [{'system': 'http://snomed.info/sct', 'code': '368209003', 'display': 'Right arm'}]}, 'route': {'coding': [{'system': 'http://snomed.info/sct', 'code': '1210999013', 'display': 'Intradermal use'}]}, 'doseQuantity': {'value': Decimal('0.3'), 'unit': 'Inhalation - unit of product usage', 'system': 'http://snomed.info/sct', 'code': '2622896019'}, 'performer': [{'actor': {'type': 'Organization', 'identifier': {'system': 'https://fhir.nhs.uk/Id/ods-organization-code', 'value': 'RVVKC'}}}, {'actor': {'reference': '#Practitioner1'}}], 'location': {'identifier': {'value': 'RJC02', 'system': 'https://fhir.nhs.uk/Id/ods-organization-code'}}}
48+
# set the expected output from 'process_row' in case of success
49+
expected_result = {'resourceType': 'Immunization', 'status': 'completed', 'protocolApplied': [{'targetDisease': [], 'doseNumberPositiveInt': 1}], 'reasonCode': [{'coding': [{'system': 'http://snomed.info/sct', 'code': '1037351000000105'}]}], 'recorded': '2024-09-04', 'identifier': [{'value': 'RSV_002', 'system': 'https://www.ravs.england.nhs.uk/'}], 'patient': {'reference': '#Patient1'}, 'contained': [{'id': 'Patient1', 'resourceType': 'Patient', 'birthDate': '2008-02-17', 'gender': 'male', 'address': [{'postalCode': 'WD25 0DZ'}], 'identifier': [{'system': 'https://fhir.nhs.uk/Id/nhs-number', 'value': '9732928395'}], 'name': [{'family': 'PEEL', 'given': ['PHYLIS']}]}, {'resourceType': 'Practitioner', 'id': 'Practitioner1', 'name': [{'family': "O'Reilly", 'given': ['Ellena']}]}], 'vaccineCode': {'coding': [{'system': 'http://snomed.info/sct', 'code': '42223111000001107', 'display': 'Quadrivalent influenza vaccine (split virion, inactivated)'}]}, 'manufacturer': {'display': 'Sanofi Pasteur'}, 'expirationDate': '2024-09-15', 'lotNumber': 'BN92478105653', 'extension': [{'url': 'https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationProcedure', 'valueCodeableConcept': {'coding': [{'system': 'http://snomed.info/sct', 'code': '956951000000104', 'display': 'RSV vaccination in pregnancy (procedure)'}]}}], 'occurrenceDateTime': '2024-09-04T18:33:25+00:00', 'primarySource': True, 'site': {'coding': [{'system': 'http://snomed.info/sct', 'code': '368209003', 'display': 'Right arm'}]}, 'route': {'coding': [{'system': 'http://snomed.info/sct', 'code': '1210999013', 'display': 'Intradermal use'}]}, 'doseQuantity': {'value': Decimal('0.3'), 'unit': 'Inhalation - unit of product usage', 'system': 'http://snomed.info/sct', 'code': '2622896019'},
50+
'performer': [{'actor': {'type': 'Organization', 'identifier': {'system': 'https://fhir.nhs.uk/Id/ods-organization-code', 'value': 'RVVKC'}}}, {'actor': {'reference': '#Practitioner1'}}], 'location': {'identifier': {'value': 'RJC02', 'system': 'https://fhir.nhs.uk/Id/ods-organization-code'}}}
5051

5152
# call 'process_row' with required details
5253
imms_fhir_resource = process_row("EMIS", Allowed_Operations, ROW_DETAILS)
5354
# validate if the response with expected result
5455
self.assertDictEqual(imms_fhir_resource["fhir_json"], expected_result)
55-
56+
5657
def test_process_row_invalid_action_flag(self):
5758
"""
58-
Test that process_row gives the expected output. These tests check that the row is valid and matches the expected output.
59+
Test that process_row gives the expected output.
60+
These tests check that the row is valid and matches the expected output.
5961
"""
6062
Mock_Row = deepcopy(ROW_DETAILS)
6163
# setting up the invalid action flag other than 'NEW', 'UPDATE' or 'DELETE'
62-
Mock_Row['ACTION_FLAG'] = 'Invalid'
64+
Mock_Row['ACTION_FLAG'] = 'Invalid'
6365

6466
# call 'process_row' with required details
6567
response = process_row("EMIS", Allowed_Operations, Mock_Row)
@@ -69,12 +71,13 @@ def test_process_row_invalid_action_flag(self):
6971

7072
def test_process_row_missing_action_flag(self):
7173
"""
72-
Test that process_row gives the expected output. These tests check that the row is valid and matches the expected output.
74+
Test that process_row gives the expected output.
75+
These tests check that the row is valid and matches the expected output.
7376
"""
7477

7578
Mock_Row = deepcopy(ROW_DETAILS)
76-
# removing action flag from row
77-
Mock_Row.pop('ACTION_FLAG')
79+
# removing action flag from row
80+
Mock_Row.pop('ACTION_FLAG')
7881

7982
# call 'process_row' with required details
8083
response = process_row("EMIS", Allowed_Operations, Mock_Row)
@@ -83,26 +86,27 @@ def test_process_row_missing_action_flag(self):
8386

8487
def test_process_row_missing_permission(self):
8588
"""
86-
Test that process_row gives the expected output. These tests check that the row is valid and matches the expected output.
89+
Test that process_row gives the expected output.
90+
These tests check that the row is valid and matches the expected output.
8791
"""
8892
# only create and delete permission. Missing update
89-
allowed_operation = {'CREATE', 'DELETE'}
93+
allowed_operation = {'CREATE', 'DELETE'}
9094
# copy row data with Action_Flag = 'Update'
91-
Mock_Row = deepcopy(ROW_DETAILS)
95+
Mock_Row = deepcopy(ROW_DETAILS)
9296

9397
# call 'process_row' with required details
9498
response = process_row("EMIS", allowed_operation, Mock_Row)
95-
9699
self.assertEqual(response['diagnostics']['error_type'], 'NO_PERMISSIONS')
97100
self.assertEqual(response['diagnostics']['statusCode'], 403)
98101

99102
def test_process_row_missing_unique_id(self):
100103
"""
101-
Test that process_row gives the expected output. These tests check that the row is valid and matches the expected output.
104+
Test that process_row gives the expected output.
105+
These tests check that the row is valid and matches the expected output.
102106
"""
103107
# copy row data and remove 'UNIQUE_ID'
104-
Mock_Row = deepcopy(ROW_DETAILS)
105-
Mock_Row.pop('UNIQUE_ID')
108+
Mock_Row = deepcopy(ROW_DETAILS)
109+
Mock_Row.pop('UNIQUE_ID')
106110
# call 'process_row' with required details
107111
response = process_row("EMIS", Allowed_Operations, Mock_Row)
108112

@@ -111,14 +115,15 @@ def test_process_row_missing_unique_id(self):
111115

112116
def test_process_row_missing_unique_id_uri(self):
113117
"""
114-
Test that process_row gives the expected output. These tests check that the row is valid and matches the expected output.
118+
Test that process_row gives the expected output.
119+
These tests check that the row is valid and matches the expected output.
115120
"""
116121
# copy row data and remove 'UNIQUE_ID_URI'
117-
Mock_Row = deepcopy(ROW_DETAILS)
118-
Mock_Row.pop('UNIQUE_ID_URI')
122+
Mock_Row = deepcopy(ROW_DETAILS)
123+
Mock_Row.pop('UNIQUE_ID_URI')
119124
# call 'process_row' with required details
120125
response = process_row("EMIS", Allowed_Operations, Mock_Row)
121-
126+
122127
self.assertEqual(response['diagnostics']['error_message'], 'UNIQUE_ID or UNIQUE_ID_URI is missing')
123128
self.assertEqual(response['diagnostics']['statusCode'], 400)
124129

recordprocessor/tests/test_send_to_kinesis.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
from unittest.mock import patch
33
from moto import mock_kinesis
44
from boto3 import client as boto3_client
5-
from src.send_to_kinesis import send_to_kinesis
65

76
from tests.utils_for_recordprocessor_tests.utils_for_recordprocessor_tests import (
87
GenericSetUp,
98
GenericTearDown,
109
)
11-
from tests.utils_for_recordprocessor_tests.values_for_recordprocessor_tests import (
10+
from tests.utils_for_recordprocessor_tests.values_for_recordprocessor_tests import (
1211
REGION_NAME,
1312
)
1413
from tests.utils_for_recordprocessor_tests.mock_environment_variables import MOCK_ENVIRONMENT_DICT
@@ -27,10 +26,10 @@ def setUp(self) -> None:
2726

2827
def tearDown(self) -> None:
2928
GenericTearDown(None, None, kinesis_client)
30-
29+
3130
@patch.dict("os.environ", MOCK_ENVIRONMENT_DICT)
32-
def test_send_to_kinesis_success(self):
33-
31+
def test_send_to_kinesis_success(self):
32+
3433
kinesis_client.return_value = {'ResponseMetadata': {'HTTPStatusCode': 200}}
3534

3635
# arrange required parameters
@@ -39,8 +38,8 @@ def test_send_to_kinesis_success(self):
3938
vaccine_type = "test_vaccine"
4039

4140
result = send_to_kinesis(supplier, message_body, vaccine_type)
42-
self.assertTrue(result)
43-
41+
self.assertTrue(result)
42+
4443

4544
if __name__ == '__main__':
46-
unittest.main()
45+
unittest.main()

recordprocessor/tests/test_unique_permission.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
import unittest
44

55
from src.unique_permission import get_unique_action_flags_from_s3
6-
from tests.utils_for_recordprocessor_tests.values_for_recordprocessor_tests import MockFileDetails, ValidMockFileContent
6+
from tests.utils_for_recordprocessor_tests.values_for_recordprocessor_tests import ValidMockFileContent
7+
78

89
class TestGetUniqueFlagsFromS3(unittest.TestCase):
910
def test_get_unique_action_flags_from_s3(self):
1011
csv_data = ValidMockFileContent.with_new_and_update_and_delete
12+
13+
# set the expected result
1114
expected_output = {"NEW", "UPDATE", "DELETE"}
12-
1315
result = get_unique_action_flags_from_s3(csv_data)
14-
1516
self.assertEqual(result, expected_output)
1617

17-
18-
1918
if __name__ == '__main__':
2019
unittest.main()
21-

recordprocessor/tests/utils_for_recordprocessor_tests/utils_for_recordprocessor_tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def convert_string_to_dict_reader(data_string: str):
1010
"""Take a data string and convert it to a csv DictReader"""
1111
return DictReader(StringIO(data_string), delimiter="|")
1212

13+
1314
def get_csv_file_dict_reader(s3_client, bucket_name: str, file_key: str) -> DictReader:
1415
"""Download the file from the S3 bucket and return it as a DictReader"""
1516
ack_file_csv_obj = s3_client.get_object(Bucket=bucket_name, Key=file_key)

0 commit comments

Comments
 (0)