Skip to content

Commit b4cfbb4

Browse files
Input file handling
1 parent 391d74d commit b4cfbb4

File tree

7 files changed

+77
-101
lines changed

7 files changed

+77
-101
lines changed

libs/api_ops.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ def api_get(endpoint, header, param):
1414
resp = requests.get(url=endpoint, params=param)
1515
else:
1616
resp = requests.get(url=endpoint, params=param, headers=header)
17-
assert api_operations.__verify_response_code(resp.status_code), f"API GET failed for {endpoint}."
17+
assert api_operations.__verify_response_code(
18+
resp.status_code
19+
), f"API GET failed for {endpoint} - {resp.status_code}."
1820
return resp
1921

2022
@staticmethod

libs/constants.py

Lines changed: 28 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ class api_constants:
3838
API_SUCCESS_STATUS_CODE_MAX: Final[int] = 299
3939

4040

41-
class workflow_type:
42-
APPLICATION: Final[str] = "application"
43-
PARENTAL_CONSENT: Final[str] = "parental_consent"
44-
45-
4641
class data_values:
4742
EMPTY: Final[str] = "<empty>"
4843

@@ -108,81 +103,33 @@ class escape_characters:
108103
]
109104

110105

111-
class test_data_file_paths:
112-
PARENTAL_CONSENT: Final[str] = "test_data/ParentalConsent.xlsx"
113-
VACCS_HPV_POSITIVE: Final[str] = (
114-
f"test_data/hpv/i_positive.csv{escape_characters.SEPARATOR_CHAR}test_data/hpv/o_positive.csv{escape_characters.SEPARATOR_CHAR}hpv"
115-
)
116-
VACCS_HPV_NEGATIVE: Final[str] = (
117-
f"test_data/hpv/i_negative.csv{escape_characters.SEPARATOR_CHAR}test_data/hpv/o_negative.csv{escape_characters.SEPARATOR_CHAR}hpv"
118-
)
119-
VACCS_HIST_HPV_POSITIVE: Final[str] = (
120-
f"test_data/hpv/i_hist_positive.csv{escape_characters.SEPARATOR_CHAR}test_data/hpv/o_hist_positive.csv{escape_characters.SEPARATOR_CHAR}hpv"
121-
)
122-
VACCS_HIST_HPV_NEGATIVE: Final[str] = (
123-
f"test_data/hpv/i_hist_negative.csv{escape_characters.SEPARATOR_CHAR}test_data/hpv/o_hist_negative.csv{escape_characters.SEPARATOR_CHAR}hpv"
124-
)
125-
VACCS_HPV_DUP_1: Final[str] = (
126-
f"test_data/hpv/i_dup_1.csv{escape_characters.SEPARATOR_CHAR}test_data/hpv/o_dup_1.csv{escape_characters.SEPARATOR_CHAR}hpv"
127-
)
128-
VACCS_HPV_DUP_2: Final[str] = (
129-
f"test_data/hpv/i_dup_2.csv{escape_characters.SEPARATOR_CHAR}test_data/hpv/o_dup_2.csv{escape_characters.SEPARATOR_CHAR}hpv"
130-
)
131-
VACCS_HPV_INVALID_STRUCTURE: Final[str] = (
132-
f"test_data/hpv/i_invalid_structure.csv{escape_characters.SEPARATOR_CHAR}test_data/hpv/o_invalid_structure.csv{escape_characters.SEPARATOR_CHAR}hpv"
133-
)
134-
VACCS_HPV_EMPTY_FILE: Final[str] = (
135-
f"test_data/hpv/i_empty.csv{escape_characters.SEPARATOR_CHAR}test_data/hpv/o_empty.csv{escape_characters.SEPARATOR_CHAR}hpv"
136-
)
137-
VACCS_HPV_HEADER_ONLY: Final[str] = (
138-
f"test_data/hpv/i_header_only.csv{escape_characters.SEPARATOR_CHAR}test_data/hpv/o_header_only.csv{escape_characters.SEPARATOR_CHAR}hpv"
139-
)
140-
COHORTS_POSITIVE: Final[str] = (
141-
f"test_data/cohorts/i_positive.csv{escape_characters.SEPARATOR_CHAR}test_data/cohorts/o_positive.csv{escape_characters.SEPARATOR_CHAR}cohort"
142-
)
143-
COHORTS_NEGATIVE: Final[str] = (
144-
f"test_data/cohorts/i_negative.csv{escape_characters.SEPARATOR_CHAR}test_data/cohorts/o_negative.csv{escape_characters.SEPARATOR_CHAR}cohort"
145-
)
146-
COHORTS_INVALID_STRUCTURE: Final[str] = (
147-
f"test_data/cohorts/i_invalid_structure.csv{escape_characters.SEPARATOR_CHAR}test_data/cohorts/o_invalid_structure.csv{escape_characters.SEPARATOR_CHAR}cohort"
148-
)
149-
COHORTS_EMPTY_FILE: Final[str] = (
150-
f"test_data/cohorts/i_empty.csv{escape_characters.SEPARATOR_CHAR}test_data/cohorts/o_empty.csv{escape_characters.SEPARATOR_CHAR}cohort"
151-
)
152-
COHORTS_HEADER_ONLY: Final[str] = (
153-
f"test_data/cohorts/i_header_only.csv{escape_characters.SEPARATOR_CHAR}test_data/cohorts/o_header_only.csv{escape_characters.SEPARATOR_CHAR}cohort"
154-
)
155-
CHILD_POSITIVE: Final[str] = (
156-
f"test_data/child/i_positive.csv{escape_characters.SEPARATOR_CHAR}test_data/child/o_positive.csv{escape_characters.SEPARATOR_CHAR}child"
157-
)
158-
CHILD_NEGATIVE: Final[str] = (
159-
f"test_data/child/i_negative.csv{escape_characters.SEPARATOR_CHAR}test_data/child/o_negative.csv{escape_characters.SEPARATOR_CHAR}child"
160-
)
161-
CHILD_INVALID_STRUCTURE: Final[str] = (
162-
f"test_data/child/i_invalid_structure.csv{escape_characters.SEPARATOR_CHAR}test_data/child/o_invalid_structure.csv{escape_characters.SEPARATOR_CHAR}child"
163-
)
164-
CHILD_EMPTY_FILE: Final[str] = (
165-
f"test_data/child/i_empty.csv{escape_characters.SEPARATOR_CHAR}test_data/child/o_empty.csv{escape_characters.SEPARATOR_CHAR}child"
166-
)
167-
CHILD_HEADER_ONLY: Final[str] = (
168-
f"test_data/child/i_header_only.csv{escape_characters.SEPARATOR_CHAR}test_data/child/o_header_only.csv{escape_characters.SEPARATOR_CHAR}child"
169-
)
170-
CLASS_POSITIVE: Final[str] = (
171-
f"test_data/class_list/i_positive.csv{escape_characters.SEPARATOR_CHAR}test_data/class_list/o_positive.csv{escape_characters.SEPARATOR_CHAR}class"
172-
)
173-
CLASS_NEGATIVE: Final[str] = (
174-
f"test_data/class_list/i_negative.csv{escape_characters.SEPARATOR_CHAR}test_data/class_list/o_negative.csv{escape_characters.SEPARATOR_CHAR}class"
175-
)
176-
CLASS_INVALID_STRUCTURE: Final[str] = (
177-
f"test_data/class_list/i_invalid_structure.csv{escape_characters.SEPARATOR_CHAR}test_data/class_list/o_invalid_structure.csv{escape_characters.SEPARATOR_CHAR}class"
178-
)
179-
CLASS_EMPTY_FILE: Final[str] = (
180-
f"test_data/class_list/i_empty.csv{escape_characters.SEPARATOR_CHAR}test_data/class_list/o_empty.csv{escape_characters.SEPARATOR_CHAR}class"
181-
)
182-
CLASS_HEADER_ONLY: Final[str] = (
183-
f"test_data/class_list/i_header_only.csv{escape_characters.SEPARATOR_CHAR}test_data/class_list/o_header_only.csv{escape_characters.SEPARATOR_CHAR}class"
184-
)
185-
186-
187106
class file_encoding:
188107
ASCII = "ascii"
108+
109+
110+
class test_data_file_paths:
111+
PARENTAL_CONSENT: Final[str] = "test_data/ParentalConsent.xlsx"
112+
VACCS_HPV_POSITIVE: Final[str] = "VACCS_HPV_POSITIVE"
113+
VACCS_HPV_NEGATIVE: Final[str] = "VACCS_HPV_NEGATIVE"
114+
VACCS_HIST_HPV_POSITIVE: Final[str] = "VACCS_HIST_HPV_POSITIVE"
115+
VACCS_HIST_HPV_NEGATIVE: Final[str] = "VACCS_HIST_HPV_NEGATIVE"
116+
VACCS_HPV_DUP_1: Final[str] = "VACCS_HPV_DUP_1"
117+
VACCS_HPV_DUP_2: Final[str] = "VACCS_HPV_DUP_2"
118+
VACCS_HPV_INVALID_STRUCTURE: Final[str] = "VACCS_HPV_INVALID_STRUCTURE"
119+
VACCS_HPV_EMPTY_FILE: Final[str] = "VACCS_HPV_EMPTY_FILE"
120+
VACCS_HPV_HEADER_ONLY: Final[str] = "VACCS_HPV_HEADER_ONLY"
121+
COHORTS_POSITIVE: Final[str] = "COHORTS_POSITIVE"
122+
COHORTS_NEGATIVE: Final[str] = "COHORTS_NEGATIVE"
123+
COHORTS_INVALID_STRUCTURE: Final[str] = "COHORTS_INVALID_STRUCTURE"
124+
COHORTS_EMPTY_FILE: Final[str] = "COHORTS_EMPTY_FILE"
125+
COHORTS_HEADER_ONLY: Final[str] = "COHORTS_HEADER_ONLY"
126+
CHILD_POSITIVE: Final[str] = "CHILD_POSITIVE"
127+
CHILD_NEGATIVE: Final[str] = "CHILD_NEGATIVE"
128+
CHILD_INVALID_STRUCTURE: Final[str] = "CHILD_INVALID_STRUCTURE"
129+
CHILD_EMPTY_FILE: Final[str] = "CHILD_EMPTY_FILE"
130+
CHILD_HEADER_ONLY: Final[str] = "CHILD_HEADER_ONLY"
131+
CLASS_POSITIVE: Final[str] = "CLASS_POSITIVE"
132+
CLASS_NEGATIVE: Final[str] = "CLASS_NEGATIVE"
133+
CLASS_INVALID_STRUCTURE: Final[str] = "CLASS_INVALID_STRUCTURE"
134+
CLASS_EMPTY_FILE: Final[str] = "CLASS_EMPTY_FILE"
135+
CLASS_HEADER_ONLY: Final[str] = "CLASS_HEADER_ONLY"

