Skip to content

Commit a028215

Browse files
Andyg79adrianoaru-nhsvictor-soares-ibmmepr1
authored
Updated DateTimeUtils to allow for bcss displaying timestamps in UTC (#21)
<!-- markdownlint-disable-next-line first-line-heading --> ## Description <!-- Describe your changes in detail. --> Our reports tests verify timestamps and not all of the timestamps in bcss display the timestamp in DST so several tests are failing. I've made some changes to the DateTimeUtil to allow us to assert timestamps in either DST or UTC, depending on the current bcss app settings. ## Context <!-- Why is this change required? What problem does it solve? --> This allows the timestamp verification steps to pass, until the issue has been resolved in the app. ## Type of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> - [x] Refactoring (non-breaking change) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would change existing functionality) - [ ] Bug fix (non-breaking change which fixes an issue) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I am familiar with the [contributing guidelines](https://github.com/nhs-england-tools/playwright-python-blueprint/blob/main/CONTRIBUTING.md) - [x] I have followed the code style of the project - [x] I have added tests to cover my changes (where appropriate) - [x] I have updated the documentation accordingly - [ ] This PR is a result of pair or mob programming --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [x] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes. --------- Co-authored-by: adrianoaru-nhs <[email protected]> Co-authored-by: victor-soares-ibm <[email protected]> Co-authored-by: Adriano Aru <[email protected]> Co-authored-by: mepr1 <[email protected]>
1 parent a9fc727 commit a028215

File tree

3 files changed

+71
-22
lines changed

3 files changed

+71
-22
lines changed

pages/reports/reports_page.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from playwright.sync_api import Page
2+
import pytest
23
from pages.base_page import BasePage
34
from utils.table_util import TableUtils
45

@@ -10,7 +11,9 @@ def __init__(self, page):
1011

1112
# Initialize TableUtils for different tables
1213
self.failsafe_reports_sub_links_table = TableUtils(page, "#listReportDataTable")
13-
self.fail_safe_reports_screening_subjects_with_inactive_open_episodes_table = TableUtils(page, "#subjInactiveOpenEpisodes")
14+
self.fail_safe_reports_screening_subjects_with_inactive_open_episodes_table = (
15+
TableUtils(page, "#subjInactiveOpenEpisodes")
16+
)
1417

1518
# Reports page main menu links
1619
self.bureau_reports_link = self.page.get_by_text("Bureau Reports")
@@ -50,17 +53,18 @@ def __init__(self, page):
5053
)
5154

5255
# Set patients screening centre dropdown locators
56+
SCREENING_CENTRE = "Screening Centre"
5357
self.set_patients_screening_centre_dropdown = self.page.locator(
5458
"#cboScreeningCentre"
5559
)
5660
self.six_weeks_availability_not_set_up_set_patients_screening_centre_dropdown = self.page.get_by_label(
57-
"Screening Centre"
61+
SCREENING_CENTRE
5862
)
5963
self.practitioner_appointments_set_patients_screening_centre_dropdown = (
60-
page.get_by_label("Screening Centre")
64+
page.get_by_label(SCREENING_CENTRE)
6165
)
6266
self.attendance_not_updated_set_patients_screening_centre_dropdown = (
63-
page.get_by_label("Screening Centre")
67+
page.get_by_label(SCREENING_CENTRE)
6468
)
6569

