Skip to content

Commit 1acb822

Browse files
authored
Merge pull request #240 from NHSDigital/remove-file-record-count
Refactor waiting for background imports
2 parents 9c85766 + f090080 commit 1acb822

File tree

6 files changed

+50
-48
lines changed

6 files changed

+50
-48
lines changed

libs/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,9 @@ class CurrentExecution:
99
session_screenshots_dir: str = ""
1010
capture_screenshot_flag: bool = False
1111
screenshot_sequence: int = 0
12-
file_record_count: int = 0
1312

1413
@classmethod
1514
def get_env_values(cls):
1615
cls.capture_screenshot_flag = (
1716
os.environ.get("CAPTURE_SCREENSHOTS", "").lower() == "true"
1817
)
19-
20-
@classmethod
21-
def set_file_record_count(cls, record_count: int):
22-
cls.file_record_count = record_count
23-
24-
@classmethod
25-
def get_file_record_count(cls) -> int:
26-
return cls.file_record_count

libs/mavis_constants.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ class mavis_file_types(Enum):
4242
VACCS_SYSTMONE = auto()
4343

4444

45-
class record_limit:
46-
FILE_RECORD_MIN_THRESHOLD: Final[int] = 15
47-
FILE_RECORD_MAX_THRESHOLD: Final[int] = 15
48-
49-
5045
class test_data_file_paths:
5146
PARENTAL_CONSENT_HPV: Final[str] = "test_data/ParentalConsent_HPV.xlsx"
5247
PARENTAL_CONSENT_DOUBLES: Final[str] = "test_data/ParentalConsent_Doubles.xlsx"

