Skip to content

Commit cbd5cb9

Browse files
committed
VED-386: recordprocessor filevalidation logic and dependency updates
1 parent 7b42dd4 commit cbd5cb9

File tree

7 files changed

+45
-18
lines changed

7 files changed

+45
-18
lines changed

.github/workflows/sonarcloud.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
id: filenameprocessor
4141
continue-on-error: true
4242
run: |
43-
poetry env use 3.10
43+
poetry env use 3.11
4444
poetry install
4545
poetry run coverage run -m unittest discover || echo "filenameprocessor tests failed" >> ../failed_tests.txt
4646
poetry run coverage xml -o ../filenameprocessor-coverage.xml
@@ -50,7 +50,7 @@ jobs:
5050
id: recordprocessor
5151
continue-on-error: true
5252
run: |
53-
poetry env use 3.10
53+
poetry env use 3.11
5454
poetry install
5555
poetry run coverage run -m unittest discover || echo "recordprocessor tests failed" >> ../failed_tests.txt
5656
poetry run coverage xml -o ../recordprocessor-coverage.xml

filenameprocessor/src/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ class Constants:
6060
"8J1100001": "PINNACLE",
6161
"8HK48": "SONAR",
6262
"YGA": "TPP",
63+
"V0V8L":"MAVIS",
64+
"X8E5B":"RAVS",
6365
"0DE": "AGEM-NIVS",
6466
"0DF": "NIMS",
6567
"8HA94": "EVA",
66-
"X26": "RAVS",
6768
"YGMYH": "MEDICAL_DIRECTOR",
6869
"W00": "WELSH_DA_1",
6970
"W000": "WELSH_DA_2",

recordprocessor/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM public.ecr.aws/lambda/python:3.10 AS base
1+
FROM public.ecr.aws/lambda/python:3.11 AS base
22

33
# Create a non-root user with a specific UID and GID
44
RUN mkdir -p /home/appuser && \

recordprocessor/src/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,8 @@ class ActionFlag(Enum):
9797
NEW = Permission.CREATE
9898
UPDATE = Permission.UPDATE
9999
DELETE = Permission.DELETE
100+
101+
102+
class AllowedPermission(Enum):
103+
CRUD = {"C", "U", "D"}
104+
CRUDS = {"C", "U", "D"}

recordprocessor/src/file_level_validation.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from errors import InvalidHeaders, NoOperationPermissions
1111
from logging_decorator import file_level_validation_logging_decorator
1212
from audit_table import change_audit_table_status_to_processed, get_next_queued_file_details
13-
from constants import SOURCE_BUCKET_NAME, EXPECTED_CSV_HEADERS, Permission, ActionFlag
13+
from constants import SOURCE_BUCKET_NAME, EXPECTED_CSV_HEADERS, Permission, ActionFlag, AllowedPermission
1414

1515

1616
def validate_content_headers(csv_content_reader) -> None:
@@ -43,21 +43,14 @@ def validate_action_flag_permissions(
4343
return set()
4444

4545
# Get allowed permission in single letters from allowed_permissions_list
46-
allowed_ops = set()
47-
for perm in allowed_permissions_list:
48-
if perm.startswith(f"{vaccine_type}."):
49-
allowed_ops.update(perm.split(".")[1])
50-
5146
allowed_ops = set()
5247
for perm in allowed_permissions_list:
5348
if not perm.startswith(f"{vaccine_type}."):
5449
continue
5550

5651
_, op_code = perm.split(".")
57-
if op_code == "CRUD":
58-
allowed_ops.update({"C", "R", "U", "D"})
59-
elif op_code == "CRUDS":
60-
allowed_ops.update({"C", "R", "U", "D", "S"})
52+
if op_code in AllowedPermission.__members__:
53+
allowed_ops.update(AllowedPermission[op_code].value)
6154
else:
6255
allowed_ops.add(op_code)
6356

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
import pandas as pd
22
from io import StringIO
3+
import logging
4+
5+
6+
logger = logging.getLogger(__name__)
37

48

59
def get_unique_action_flags_from_s3(csv_data):
610
"""
711
Reads the CSV file from an S3 bucket and returns a set of unique ACTION_FLAG values.
812
"""
913
# Load content into a pandas DataFrame
10-
df = pd.read_csv(StringIO(csv_data), delimiter="|", usecols=["ACTION_FLAG"])
14+
try:
15+
df = pd.read_csv(StringIO(csv_data), delimiter="|", usecols=["ACTION_FLAG"])
16+
except ValueError:
17+
logger.warning("ACTION_FLAG column missing or malformed in file.")
18+
return set()
19+
20+
if "ACTION_FLAG" not in df.columns:
21+
logger.warning("ACTION_FLAG column is missing in file.")
22+
return set()
1123
# Get unique ACTION_FLAG values in one step
12-
unique_action_flags = set(df["ACTION_FLAG"].str.upper().unique())
24+
unique_action_flags = set(
25+
df["ACTION_FLAG"]
26+
.dropna()
27+
.astype(str)
28+
.str.upper()
29+
.unique()
30+
)
1331
return unique_action_flags

recordprocessor/tests/test_file_level_validation.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_validate_action_flag_permissions(self):
9494

9595
# Case: Supplier has no permissions to perform any of the requested operations
9696
# Test case tuples are stuctured as (vaccine_type, vaccine_permissions, file_content)
97-
test_cases = [
97+
invalid_cases = [
9898
# FLU, no permissions
9999
("FLU", ["FLU.U", "COVID19.CRUDS"], valid_content_new_and_delete_lowercase),
100100
# COVID19, no permissions
@@ -103,11 +103,21 @@ def test_validate_action_flag_permissions(self):
103103
("RSV", ["FLU.C", "FLU.U"], valid_content_update_and_delete_lowercase),
104104
]
105105

106-
for vaccine_type, vaccine_permissions, file_content in test_cases:
106+
for vaccine_type, vaccine_permissions, file_content in invalid_cases:
107107
with self.subTest():
108108
with self.assertRaises(NoOperationPermissions):
109109
validate_action_flag_permissions("TEST_SUPPLIER", vaccine_type, vaccine_permissions, file_content)
110110

111+
no_flag_cases = [
112+
("FLU", ["FLU.C"], valid_file_content.replace("new", "").replace("update", "")),
113+
("COVID19", ["COVID19.CRUD"], valid_file_content.replace("new", "INVALID").replace("update", "")),
114+
]
115+
116+
for vaccine_type, permissions, file_content in no_flag_cases:
117+
with self.subTest(f"{vaccine_type} with invalid or missing ACTION_FLAGs"):
118+
result = validate_action_flag_permissions("TEST_SUPPLIER", vaccine_type, permissions, file_content)
119+
self.assertEqual(result, set())
120+
111121

112122
if __name__ == "__main__":
113123
unittest.main()

0 commit comments

Comments
 (0)