Skip to content

Commit 4564aec

Browse files
committed
remove redundancy
1 parent 59a83a7 commit 4564aec

File tree

4 files changed

+11
-53
lines changed

4 files changed

+11
-53
lines changed

backend/src/models/fhir_immunization_pre_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def pre_validate_recorded(self, values: dict) -> dict:
519519
"""
520520
try:
521521
recorded = values["recorded"]
522-
PreValidation.for_recorded_date_time(recorded, "recorded")
522+
PreValidation.for_date_time(recorded, "recorded",strict_timezone=False)
523523
except KeyError:
524524
pass
525525

backend/src/models/utils/pre_validator_utils.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,6 @@ def for_date(field_value: str, field_location: str):
9696
raise ValueError(
9797
f'{field_location} must be a valid date string in the format "YYYY-MM-DD"'
9898
) from value_error
99-
100-
@staticmethod
101-
def for_recorded_date_time(field_value: str, field_location: str):
102-
"""
103-
Relaxed validator for the 'recorded' field.
104-
Accepts any timezone or no timezone.
105-
"""
106-
return PreValidation.for_date_time(field_value, field_location, strict_timezone=False)
107-
10899

109100
@staticmethod
110101
def for_date_time(field_value: str, field_location: str, strict_timezone: bool = True):

backend/tests/utils/pre_validation_test_utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,10 @@ def test_date_time_value(
363363
expected_error_message += f"Note that partial dates are not allowed for {field_location} in this service."
364364

365365
if is_occurrence_date_time:
366-
invalid_datetime_formats = InvalidValues.for_date_time_string_formats
367-
invalid_datetime_values = InvalidValues.for_date_times
366+
invalid_datetime_formats = InvalidValues.for_date_time_string_formats_for_strict_timezone
368367
else:
369368
# For recorded, skip values that are valid ISO with non-restricted timezone
370-
invalid_datetime_formats = InvalidValues.for_date_time_string_formats_for_recorded
371-
invalid_datetime_values = InvalidValues.for_date_times_for_recorded
369+
invalid_datetime_formats = InvalidValues.for_date_time_string_formats_for_relaxed_timezone
372370

373371
# Test invalid date time string formats
374372
for invalid_occurrence_date_time in invalid_datetime_formats:
@@ -381,7 +379,7 @@ def test_date_time_value(
381379
)
382380

383381
# Test invalid date times
384-
for invalid_occurrence_date_time in invalid_datetime_values:
382+
for invalid_occurrence_date_time in InvalidValues.for_date_times:
385383
test_invalid_values_rejected(
386384
test_instance,
387385
valid_json_data,

backend/tests/utils/values_for_tests.py

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class InvalidValues:
281281
]
282282

283283
# Strings which are not in acceptable date time format
284-
for_date_time_string_formats = [
284+
for_date_time_string_formats_for_relaxed_timezone = [
285285
"", # Empty string
286286
"invalid", # Invalid format
287287
"20000101", # Date digits only (i.e. without hypens)
@@ -290,10 +290,6 @@ class InvalidValues:
290290
"2000", # Year only
291291
"2000-01", # Year and month only
292292
"2000-01-01T00:00:00+00", # Date and time with GMT timezone offset only in hours
293-
"2000-01-01T00:00:00-00:00", # Date and time with negative GMT timezone offset
294-
"2000-01-01T00:00:00-01:00", # Date and time with negative GMT timezone offset
295-
"2000-01-01T00:00:00-05:00", # Date and time with negative offset asides from GMT and BST
296-
"2000-01-01T00:00:00+05:00", # Date and time with offset asides from GMT and BST
297293
"2000-01-01T00:00:00+01", # Date and time with BST timezone offset only in hours
298294
"12000-01-01T00:00:00+00:00", # Extra character at start of string
299295
"2000-01-01T00:00:00+00:001", # Extra character at end of string
@@ -302,7 +298,6 @@ class InvalidValues:
302298
"2000-01-0122:22:22+00:00.000", # Missing T (with milliseconds)
303299
"2000-01-01T222222+00:00", # Missing time colons
304300
"2000-01-01T22:22:2200:00", # Missing timezone indicator
305-
"2000-01-01T22:22:22-0100", # Missing timezone colon
306301
"2000-01-01T22:22:22-01", # Timezone hours only
307302
"99-01-01T00:00:00+00:00", # Missing century (i.e. only 2 digits for year)
308303
"01-01-2000T00:00:00+00:00", # Date in wrong order (DD-MM-YYYY)
@@ -323,40 +318,14 @@ class InvalidValues:
323318
"2000-01-01T00:00:00+00:60", # Timezone minute 60
324319
]
325320

326-
for_date_time_string_formats_for_recorded = [
327-
"", # Empty string
328-
"invalid", # Invalid format
329-
"20000101", # Date digits only (i.e. without hypens)
330-
"20000101000000", # Date and time digits only
331-
"200001010000000000", # Date, time and timezone digits only
332-
"2000", # Year only
333-
"2000-01", # Year and month only
334-
"2000-01-01T00:00:00+00", # Date and time with GMT timezone offset only in hours
335-
"2000-01-01T00:00:00+01", # Date and time with BST timezone offset only in hours
336-
"12000-01-01T00:00:00+00:00", # Extra character at start of string
337-
"2000-01-01T00:00:00+00:001", # Extra character at end of string
338-
"12000-01-02T00:00:00-01:001", # Extra characters at start and end of string
339-
"2000-01-0122:22:22+00:00", # Missing T
340-
"2000-01-0122:22:22+00:00.000", # Missing T (with milliseconds)
341-
"2000-01-01T222222+00:00", # Missing time colons
342-
"2000-01-01T22:22:2200:00", # Missing timezone indicator
343-
"2000-01-01T22:22:22-01", # Timezone hours only
344-
"99-01-01T00:00:00+00:00", # Missing century (i.e. only 2 digits for year)
345-
"01-01-2000T00:00:00+00:00", # Date in wrong order (DD-MM-YYYY)
346-
]
347-
348-
for_date_times_for_recorded = [
349-
"2000-00-01T00:00:00+00:00", # Month 00
350-
"2000-13-01T00:00:00+00:00", # Month 13
351-
"2000-01-32T00:00:00+00:00", # Day 32
352-
"2000-02-30T00:00:00+00:00", # Invalid month and day combination (30th February)
353-
"2000-01-01T24:00:00+00:00", # Hour 24
354-
"2000-01-01T00:60:00+00:00", # Minute 60
355-
"2000-01-01T00:00:60+00:00", # Second 60
356-
"2000-01-01T00:00:00+00:60", # Timezone minute 60
321+
for_date_time_string_formats_for_strict_timezone = for_date_time_string_formats_for_relaxed_timezone + [
322+
"2000-01-01T22:22:22-0100", # Missing timezone colon
323+
"2000-01-01T00:00:00-01:00", # Date and time with negative GMT timezone offset
324+
"2000-01-01T00:00:00-05:00", # Date and time with negative offset asides from GMT and BST
325+
"2000-01-01T00:00:00+05:00", # Date and time with offset asides from GMT and BST
326+
"2000-01-01T00:00:00-00:00", # Date and time with negative GMT timezone offset
357327
]
358328

359-
360329
for_lists_of_strings_of_length_1 = [[1], [False], [["Test1"]]]
361330

362331
for_lists_of_dicts_of_length_1 = [[1], [False], [["Invalid"]], ["Invalid"]]

0 commit comments

Comments
 (0)