Skip to content

Commit 2f04c81

Browse files
FimranNHSfimran08
andauthored
Ved 825 (#39)
* patient Api and batch negative scenarios are complete * added patient detail and performer detail scenarios in APi and batch processing * final tests * fix issue * fix string issue * add retry in fetch delta table --------- Co-authored-by: fimran08 <[email protected]>
1 parent 2e21ba2 commit 2f04c81

16 files changed

+476
-89
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
],
2424
"cucumberautocomplete.strictGherkinCompletion": true,
2525
"cucumberautocomplete.smartSnippets": true,
26-
"cucumberautocomplete.skipDocStrings": true,
26+
"cucumberautocomplete.skipDocStringsFormat": true,
27+
"cucumberautocomplete.formatOnSave": true,
2728
"cucumberautocomplete.customParameters": [
2829
{
2930
"regex": "([A-Za-z0-9_]+)",

features/APITests/create.feature

Lines changed: 78 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,28 @@ Scenario Outline: Verify that the POST Create API will fail if occurrenceDateTim
109109
Given Valid json payload is created where occurrenceDateTime has invalid '<Date>' date
110110
When Trigger the post create request
111111
Then The request will be unsuccessful with the status code '400'
112-
And The Response JSONs should contain correct error message for 'invalid_OccurrenceDateTime'
112+
And The Response JSONs should contain correct error message for '<error_type>'
113113
Examples:
114-
| Date |
115-
| future_occurrence |
116-
| invalid_format |
117-
| nonexistent |
118-
| empty |
114+
| Date | error_type |
115+
| future_occurrence | invalid_OccurrenceDateTime |
116+
| invalid_format | invalid_OccurrenceDateTime |
117+
| nonexistent | invalid_OccurrenceDateTime |
118+
| empty | invalid_OccurrenceDateTime |
119+
| none | empty_OccurrenceDateTime |
119120

120121
@supplier_name_Postman_Auth @vaccine_type_RSV @patient_id_Random
121122
Scenario Outline: Verify that the POST Create API will fail if recorded has future or invalid formatted date
122123
Given Valid json payload is created where recorded has invalid '<Date>' date
123124
When Trigger the post create request
124125
Then The request will be unsuccessful with the status code '400'
125-
And The Response JSONs should contain correct error message for 'invalid_recorded'
126+
And The Response JSONs should contain correct error message for '<error_type>'
126127
Examples:
127-
| Date |
128-
| future_date |
129-
| invalid_format |
130-
| nonexistent |
131-
| empty |
128+
| Date | error_type |
129+
| future_date | invalid_recorded |
130+
| invalid_format | invalid_recorded |
131+
| nonexistent | invalid_recorded |
132+
| empty | invalid_recorded |
133+
| none | empty_recorded |
132134

133135
@supplier_name_Postman_Auth @vaccine_type_RSV @patient_id_Random
134136
Scenario Outline: Verify that the POST Create API will fail if patient's data of birth has future or invalid formatted date
@@ -142,6 +144,7 @@ Scenario Outline: Verify that the POST Create API will fail if patient's data of
142144
| invalid_format | invalid_DateOfBirth |
143145
| nonexistent | invalid_DateOfBirth |
144146
| empty | invalid_DateOfBirth |
147+
| none | missing_DateOfBirth |
145148

146149
@supplier_name_Postman_Auth @vaccine_type_RSV @patient_id_Random
147150
Scenario Outline: Verify that the POST Create API will fail if expiration date has invalid formatted date
@@ -153,4 +156,66 @@ Scenario Outline: Verify that the POST Create API will fail if expiration date h
153156
| Date |
154157
| invalid_format |
155158
| nonexistent |
156-
| empty |
159+
| empty |
160+
161+
@supplier_name_Postman_Auth @vaccine_type_RSV @patient_id_Random
162+
Scenario Outline: Verify that the POST Create API will fail if nhs number is invalid
163+
Given Valid json payload is created where Nhs number is invalid '<invalid_NhsNumber>'
164+
When Trigger the post create request
165+
Then The request will be unsuccessful with the status code '400'
166+
And The Response JSONs should contain correct error message for '<error_type>'
167+
Examples:
168+
|invalid_NhsNumber |error_type |
169+
|1234567890 |invalid_Mod11_NhsNumber |
170+
|12345678 |invalid_NHSNumber_length |
171+
172+
@supplier_name_Postman_Auth @vaccine_type_RSV @patient_id_Random
173+
Scenario Outline: Verify that the POST Create API will fail if patient forename is invalid
174+
Given Valid json payload is created where patient forename is '<forename>'
175+
When Trigger the post create request
176+
Then The request will be unsuccessful with the status code '400'
177+
And The Response JSONs should contain correct error message for '<error_type>'
178+
Examples:
179+
| forename | error_type |
180+
| empty | empty_forename |
181+
| missing | no_forename |
182+
| white_space_array | empty_forename |
183+
| single_value_max_len | max_len_forename |
184+
| max_len_array | max_item_forename |
185+
186+
@supplier_name_Postman_Auth @vaccine_type_RSV @patient_id_Random
187+
Scenario Outline: Verify that the POST Create API will fail if patient surname is invalid
188+
Given Valid json payload is created where patient surname is '<surname>'
189+
When Trigger the post create request
190+
Then The request will be unsuccessful with the status code '400'
191+
And The Response JSONs should contain correct error message for '<error_type>'
192+
Examples:
193+
| surname | error_type |
194+
| empty | empty_surname |
195+
| missing | no_surname |
196+
| white_space | empty_surname |
197+
| name_length_36 | max_len_surname |
198+
199+
@supplier_name_Postman_Auth @vaccine_type_RSV @patient_id_Random
200+
Scenario: Verify that the POST Create API will fail if patient name is empty
201+
Given Valid json payload is created where patient name is empty
202+
When Trigger the post create request
203+
Then The request will be unsuccessful with the status code '400'
204+
And The Response JSONs should contain correct error message for 'empty_forename_surname'
205+
206+
@supplier_name_Postman_Auth @vaccine_type_RSV @patient_id_Random
207+
Scenario Outline: Verify that the POST Create API will fail if patient gender is invalid
208+
Given Valid json payload is created where patient gender is '<gender>'
209+
When Trigger the post create request
210+
Then The request will be unsuccessful with the status code '400'
211+
And The Response JSONs should contain correct error message for '<error_type>'
212+
Examples:
213+
| gender | error_type |
214+
| random_text | invalid_gender |
215+
| empty | empty_gender |
216+
| number | should_be_string |
217+
| gender_code | invalid_gender |
218+
| missing | missing_gender |
219+
220+
221+

features/APITests/steps/test_create_steps.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
import logging
1010
from pytest_bdd import scenarios, given, when, then, parsers
1111
import pytest_check as check
12-
from .common_steps import *
13-
14-
15-
logging.basicConfig(filename='debugLog.log', level=logging.INFO)
16-
logger = logging.getLogger(__name__)
1712

13+
from utilities.text_helper import get_text
14+
from .common_steps import *
1815

1916
scenarios('APITests/create.feature')
2017

@@ -192,4 +189,42 @@ def validate_procedure_term_blank_in_delta_table(context):
192189
assert actual_terms["procedure_term"] == "", f"Expected procedure term text to be blank, but got '{actual_terms['procedure_term']}'"
193190
assert actual_terms["product_term"] == "", f"Expected product term text to be blank, but got '{actual_terms['product_term']}'"
194191
assert actual_terms["site_term"] == "", f"Expected site of vaccination term text to be blank, but got '{actual_terms['site_term']}'"
195-
assert actual_terms["route_term"] == "", f"Expected route of vaccination term text to be blank, but got '{actual_terms['route_term']}'"
192+
assert actual_terms["route_term"] == "", f"Expected route of vaccination term text to be blank, but got '{actual_terms['route_term']}'"
193+
194+
195+
@given(parsers.parse("Valid json payload is created where Nhs number is invalid '{invalid_NhsNumber}'"))
196+
def create_request_with_invalid_Nhsnumber(context, invalid_NhsNumber):
197+
valid_json_payload_is_created(context)
198+
context.immunization_object.contained[1].identifier[0].value = invalid_NhsNumber
199+
200+
@given(parsers.parse("Valid json payload is created where patient forename is '{forename}'"))
201+
def create_request_with_invalid_forename(context, forename):
202+
valid_json_payload_is_created(context)
203+
if forename == 'single_value_max_len':
204+
context.immunization_object.contained[1].name[0].given = [get_text("name_length_36")]
205+
elif forename == 'max_len_array':
206+
context.immunization_object.contained[1].name[0].given = [
207+
get_text("name_length_15"),
208+
get_text("name_length_5"),
209+
get_text("name_length_5"),
210+
get_text("name_length_10"),
211+
get_text("name_length_10"),
212+
get_text("name_length_10"),
213+
]
214+
else:
215+
context.immunization_object.contained[1].name[0].given = get_text(forename)
216+
217+
@given(parsers.parse("Valid json payload is created where patient surname is '{surname}'"))
218+
def create_request_with_invalid_surname(context, surname):
219+
valid_json_payload_is_created(context)
220+
context.immunization_object.contained[1].name[0].family = get_text(surname)
221+
222+
@given(parsers.parse("Valid json payload is created where patient gender is '{gender}'"))
223+
def create_request_with_invalid_surname(context, gender):
224+
valid_json_payload_is_created(context)
225+
context.immunization_object.contained[1].gender = get_text(gender)
226+
227+
@given("Valid json payload is created where patient name is empty")
228+
def create_request_with_empty_nam(context):
229+
valid_json_payload_is_created(context)
230+
context.immunization_object.contained[1].name = None

features/batchTests/Steps/batch_common_steps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def valid_batch_file_is_created(context):
6868
save_record_to_batch_files_directory(context)
6969
print(f"Batch file created: {context.filename}")
7070

71-
@when("batch file upload in s3 bucket")
71+
@when("batch file is uploaded in s3 bucket")
7272
@ignore_local_run_set_test_data
7373
def batch_file_upload_in_s3_bucket(context):
7474
upload_file_to_S3(context)
@@ -79,7 +79,7 @@ def batch_file_upload_in_s3_bucket(context):
7979
@then("file will be moved to destination bucket and inf ack file will be created")
8080
def file_will_be_moved_to_destination_bucket(context):
8181
context.fileContent = wait_and_read_ack_file(context, "ack")
82-
assert context.fileContent, f"File not found in destination bucket after timeout: {context.forwarded_prefix}"
82+
assert context.fileContent, f"File not found in destination bucket after timeout: {context.forwarded_prefix}"
8383

8484
@then("inf ack file has success status for processed batch file")
8585
def all_records_are_processed_successfully_in_the_inf_ack_file(context):
@@ -96,7 +96,7 @@ def all_records_are_processed_successfully_in_the_batch_file(context):
9696
all_valid = validate_bus_ack_file(context)
9797
assert all_valid, "One or more records failed validation checks"
9898

99-
@then("Audit table will have correct status and queue name for the processed batch file")
99+
@then("Audit table will have correct status, queue name and record count for the processed batch file")
100100
def validate_imms_audit_table(context):
101101
table_query_response = fetch_batch_audit_table_detail(context.aws_profile_name, context.filename, context.S3_env)
102102

features/batchTests/Steps/test_create_batch_steps.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from utilities.batch_S3_buckets import *
55
from utilities.batch_file_helper import *
66
from utilities.date_helper import *
7+
from utilities.text_helper import get_text
78
from utilities.vaccination_constants import *
89
from pytest_bdd import scenarios, given, when, then, parsers
910
import pytest_check as check
@@ -44,6 +45,49 @@ def valid_batch_file_is_created_with_invalid_person_dateOfBirth_date(datatable,
4445
build_dataFrame_using_datatable(datatable, context)
4546
context.vaccine_df['PERSON_DOB'] = context.vaccine_df['UNIQUE_ID'].apply(lambda uid: get_batch_date(uid.split('-')[1]))
4647
create_batch_file(context)
48+
49+
@given("batch file is created for below data where Person detail has invalid data")
50+
@ignore_if_local_run
51+
def valid_batch_file_is_created_with_invalid_patient_data(datatable, context):
52+
build_dataFrame_using_datatable(datatable, context)
53+
context.vaccine_df.loc[0,["NHS_NUMBER"]] = "12345678"
54+
context.vaccine_df.loc[1,["NHS_NUMBER"]] = "1234567890"
55+
context.vaccine_df.loc[2,["PERSON_FORENAME"]] = ""
56+
context.vaccine_df.loc[3,["PERSON_FORENAME", "PERSON_SURNAME"]] = ""
57+
context.vaccine_df.loc[4,["PERSON_SURNAME"]] = ""
58+
context.vaccine_df.loc[5,["PERSON_GENDER_CODE"]] = "8"
59+
context.vaccine_df.loc[6,["PERSON_GENDER_CODE"]] = "unknow"
60+
context.vaccine_df.loc[7,["PERSON_GENDER_CODE"]] = ""
61+
context.vaccine_df.loc[8,["PERSON_FORENAME"]] = " "
62+
context.vaccine_df.loc[9,["PERSON_SURNAME"]] = " "
63+
context.vaccine_df.loc[10,["PERSON_SURNAME"]] = get_text("name_length_36")
64+
context.vaccine_df.loc[11,["PERSON_FORENAME"]] = get_text("name_length_36")
65+
create_batch_file(context)
66+
67+
@given("batch file is created for below data where performer detail has invalid data")
68+
@ignore_if_local_run
69+
def valid_batch_file_is_created_with_invalid_performer_data(datatable, context):
70+
build_dataFrame_using_datatable(datatable, context)
71+
context.vaccine_df.loc[0,["PERFORMING_PROFESSIONAL_FORENAME"]] = ""
72+
context.vaccine_df.loc[1,["PERFORMING_PROFESSIONAL_SURNAME"]] = ""
73+
create_batch_file(context)
74+
75+
@given("batch file is created for below data where person detail has valid values")
76+
@ignore_if_local_run
77+
def valid_batch_file_is_created_with_different_values_gender(datatable, context):
78+
build_dataFrame_using_datatable(datatable, context)
79+
context.vaccine_df.loc[0,["PERSON_GENDER_CODE"]] = "0"
80+
context.vaccine_df.loc[1,["PERSON_GENDER_CODE"]] = "1"
81+
context.vaccine_df.loc[2,["PERSON_GENDER_CODE"]] = "2"
82+
context.vaccine_df.loc[3,["PERSON_GENDER_CODE"]] = "9"
83+
context.vaccine_df.loc[4,["PERSON_GENDER_CODE"]] = "unknown"
84+
context.vaccine_df.loc[5,["PERSON_GENDER_CODE"]] = "male"
85+
context.vaccine_df.loc[6,["PERSON_GENDER_CODE"]] = "female"
86+
context.vaccine_df.loc[7,["PERSON_GENDER_CODE"]] = "other"
87+
context.vaccine_df.loc[8,["PERSON_SURNAME"]] = get_text("name_length_35")
88+
context.vaccine_df.loc[9,["PERSON_FORENAME"]] = get_text("name_length_35")
89+
context.vaccine_df.loc[10,["PERSON_FORENAME"]] = f'Elan {get_text("name_length_15")}'
90+
create_batch_file(context)
4791

4892
@then("all records are rejected in the bus ack file and no imms id is generated")
4993
def all_record_are_rejected_for_given_field_name(context):

0 commit comments

Comments
 (0)