Skip to content

Commit a705b80

Browse files
committed
resolve sonar issues
1 parent b5ae016 commit a705b80

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

lambdas/shared/src/common/validator/expression_checker.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime
22
from decimal import Decimal
3-
from typing import Optional, Union
3+
from typing import Optional
44

55
from common.validator.constants.constants import Constants
66
from common.validator.constants.enums import MESSAGES, ExceptionLevels
@@ -37,8 +37,6 @@ def validate_expression(
3737
return self.validation_for_date_time(expression_rule, field_name, field_value)
3838
case "POSITIVEINTEGER":
3939
return self.validation_for_positive_integer(expression_rule, field_name, field_value)
40-
case "UNIQUELIST":
41-
return self.validation_for_unique_list(expression_rule, field_name, field_value)
4240
case "BOOLEAN":
4341
return self.validation_for_boolean(expression_rule, field_name, field_value)
4442
case "INTDECIMAL":
@@ -108,7 +106,7 @@ def validation_for_positive_integer(self, expression_rule, field_name, field_val
108106
return ErrorReport(ExceptionLevels.UNEXPECTED_EXCEPTION, message, None, field_name)
109107

110108
def validation_for_integer_or_decimal(
111-
self, _expression_rule, field_name: str, field_value: Union[int, Decimal]
109+
self, _expression_rule, field_name: str, field_value: int | Decimal
112110
) -> ErrorReport:
113111
"""
114112
Apply pre-validation to a decimal field to ensure that it is an integer or decimal,
@@ -131,24 +129,6 @@ def validation_for_integer_or_decimal(
131129
message = MESSAGES[ExceptionLevels.UNEXPECTED_EXCEPTION] % (e.__class__.__name__, e)
132130
return ErrorReport(ExceptionLevels.UNEXPECTED_EXCEPTION, message, None, field_name)
133131

134-
def validation_for_unique_list(
135-
list_to_check: list,
136-
unique_value_in_list: str,
137-
field_location: str,
138-
):
139-
"""
140-
Apply pre-validation to a list of dictionaries to ensure that a specified value in each
141-
dictionary is unique across the list
142-
"""
143-
found = []
144-
for item in list_to_check:
145-
if item[unique_value_in_list] in found:
146-
raise ValueError(
147-
f"{field_location.replace('FIELD_TO_REPLACE', item[unique_value_in_list])}" + " must be unique"
148-
)
149-
150-
found.append(item[unique_value_in_list])
151-
152132
def validation_for_boolean(self, expression_rule: str, field_name: str, field_value: str) -> ErrorReport:
153133
"""Apply pre-validation to a boolean field to ensure that it is a boolean"""
154134
try:
@@ -303,7 +283,7 @@ def validation_for_string_values(self, expression_rule: str, field_name: str, fi
303283
message = MESSAGES[ExceptionLevels.UNEXPECTED_EXCEPTION] % (e.__class__.__name__, e)
304284
return ErrorReport(ExceptionLevels.UNEXPECTED_EXCEPTION, message, None, field_name)
305285

306-
def validation_for_nhs_number(self, expression_rule: str, field_name: str, field_value: str) -> ErrorReport:
286+
def validation_for_nhs_number(self, _expression_rule: str, field_name: str, field_value: str) -> ErrorReport:
307287
"""
308288
Apply pre-validation to an NHS number to ensure that it is a valid NHS number
309289
"""
@@ -320,7 +300,7 @@ def validation_for_nhs_number(self, expression_rule: str, field_name: str, field
320300
message = MESSAGES[ExceptionLevels.UNEXPECTED_EXCEPTION] % (e.__class__.__name__, e)
321301
return ErrorReport(ExceptionLevels.UNEXPECTED_EXCEPTION, message, None, field_name)
322302

323-
def validation_for_snomed_code(self, expression_rule: str, field_location: str, field_value: str):
303+
def validation_for_snomed_code(self, _expression_rule: str, field_location: str, field_value: str):
324304
"""
325305
Apply prevalidation to snomed code to ensure that its a valid one.
326306
"""

lambdas/shared/src/common/validator/validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
class Validator:
19-
def __init__(self, schema_file: dict = {}):
19+
def __init__(self, schema_file: dict = None):
2020
self.schema_file = schema_file
2121
self.schema_parser = SchemaParser()
2222

0 commit comments

Comments
 (0)