Skip to content

Commit 4a59115

Browse files
committed
valid values test
1 parent 4564aec commit 4a59115

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

backend/tests/utils/pre_validation_test_utils.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,29 @@ def test_date_time_value(
328328
* Invalid date time string formats
329329
* Invalid date-times
330330
"""
331+
expected_error_message = (
332+
f"{field_location} must be a valid datetime in one of the following formats:"
333+
"- 'YYYY-MM-DD' — Full date only"
334+
"- 'YYYY-MM-DDThh:mm:ss' — Full date and time without milliseconds"
335+
"- 'YYYY-MM-DDThh:mm:ss.f' — Full date and time with milliseconds (any level of precision)"
336+
"- 'YYYY-MM-DDThh:mm:ss%z' — Full date and time with timezone (e.g. +00:00 or +01:00)"
337+
"- 'YYYY-MM-DDThh:mm:ss.f%z' — Full date and time with milliseconds and timezone"
338+
)
339+
340+
if is_occurrence_date_time:
341+
expected_error_message += "Only '+00:00' and '+01:00' are accepted as valid timezone offsets.\n"
342+
expected_error_message += f"Note that partial dates are not allowed for {field_location} in this service."
343+
valid_datetime_formats = ValidValues.for_date_times_strict_timezones
344+
invalid_datetime_formats = InvalidValues.for_date_time_string_formats_for_strict_timezone
345+
else:
346+
# For recorded, skip values that are valid ISO with non-restricted timezone
347+
valid_datetime_formats = ValidValues.for_date_times_relaxed_timezones
348+
invalid_datetime_formats = InvalidValues.for_date_time_string_formats_for_relaxed_timezone
331349

332350
valid_json_data = deepcopy(test_instance.json_data)
333351

334352
# Test that valid data is accepted
335-
test_valid_values_accepted(test_instance, valid_json_data, field_location, ValidValues.for_date_times)
353+
test_valid_values_accepted(test_instance, valid_json_data, field_location, valid_datetime_formats)
336354

337355
# Set list of invalid data types to test
338356
invalid_data_types_for_strings = InvalidDataTypes.for_strings
@@ -349,25 +367,6 @@ def test_date_time_value(
349367
expected_error_message=f"{field_location} must be a string",
350368
)
351369

352-
expected_error_message = (
353-
f"{field_location} must be a valid datetime in one of the following formats:"
354-
"- 'YYYY-MM-DD' — Full date only"
355-
"- 'YYYY-MM-DDThh:mm:ss' — Full date and time without milliseconds"
356-
"- 'YYYY-MM-DDThh:mm:ss.f' — Full date and time with milliseconds (any level of precision)"
357-
"- 'YYYY-MM-DDThh:mm:ss%z' — Full date and time with timezone (e.g. +00:00 or +01:00)"
358-
"- 'YYYY-MM-DDThh:mm:ss.f%z' — Full date and time with milliseconds and timezone"
359-
)
360-
361-
if is_occurrence_date_time:
362-
expected_error_message += "Only '+00:00' and '+01:00' are accepted as valid timezone offsets.\n"
363-
expected_error_message += f"Note that partial dates are not allowed for {field_location} in this service."
364-
365-
if is_occurrence_date_time:
366-
invalid_datetime_formats = InvalidValues.for_date_time_string_formats_for_strict_timezone
367-
else:
368-
# For recorded, skip values that are valid ISO with non-restricted timezone
369-
invalid_datetime_formats = InvalidValues.for_date_time_string_formats_for_relaxed_timezone
370-
371370
# Test invalid date time string formats
372371
for invalid_occurrence_date_time in invalid_datetime_formats:
373372
test_invalid_values_rejected(

backend/tests/utils/values_for_tests.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ValidValues:
3131

3232
nhs_number = "9990548609"
3333

34-
for_date_times = [
34+
for_date_times_strict_timezones = [
3535
"2000-01-01", # Full date only
3636
"2000-01-01T00:00:00+00:00", # Time and offset all zeroes
3737
"2000-01-01T10:34:27", # Date with Time only
@@ -44,6 +44,12 @@ class ValidValues:
4444
"1933-12-31T11:11:11.111111+00:00", # DateTime with milliseconds to 6 decimal places
4545
]
4646

47+
for_date_times_relaxed_timezones = for_date_times_strict_timezones + [
48+
"2000-01-01T00:00:00+05:00", # Time and offset all zeroes
49+
"1933-12-31T11:11:11-01:00", # Negative offset (with hours and minutes not 0)
50+
"1933-12-31T11:11:11.1-05:00", # DateTime with milliseconds to 1 decimal place
51+
]
52+
4753
for_strings_with_any_length_chars = (
4854
"This is a really long string with more than 100 characters to test whether the validator is working well!! "
4955
)

0 commit comments

Comments
 (0)