libs/testdata_ops.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ def create_file_from_template(
8686
_file_text.append(line)
8787
_ctr += 1
8888

89-
self.ce.set_file_record_count(record_count=_ctr)
90-
9189
filename = f"{file_name_prefix}{get_current_datetime()}.csv"
9290

9391
path = pathlib.Path("working") / filename

pages/import_records.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from libs import CurrentExecution, testdata_ops
44
from libs.generic_constants import actions, escape_characters, properties, wait_time
55
from libs.playwright_ops import PlaywrightOperations
6-
from libs.mavis_constants import mavis_file_types, record_limit
6+
from libs.mavis_constants import mavis_file_types, test_data_values
77
from libs.wrappers import get_link_formatted_date_time
88

99
from .children import ChildrenPage
@@ -39,6 +39,14 @@ def __init__(self, playwright_operations: PlaywrightOperations):
3939
self.vaccines_page = VaccinesPage(playwright_operations)
4040
self.upload_time = ""
4141

42+
@property
43+
def alert_success(self):
44+
return self.ce.page.get_by_text("Import processing started")
45+
46+
def is_processing_in_background(self):
47+
self.ce.page.wait_for_load_state()
48+
return self.alert_success.is_visible()
49+
4250
def import_child_records(
4351
self, file_paths: str, verify_on_children_page: bool = False
4452
):
@@ -62,9 +70,11 @@ def import_child_records(
6270
)
6371
self.po.act(locator=self.BTN_CONTINUE, action=actions.CLICK_BUTTON)
6472
self._record_upload_time()
65-
self.po.act(locator=None, action=actions.WAIT, value=wait_time.MED)
66-
if self.ce.get_file_record_count() > record_limit.FILE_RECORD_MAX_THRESHOLD:
73+
74+
if self.is_processing_in_background():
75+
self.po.act(locator=None, action=actions.WAIT, value=wait_time.MED)
6776
self._click_uploaded_file_datetime(truncated=True)
77+
6878
self._verify_upload_output(file_path=_output_file_path)
6979
if verify_on_children_page:
7080
self.children_page.verify_child_has_been_uploaded(child_list=_cl)
@@ -94,7 +104,7 @@ def import_class_list_records(
94104
self.po.act(
95105
locator=self.LBL_SCHOOL_NAME,
96106
action=actions.SELECT_FROM_LIST,
97-
value=self.sessions_page.LNK_SCHOOL_1,
107+
value=test_data_values.SCHOOL_1_NAME,
98108
)
99109
self.po.act(locator=self.BTN_CONTINUE, action=actions.CLICK_BUTTON)
100110
self._select_year_groups(*year_groups)
@@ -105,9 +115,11 @@ def import_class_list_records(
105115
)
106116
self.po.act(locator=self.BTN_CONTINUE, action=actions.CLICK_BUTTON)
107117
self._record_upload_time()
108-
self.po.act(locator=None, action=actions.WAIT, value=wait_time.MED)
109-
if self.ce.get_file_record_count() > record_limit.FILE_RECORD_MAX_THRESHOLD:
118+
119+
if self.is_processing_in_background():
120+
self.po.act(locator=None, action=actions.WAIT, value=wait_time.MED)
110121
self._click_uploaded_file_datetime(truncated=True)
122+
111123
self._verify_upload_output(file_path=_output_file_path)
112124
if verify_on_children_page:
113125
self.children_page.verify_child_has_been_uploaded(child_list=_cl)
@@ -127,9 +139,11 @@ def import_class_list_records_from_school_session(self, file_paths: str):
127139
)
128140
self.po.act(locator=self.BTN_CONTINUE, action=actions.CLICK_BUTTON)
129141
self._record_upload_time()
130-
self.po.act(locator=None, action=actions.WAIT, value=wait_time.MED)
131-
if self.ce.get_file_record_count() > record_limit.FILE_RECORD_MAX_THRESHOLD:
142+
143+
if self.is_processing_in_background():
144+
self.po.act(locator=None, action=actions.WAIT, value=wait_time.MED)
132145
self._click_uploaded_file_datetime(truncated=True)
146+
133147
self._verify_upload_output(file_path=_output_file_path)
134148

135149
def import_vaccination_records(
@@ -158,9 +172,11 @@ def import_vaccination_records(
158172
)
159173
self.po.act(locator=self.BTN_CONTINUE, action=actions.CLICK_BUTTON)
160174
self._record_upload_time()
161-
self.po.act(locator=None, action=actions.WAIT, value=wait_time.MAX)
162-
if self.ce.get_file_record_count() > record_limit.FILE_RECORD_MAX_THRESHOLD:
175+
176+
if self.is_processing_in_background():
177+
self.po.act(locator=None, action=actions.WAIT, value=wait_time.MAX)
163178
self._click_uploaded_file_datetime(truncated=True)
179+
164180
self._verify_upload_output(file_path=_output_file_path)
165181
if verify_on_children_page:
166182
self.children_page.verify_child_has_been_uploaded(child_list=_cl)
@@ -213,5 +229,5 @@ def verify_mav_855(self):
213229
self.po.verify(
214230
locator=self.LBL_MAIN,
215231
property=properties.TEXT,
216-
expected_value=self.sessions_page.LNK_SCHOOL_1,
232+
expected_value=test_data_values.SCHOOL_1_NAME,
217233
)

pages/programmes.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@
44

55
from libs import CurrentExecution, testdata_ops
66
from libs.generic_constants import actions, properties, wait_time
7-
from libs.mavis_constants import (
8-
record_limit,
9-
report_headers,
10-
test_data_file_paths,
11-
Programme,
12-
)
7+
from libs.mavis_constants import report_headers, test_data_file_paths, Programme
138
from libs.playwright_ops import PlaywrightOperations
149
from libs.wrappers import get_current_datetime, get_link_formatted_date_time
1510

1611
from .children import ChildrenPage
1712
from .consent_doubles import ConsentDoublesPage
1813
from .consent_hpv import ConsentHPVPage
1914
from .dashboard import DashboardPage
15+
from .import_records import ImportRecordsPage
2016
from .sessions import SessionsPage
2117

2218

@@ -67,6 +63,7 @@ def __init__(self, playwright_operations: PlaywrightOperations):
6763
self.children_page = ChildrenPage(playwright_operations)
6864
self.consent_hpv = ConsentHPVPage(playwright_operations)
6965
self.consent_doubles = ConsentDoublesPage(playwright_operations)
66+
self.import_records_page = ImportRecordsPage(playwright_operations)
7067

7168
def click_programme(self, programme: Programme):
7269
self.po.act(locator=programme, action=actions.CLICK_LINK)
@@ -159,9 +156,11 @@ def upload_hpv_child_records(self, file_paths: str):
159156
self.choose_file_child_records(file_path=_input_file_path)
160157
self.click_continue()
161158
self.record_upload_time()
162-
self.po.act(locator=None, action=actions.WAIT, value=wait_time.MED)
163-
if self.ce.get_file_record_count() > record_limit.FILE_RECORD_MAX_THRESHOLD:
159+
160+
if self.import_records_page.is_processing_in_background():
161+
self.po.act(locator=None, action=actions.WAIT, value=wait_time.MED)
164162
self.click_uploaded_file_datetime(truncated=True)
163+
165164
self.verify_upload_output(file_path=_output_file_path)
166165

167166
def upload_cohorts(self, file_paths: str, wait_long: bool = False):
@@ -174,12 +173,14 @@ def upload_cohorts(self, file_paths: str, wait_long: bool = False):
174173
self.choose_file_child_records(file_path=_input_file_path)
175174
self.click_continue()
176175
self.record_upload_time()
177-
if wait_long:
178-
self.po.act(locator=None, action=actions.WAIT, value="14m")
179-
else:
180-
self.po.act(locator=None, action=actions.WAIT, value=wait_time.MED)
181-
if self.ce.get_file_record_count() > record_limit.FILE_RECORD_MAX_THRESHOLD:
176+
177+
if self.import_records_page.is_processing_in_background():
178+
if wait_long:
179+
self.po.act(locator=None, action=actions.WAIT, value="14m")
180+
else:
181+
self.po.act(locator=None, action=actions.WAIT, value=wait_time.MED)
182182
self.click_uploaded_file_datetime()
183+
183184
self.verify_upload_output(file_path=_output_file_path)
184185

185186
def edit_dose_to_not_given(self):

pages/sessions.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
from libs import CurrentExecution, testdata_ops
44
from libs.generic_constants import actions, escape_characters, properties, wait_time
5-
from libs.mavis_constants import (
6-
mavis_file_types,
7-
record_limit,
8-
test_data_values,
9-
Programme,
10-
)
5+
from libs.mavis_constants import mavis_file_types, test_data_values, Programme
116
from libs.playwright_ops import PlaywrightOperations
127
from libs.wrappers import (
138
datetime,
@@ -19,6 +14,7 @@
1914
from .children import ChildrenPage
2015
from .consent_hpv import ConsentHPVPage
2116
from .dashboard import DashboardPage
17+
from .import_records import ImportRecordsPage
2218

2319

2420
class SessionsPage:
@@ -130,6 +126,7 @@ def __init__(self, playwright_operations: PlaywrightOperations):
130126
self.dashboard_page = DashboardPage(playwright_operations)
131127
self.consent_page = ConsentHPVPage(playwright_operations)
132128
self.children_page = ChildrenPage(playwright_operations)
129+
self.import_records_page = ImportRecordsPage(playwright_operations)
133130

134131
def __get_display_formatted_date(self, date_to_format: str) -> str:
135132
_parsed_date = datetime.strptime(date_to_format, "%Y%m%d")
@@ -705,9 +702,11 @@ def upload_class_list_to_school_1(
705702
self.choose_file_child_records_for_school_1(file_path=_input_file_path)
706703
self.click_continue()
707704
self._record_upload_time()
708-
if self.ce.get_file_record_count() > record_limit.FILE_RECORD_MIN_THRESHOLD:
705+
706+
if self.import_records_page.is_processing_in_background():
709707
self.po.act(locator=None, action=actions.WAIT, value=wait_time.MED)
710708
self.click_uploaded_file_datetime()
709+
711710
self.verify_upload_output(file_path=_output_file_path)
712711
if verify_on_children:
713712
self.children_page.verify_child_has_been_uploaded(child_list=_cl)
@@ -727,9 +726,11 @@ def upload_class_list_to_school_2(
727726
self.choose_file_child_records_for_school_2(file_path=_input_file_path)
728727
self.click_continue()
729728
self._record_upload_time()
730-
if self.ce.get_file_record_count() > record_limit.FILE_RECORD_MIN_THRESHOLD:
729+
730+
if self.import_records_page.is_processing_in_background():
731731
self.po.act(locator=None, action=actions.WAIT, value=wait_time.MED)
732732
self.click_uploaded_file_datetime()
733+
733734
self.verify_upload_output(file_path=_output_file_path)
734735
if verify_on_children:
735736
self.children_page.verify_child_has_been_uploaded(child_list=_cl)

0 commit comments

Comments
 (0)