6670
# Select screening practitioner dropdown locators
@@ -192,14 +196,20 @@ def click_failsafe_reports_sub_links(self):
192196
"""
193197
self.failsafe_reports_sub_links_table.click_first_link_in_column("NHS Number")
194198

195-
def click_fail_safe_reports_screening_subjects_with_inactive_open_episodes_link(self):
199+
def click_fail_safe_reports_screening_subjects_with_inactive_open_episodes_link(
200+
self,
201+
):
196202
"""
197203
Clicks the first NHS number link from the primary report table.
198204
"""
199-
self.fail_safe_reports_screening_subjects_with_inactive_open_episodes_table.click_first_link_in_column("NHS Number")
205+
self.fail_safe_reports_screening_subjects_with_inactive_open_episodes_table.click_first_link_in_column(
206+
"NHS Number"
207+
)
200208

201209
def click_fail_safe_reports_identify_and_link_new_gp_practices_link(self):
202210
"""
203211
Clicks the first Practice Code link from the primary report table.
204212
"""
205-
self.failsafe_reports_sub_links_table.click_first_link_in_column("Practice Code")
213+
self.failsafe_reports_sub_links_table.click_first_link_in_column(
214+
"Practice Code"
215+
)

tests/test_reports_page.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_failsafe_reports_screening_subjects_with_inactive_open_episode(
134134
ReportsPage(page).click_fail_safe_reports_screening_subjects_with_inactive_open_episodes_link()
135135

136136
# Verify the page title is "Subject Screening Summary"
137-
BasePage(page).bowel_cancer_screening_ntsh_page_title_contains_text(
137+
BasePage(page).bowel_cancer_screening_page_title_contains_text(
138138
"Subject Screening Summary"
139139
)
140140

@@ -219,7 +219,7 @@ def test_failsafe_reports_allocate_sc_for_patient_movements_within_hub_boundarie
219219
)
220220

221221
# Select another screening centre
222-
(ReportsPage(page).set_patients_screening_centre_dropdown).select_option(
222+
ReportsPage(page).set_patients_screening_centre_dropdown.select_option(
223223
general_properties["coventry_and_warwickshire_bcs_centre"]
224224
)
225225

@@ -346,9 +346,7 @@ def test_operational_reports_appointment_attendance_not_updated(
346346
ReportsPage(
347347
page
348348
).attendance_not_updated_set_patients_screening_centre_dropdown.select_option(
349-
ReportsPage(page).general_properties_properties[
350-
"coventry_and_warwickshire_bcs_centre"
351-
]
349+
general_properties["coventry_and_warwickshire_bcs_centre"]
352350
)
353351

354352
# Click "Generate Report" button

utils/date_time_utils.py

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
from datetime import datetime, timedelta
1+
from datetime import datetime, timedelta, tzinfo
2+
from zoneinfo import ZoneInfo
23

34

45
class DateTimeUtils:
6+
UTC_TIMEZONE = "UTC"
7+
DST_TIMEZONE = "Europe/London"
58
"""
69
A utility class for doing common actions with datetimes.
710
"""
@@ -69,16 +72,54 @@ def get_a_day_of_week(date: datetime) -> str:
6972
return date.strftime("%A")
7073

7174
@staticmethod
72-
def report_timestamp_date_format() -> str:
73-
"""Gets the current datetime in the timestamp format used on the report pages."""
74-
return DateTimeUtils.format_date(datetime.now(), "%d/%m/%Y at %H:%M:%S")
75+
def report_timestamp_date_format(use_utc: bool = True) -> str:
76+
"""Gets the current datetime in the timestamp format used on the report pages.
77+
Based on the value of `use_utc`, it chooses the appropriate timezone.
78+
"""
79+
80+
if use_utc:
81+
return DateTimeUtils.format_date(
82+
datetime.now(ZoneInfo(DateTimeUtils.UTC_TIMEZONE)),
83+
"%d/%m/%Y at %H:%M:%S",
84+
)
85+
else:
86+
return DateTimeUtils.format_date(
87+
datetime.now(ZoneInfo(DateTimeUtils.DST_TIMEZONE)),
88+
"%d/%m/%Y at %H:%M:%S",
89+
)
7590

7691
@staticmethod
77-
def fobt_kits_logged_but_not_read_report_timestamp_date_format() -> str:
78-
"""Gets the current datetime in the format used for FOBT Kits Logged but Not Read report."""
79-
return DateTimeUtils.format_date(datetime.now(), "%d %b %Y %H:%M:%S")
92+
def fobt_kits_logged_but_not_read_report_timestamp_date_format(
93+
use_utc: bool = False,
94+
) -> str:
95+
"""Gets the current datetime in the format used for FOBT Kits Logged but Not Read report.
96+
Based on the value of `use_utc`, it chooses the appropriate timezone.
97+
"""
98+
99+
if use_utc:
100+
return DateTimeUtils.format_date(
101+
datetime.now(ZoneInfo(DateTimeUtils.UTC_TIMEZONE)), "%d %b %Y %H:%M:%S"
102+
)
103+
else:
104+
return DateTimeUtils.format_date(
105+
datetime.now(ZoneInfo(DateTimeUtils.DST_TIMEZONE)), "%d %b %Y %H:%M:%S"
106+
)
80107

81108
@staticmethod
82-
def screening_practitioner_appointments_report_timestamp_date_format() -> str:
83-
"""Gets the current datetime in the format used for Screening Practitioner Appointments report."""
84-
return DateTimeUtils.format_date(datetime.now(), "%d.%m.%Y at %H:%M:%S")
109+
def screening_practitioner_appointments_report_timestamp_date_format(
110+
use_utc: bool = True,
111+
) -> str:
112+
"""Gets the current datetime in the format used for Screening Practitioner Appointments report.
113+
Based on the value of `use_utc`, it chooses the appropriate timezone.
114+
"""
115+
116+
if use_utc:
117+
return DateTimeUtils.format_date(
118+
datetime.now(ZoneInfo(DateTimeUtils.UTC_TIMEZONE)),
119+
"%d.%m.%Y at %H:%M:%S",
120+
)
121+
else:
122+
return DateTimeUtils.format_date(
123+
datetime.now(ZoneInfo(DateTimeUtils.DST_TIMEZONE)),
124+
"%d.%m.%Y at %H:%M:%S",
125+
)

0 commit comments

Comments
 (0)