libs/testdata_ops.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_new_nhs_no(self, valid=True) -> str:
3434

3535
def get_expected_errors(self, file_path: str) -> list[str]:
3636
_file_content = self.fo.get_file_text(file_path=file_path)
37-
return _file_content.split("\n") if _file_content is not None else None
37+
return _file_content.split(escape_characters.NEW_LINE) if _file_content is not None else None
3838

3939
def read_spreadsheet(self, file_path: str) -> pd.DataFrame:
4040
_df = self.fo.read_excel_to_df(file_path=file_path)
@@ -52,10 +52,12 @@ def clean_df(self, df: pd.DataFrame) -> pd.DataFrame:
5252
_df.replace(to_replace="", value=data_values.EMPTY, inplace=True)
5353
return _df
5454

55-
def split_file_paths(self, file_paths: str) -> tuple[str, str]:
56-
file_for = file_paths.split(escape_characters.SEPARATOR_CHAR)[2]
57-
_input_file_path = self.create_file_from_template(
58-
template_path=file_paths.split(escape_characters.SEPARATOR_CHAR)[0], file_name_prefix=file_for
55+
def get_file_paths(self, file_paths: str) -> tuple[str, str]:
56+
_mapping_df: pd.DataFrame = self.fo.read_csv_to_df(file_path="test_data/file_mapping.csv")
57+
_input_template_path: str = _mapping_df.query("ID==@file_paths")["INPUT_TEMPLATE"].to_string(index=False)
58+
_output_template_path: str = _mapping_df.query("ID==@file_paths")["OUTPUT_TEMPLATE"].to_string(index=False)
59+
_file_prefix: str = _mapping_df.query("ID==@file_paths")["FILE_PREFIX"].to_string(index=False)
60+
_input_file_path: str = self.create_file_from_template(
61+
template_path=_input_template_path, file_name_prefix=_file_prefix
5962
)
60-
_output_file_path = file_paths.split(escape_characters.SEPARATOR_CHAR)[1]
61-
return _input_file_path, _output_file_path
63+
return _input_file_path, _output_template_path

pages/pg_dashboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def verify_all_expected_links(self):
5757
locator=self.LNK_UNMATCHED_CONSENT_RESPONSES, property=object_properties.VISIBILITY, value=True, exact=True
5858
)
5959
self.po.verify(locator=self.LNK_SCHOOL_MOVES, property=object_properties.VISIBILITY, value=True, exact=True)
60-
self.po.verify(locator=self.LNK_NOTICES, property=object_properties.VISIBILITY, value=True, exact=True)
60+
# self.po.verify(locator=self.LNK_NOTICES, property=object_properties.VISIBILITY, value=True, exact=True) # Superuser only
6161
self.po.verify(locator=self.LNK_ORGANISATION, property=object_properties.VISIBILITY, value=True, exact=True)
6262
self.po.verify(
6363
locator=self.LNK_SERVICE_GUIDANCE, property=object_properties.VISIBILITY, value=True, exact=True

pages/pg_programmes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def verify_upload_output(self, file_path: str):
8383
self.po.verify(locator=self.LBL_MAIN, property=object_properties.TEXT, value=_msg, exact=False)
8484

8585
def upload_hpv_vaccination_records(self, file_paths: str):
86-
_input_file_path, _output_file_path = self.tdo.split_file_paths(file_paths=file_paths)
86+
_input_file_path, _output_file_path = self.tdo.get_file_paths(file_paths=file_paths)
8787
self.click_hpv()
8888
self.click_imports()
8989
self.click_import_records()
@@ -99,7 +99,7 @@ def upload_hpv_vaccination_records(self, file_paths: str):
9999
self.verify_upload_output(file_path=_output_file_path)
100100

101101
def upload_hpv_child_records(self, file_paths: str):
102-
_input_file_path, _output_file_path = self.tdo.split_file_paths(file_paths=file_paths)
102+
_input_file_path, _output_file_path = self.tdo.get_file_paths(file_paths=file_paths)
103103
self.click_hpv()
104104
self.click_imports()
105105
self.click_import_records()
@@ -114,7 +114,7 @@ def upload_hpv_child_records(self, file_paths: str):
114114
self.verify_upload_output(file_path=_output_file_path)
115115

116116
def upload_cohorts(self, file_paths: str):
117-
_input_file_path, _output_file_path = self.tdo.split_file_paths(file_paths=file_paths)
117+
_input_file_path, _output_file_path = self.tdo.get_file_paths(file_paths=file_paths)
118118
self.click_hpv()
119119
self.click_cohorts()
120120
self.click_import_cohort_records()
@@ -127,7 +127,7 @@ def upload_cohorts(self, file_paths: str):
127127
self.verify_upload_output(file_path=_output_file_path)
128128

129129
def upload_invalid_files(self, file_paths: str):
130-
_input_file_path, _output_file_path = self.tdo.split_file_paths(file_paths=file_paths)
130+
_input_file_path, _output_file_path = self.tdo.get_file_paths(file_paths=file_paths)
131131
self.click_hpv()
132132
self.click_imports()
133133
self.click_import_records()
@@ -138,7 +138,7 @@ def upload_invalid_files(self, file_paths: str):
138138
self.verify_upload_output(file_path=_output_file_path)
139139

140140
def upload_invalid_cohorts(self, file_paths: str):
141-
_input_file_path, _output_file_path = self.tdo.split_file_paths(file_paths=file_paths)
141+
_input_file_path, _output_file_path = self.tdo.get_file_paths(file_paths=file_paths)
142142
self.click_hpv()
143143
self.click_cohorts()
144144
self.click_import_cohort_records()
@@ -147,7 +147,7 @@ def upload_invalid_cohorts(self, file_paths: str):
147147
self.verify_upload_output(file_path=_output_file_path)
148148

149149
def upload_invalid_hpv_child_records(self, file_paths: str):
150-
_input_file_path, _output_file_path = self.tdo.split_file_paths(file_paths=file_paths)
150+
_input_file_path, _output_file_path = self.tdo.get_file_paths(file_paths=file_paths)
151151
self.click_hpv()
152152
self.click_imports()
153153
self.click_import_records()

pages/pg_sessions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,15 @@ def click_get_consent_responses(self):
288288
self.po.perform_action(locator=self.BTN_GET_CONSENT_RESPONSES, action=actions.CLICK_BUTTON)
289289

290290
def upload_valid_class_list(self, file_paths: str):
291-
_input_file_path, _ = self.tdo.split_file_paths(file_paths=file_paths)
291+
_input_file_path, _ = self.tdo.get_file_paths(file_paths=file_paths)
292292
self.click_scheduled()
293293
self.click_school1()
294294
self.click_import_class_list()
295295
self.choose_file_child_records(file_path=_input_file_path)
296296
self.click_continue()
297297

298298
def update_triage_outcome_positive(self, file_paths):
299-
_input_file_path, _ = self.tdo.split_file_paths(file_paths=file_paths)
299+
_input_file_path, _ = self.tdo.get_file_paths(file_paths=file_paths)
300300
self.click_scheduled()
301301
self.click_school1()
302302
self.click_import_class_list()
@@ -325,7 +325,7 @@ def update_triage_outcome_positive(self, file_paths):
325325
self.verify_activity_log_entry(consent_given=True)
326326

327327
def update_triage_outcome_consent_refused(self, file_paths):
328-
_input_file_path, _ = self.tdo.split_file_paths(file_paths=file_paths)
328+
_input_file_path, _ = self.tdo.get_file_paths(file_paths=file_paths)
329329
self.click_scheduled()
330330
self.click_school1()
331331
self.click_import_class_list()
@@ -372,7 +372,7 @@ def create_invalid_session(self):
372372
self.schedule_session(future_date=_future_date, expect_error=True)
373373

374374
def upload_class_list(self, file_paths: str):
375-
_input_file_path, _output_file_path = self.tdo.split_file_paths(file_paths=file_paths)
375+
_input_file_path, _output_file_path = self.tdo.get_file_paths(file_paths=file_paths)
376376
self.click_scheduled()
377377
self.click_school1()
378378
self.click_import_class_list()
@@ -384,7 +384,7 @@ def upload_class_list(self, file_paths: str):
384384
self.verify_upload_output(file_path=_output_file_path)
385385

386386
def upload_invalid_class_list_records(self, file_paths: str):
387-
_input_file_path, _output_file_path = self.tdo.split_file_paths(file_paths=file_paths)
387+
_input_file_path, _output_file_path = self.tdo.get_file_paths(file_paths=file_paths)
388388
self.click_scheduled()
389389
self.click_school1()
390390
self.click_import_class_list()

test_data/file_mapping.csv

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
ID,INPUT_TEMPLATE,OUTPUT_TEMPLATE,FILE_PREFIX
2+
VACCS_HPV_POSITIVE,test_data/hpv/i_positive.csv,test_data/hpv/o_positive.csv,hpv
3+
VACCS_HPV_NEGATIVE,test_data/hpv/i_negative.csv,test_data/hpv/o_negative.csv,hpv
4+
VACCS_HIST_HPV_POSITIVE,test_data/hpv/i_hist_positive.csv,test_data/hpv/o_hist_positive.csv,hpv
5+
VACCS_HIST_HPV_NEGATIVE,test_data/hpv/i_hist_negative.csv,test_data/hpv/o_hist_negative.csv,hpv
6+
VACCS_HPV_DUP_1,test_data/hpv/i_dup_1.csv,test_data/hpv/o_dup_1.csv,hpv
7+
VACCS_HPV_DUP_2,test_data/hpv/i_dup_2.csv,test_data/hpv/o_dup_2.csv,hpv
8+
VACCS_HPV_INVALID_STRUCTURE,test_data/hpv/i_invalid_structure.csv,test_data/hpv/o_invalid_structure.csv,hpv
9+
VACCS_HPV_EMPTY_FILE,test_data/hpv/i_empty.csv,test_data/hpv/o_empty.csv,hpv
10+
VACCS_HPV_HEADER_ONLY,test_data/hpv/i_header_only.csv,test_data/hpv/o_header_only.csv,hpv
11+
COHORTS_POSITIVE,test_data/cohorts/i_positive.csv,test_data/cohorts/o_positive.csv,cohort
12+
COHORTS_NEGATIVE,test_data/cohorts/i_negative.csv,test_data/cohorts/o_negative.csv,cohort
13+
COHORTS_INVALID_STRUCTURE,test_data/cohorts/i_invalid_structure.csv,test_data/cohorts/o_invalid_structure.csv,cohort
14+
COHORTS_EMPTY_FILE,test_data/cohorts/i_empty.csv,test_data/cohorts/o_empty.csv,cohort
15+
COHORTS_HEADER_ONLY,test_data/cohorts/i_header_only.csv,test_data/cohorts/o_header_only.csv,cohort
16+
CHILD_POSITIVE,test_data/child/i_positive.csv,test_data/child/o_positive.csv,child
17+
CHILD_NEGATIVE,test_data/child/i_negative.csv,test_data/child/o_negative.csv,child
18+
CHILD_INVALID_STRUCTURE,test_data/child/i_invalid_structure.csv,test_data/child/o_invalid_structure.csv,child
19+
CHILD_EMPTY_FILE,test_data/child/i_empty.csv,test_data/child/o_empty.csv,child
20+
CHILD_HEADER_ONLY,test_data/child/i_header_only.csv,test_data/child/o_header_only.csv,child
21+
CLASS_POSITIVE,test_data/class_list/i_positive.csv,test_data/class_list/o_positive.csv,class
22+
CLASS_NEGATIVE,test_data/class_list/i_negative.csv,test_data/class_list/o_negative.csv,class
23+
CLASS_INVALID_STRUCTURE,test_data/class_list/i_invalid_structure.csv,test_data/class_list/o_invalid_structure.csv,class
24+
CLASS_EMPTY_FILE,test_data/class_list/i_empty.csv,test_data/class_list/o_empty.csv,class
25+
CLASS_HEADER_ONLY,test_data/class_list/i_header_only.csv,test_data/class_list/o_header_only.csv,class

0 commit comments

Comments
 (0)