Skip to content

Commit 6de9ba3

Browse files
committed
Merge branch 'feature/BCSS-20580-selenium-to-playwright-non-invitation-days' into feature/BCSS-20580-selenium-to-playwright-generate_fobt_invitations
to resolve merge conflicts
2 parents b2a46c5 + dfa3387 commit 6de9ba3

File tree

2 files changed

+38
-55
lines changed

2 files changed

+38
-55
lines changed

tests_utils/test_date_time_utils.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,26 @@ def test_add_days():
3232
assert new_date == date + timedelta(days=5)
3333

3434

35-
def test_get_day_of_week_for_today():
35+
# Valid weekdays for testing get_day_of_week
36+
VALID_WEEKDAYS = [
37+
"Monday",
38+
"Tuesday",
39+
"Wednesday",
40+
"Thursday",
41+
"Friday",
42+
"Saturday",
43+
"Sunday",
44+
]
45+
46+
47+
def test_get_day_of_week_with_specific_date():
3648
dtu = utils.date_time_utils.DateTimeUtils()
37-
date = datetime.now()
38-
day_of_week = dtu.get_a_day_of_week(date)
39-
assert day_of_week in [
40-
"Monday",
41-
"Tuesday",
42-
"Wednesday",
43-
"Thursday",
44-
"Friday",
45-
"Saturday",
46-
"Sunday",
47-
]
48-
49-
50-
def test_get_a_day_of_week():
49+
date = datetime(2023, 11, 8) # Known Wednesday
50+
day_of_week = dtu.get_day_of_week(date)
51+
assert day_of_week in VALID_WEEKDAYS
52+
53+
54+
def test_get_day_of_week_with_default_today():
5155
dtu = utils.date_time_utils.DateTimeUtils()
52-
date = datetime(2023, 11, 8)
53-
day_of_week = dtu.get_a_day_of_week(date)
54-
assert day_of_week in [
55-
"Monday",
56-
"Tuesday",
57-
"Wednesday",
58-
"Thursday",
59-
"Friday",
60-
"Saturday",
61-
"Sunday",
62-
]
56+
day_of_week = dtu.get_day_of_week()
57+
assert day_of_week in VALID_WEEKDAYS

utils/date_time_utils.py

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime, timedelta
2+
from typing import Optional
23
import random
34

45

@@ -46,27 +47,18 @@ def add_days(date: datetime, days: float) -> datetime:
4647
return date + timedelta(days=days)
4748

4849
@staticmethod
49-
def get_day_of_week_for_today(date: datetime) -> str:
50-
"""Gets the day of the week (e.g., Monday, Tuesday) from the specified date.
51-
52-
Args:
53-
date (datetime): The current date using the now function
54-
55-
Returns:
56-
str: The day of the week relating to the specified date.
50+
def get_day_of_week(date: Optional[datetime] = None) -> str:
5751
"""
58-
return date.strftime("%A")
59-
60-
@staticmethod
61-
def get_a_day_of_week(date: datetime) -> str:
62-
"""Gets the day of the week (e.g., Monday, Tuesday) from the specified date.
52+
Returns the day of the week (e.g., Monday, Tuesday) for the given date.
53+
If no date is provided, uses today’s date.
6354
6455
Args:
65-
date (datetime): The date for which the day of the week will be returned.
56+
date (Optional[datetime]): The date to inspect. Defaults to now.
6657
6758
Returns:
68-
str: The day of the week relating to the specified date.
59+
str: Day of week corresponding to the date.
6960
"""
61+
date = date or datetime.now()
7062
return date.strftime("%A")
7163

7264
@staticmethod
@@ -99,7 +91,8 @@ def screening_practitioner_appointments_report_timestamp_date_format() -> str:
9991

10092
return DateTimeUtils.format_date(datetime.now(), "%d.%m.%Y at %H:%M:%S")
10193

102-
def month_string_to_number(self, string: str) -> int:
94+
@staticmethod
95+
def month_string_to_number(string: str) -> int:
10396
"""
10497
This is used to convert a month from a string to an integer.
10598
It accepts the full month or the short version and is not case sensitive
@@ -124,22 +117,17 @@ def month_string_to_number(self, string: str) -> int:
124117
out = months[month_short]
125118
return out
126119
except Exception:
127-
raise ValueError("Not a month")
120+
raise ValueError(
121+
f"'{string}' is not a valid month name. Accepted values are: {', '.join(months.keys())}"
122+
)
128123

129-
def generate_unique_weekday_date(self, start_year: int = 2025) -> str:
124+
@staticmethod
125+
def generate_unique_weekday_date(start_year: int = 2025) -> str:
130126
"""
131-
Generates a future weekday date from the specified year onward.
132-
133-
This function returns a dynamically generated date string in the format 'dd/mm/yyyy'
134-
that always falls on a weekday (Monday–Friday) and is suitable for use in automated tests
135-
where the date must differ on each run to avoid duplication issues.
136-
137-
A small pseudorandom offset is added to ensure uniqueness between runs.
127+
Returns a random future weekday (Mon–Fri) date from the given year onward.
138128
139-
Note:
140-
This function uses Python's built-in `random` module to add variability.
141-
Since this is for test-only purposes and does not involve security-sensitive logic,
142-
the use of a non-cryptographic PRNG is appropriate and intentional.
129+
The result is in 'dd/mm/yyyy' format and useful for automated tests needing
130+
unique, non-weekend dates. Uses non-cryptographic randomness for variability between runs.
143131
144132
Args:
145133
start_year (int): The minimum year from which the date may be generated. Defaults to 2025.

0 commit comments

Comments
 (0)