def test_list_put(self): # Pre-Req Utils.send_consent_post(self.token) Utils.send_list_post(self.token) get_list_response = Utils.send_list_get(self.token) list_id = get_list_response['id'] version_id = get_list_response['version'] # Given expected_status_code = 200 req_body = request_bank.get_body(Request.LIST_PUT) req_body['id'] = list_id # When response = requests.put( url=config.REASONABLE_ADJUSTMENTS_LIST + '/' + list_id, headers={ 'Authorization': f'Bearer {self.token}', 'nhsd-session-urid': config.TEST_NHSD_SESSION_URID, 'x-request-id': str(uuid.uuid4()), 'content-type': 'application/fhir+json', 'accept': 'application/fhir+json', 'if-match': version_id, }, data=json.dumps(req_body) ) # Then assert_that(expected_status_code).is_equal_to(response.status_code)
def test_consent_put(self): # Pre-Req Utils.send_consent_post(self.token) # Given expected_status_code = 200 # And consent = Utils.send_consent_get(self.token) consent_id = consent['id'] version_id = consent['version'] # When response = requests.put( url=config.REASONABLE_ADJUSTMENTS_CONSENT + '/' + consent_id, json=request_bank.get_body(Request.CONSENT_PUT), headers={ 'Authorization': f'Bearer {self.token}', 'nhsd-session-urid': config.TEST_NHSD_SESSION_URID, 'x-request-id': str(uuid.uuid4()), 'content-type': 'application/fhir+json', 'If-Match': version_id } ) # Then assert_that(expected_status_code).is_equal_to(response.status_code)
def test_flag_put(self): # Pre-Req: Patient has both a consent and flag Utils.send_consent_post(self.token) Utils.send_flag_post(self.token) get_flag_response = Utils.send_flag_get(self.token) # Given expected_status_code = 200 flag_id = get_flag_response['id'] version_id = get_flag_response['version'] # When response = requests.put( url=config.REASONABLE_ADJUSTMENTS_FLAG + '/' + flag_id, headers={ 'Authorization': f'Bearer {self.token}', 'nhsd-session-urid': config.TEST_NHSD_SESSION_URID, 'x-request-id': str(uuid.uuid4()), 'content-type': 'application/fhir+json', 'Accept': 'application/fhir+json', 'If-match': version_id, }, json=request_bank.get_body(Request.FLAG_PUT) ) # Then assert_that(expected_status_code).is_equal_to(response.status_code)
def send_raremoverecord_post(auth_token: str): response = requests.post( url=config.REASONABLE_ADJUSTMENTS_REMOVE_RA_RECORD, headers={ 'Authorization': f'Bearer {auth_token}', 'nhsd-session-urid': config.TEST_NHSD_SESSION_URID, 'x-request-id': str(uuid.uuid4()), 'content-type': 'application/fhir+json', 'If-Match': 'W/"1"' }, json=request_bank.get_body(Request.REMOVE_RA_RECORD_POST)) return response
def send_list_post(auth_token: str): response = requests.post( url=config.REASONABLE_ADJUSTMENTS_LIST, headers={ 'Authorization': f'Bearer {auth_token}', 'nhsd-session-urid': config.TEST_NHSD_SESSION_URID, 'x-request-id': str(uuid.uuid4()), 'content-type': 'application/fhir+json' }, json=request_bank.get_body(Request.LIST_POST), ) return response
def send_consent_post(auth_token: str): expected_status_code = 201 response = requests.post( url=config.REASONABLE_ADJUSTMENTS_CONSENT, json=request_bank.get_body(Request.CONSENT_POST), headers={ 'Authorization': f'Bearer {auth_token}', 'nhsd-session-urid': config.TEST_NHSD_SESSION_URID, 'x-request-id': str(uuid.uuid4()), 'content-type': 'application/fhir+json' }) assert_that(expected_status_code).is_equal_to(response.status_code) return response
def test_prefer_response_async(self): # Given expected_status_code = 202 # When response = requests.post( url=config.REASONABLE_ADJUSTMENTS_CONSENT, json=request_bank.get_body(Request.CONSENT_POST), headers={ 'Authorization': f'Bearer {self.token}', 'nhsd-session-urid': config.TEST_NHSD_SESSION_URID, 'x-request-id': str(uuid.uuid4()), 'content-type': 'application/fhir+json', 'Prefer': 'respond-async' } ) # Then assert_that(response.status_code).is_equal_to(expected_status_code)
def test_prefer_response_async(self): # Given expected_status_code = 202 expected_poll_status_code = 201 # When response = requests.post( url=config.REASONABLE_ADJUSTMENTS_CONSENT, json=request_bank.get_body(Request.CONSENT_POST), headers={ 'Authorization': f'Bearer {self.token}', 'nhsd-session-urid': config.TEST_NHSD_SESSION_URID, 'x-request-id': str(uuid.uuid4()), 'content-type': 'application/fhir+json', 'Prefer': 'respond-async' }) if not 'sandbox' in config.REASONABLE_ADJUSTMENTS_BASE_URL: poll_url = response.headers['Content-Location'] loop = True while loop: poll_response = requests.get(url=poll_url, headers={ 'Authorization': f'Bearer {self.token}', 'nhsd-session-urid': config.TEST_NHSD_SESSION_URID, 'x-request-id': str(uuid.uuid4()), 'content-type': 'application/fhir+json' }) loop = False if poll_response.status_code == 202: loop = True # Then assert_that(response.status_code).is_equal_to(expected_status_code) if not 'sandbox' in config.REASONABLE_ADJUSTMENTS_BASE_URL: assert_that(poll_response.status_code).is_equal_to( expected_poll_status_code)
def test_remove_ra_record_post(self): # Pre_Req : Patient record with a consent Utils.send_consent_post(self.token) # Given expected_status_code = 200 # When response = requests.post( url=config.REASONABLE_ADJUSTMENTS_REMOVE_RA_RECORD, headers={ 'Authorization': f'Bearer {self.token}', 'nhsd-session-urid': config.TEST_NHSD_SESSION_URID, 'x-request-id': str(uuid.uuid4()), 'content-type': 'application/fhir+json', 'If-Match': 'W/"1"' }, json=request_bank.get_body(Request.REMOVE_RA_RECORD_POST)) # Then assert_that(expected_status_code).is_equal_to(response.status_code)
def test_list_post(self): # Pre-Req - Patient has consent Utils.send_consent_post(self.token) # Given expected_status_code = 201 # When response = requests.post(url=config.REASONABLE_ADJUSTMENTS_LIST, headers={ 'Authorization': f'Bearer {self.token}', 'nhsd-session-urid': config.TEST_NHSD_SESSION_URID, 'x-request-id': str(uuid.uuid4()), 'content-type': 'application/fhir+json', 'Accept': 'application/fhir+json' }, json=request_bank.get_body(Request.LIST_POST)) # Then assert_that(expected_status_code).is_equal_to(response.status_code)
def test_duplicate_consent_record(self): # Pre-Req Utils.send_consent_post(self.token) # Given expected_status_code = 422 # When response = requests.post(url=config.REASONABLE_ADJUSTMENTS_CONSENT, json=request_bank.get_body( Request.CONSENT_POST), headers={ 'Authorization': f'Bearer {self.token}', 'nhsd-session-urid': '093895563513', 'x-request-id': str(uuid.uuid4()), 'content-type': 'application/fhir+json', 'Accept': 'application/fhir+json' }) response_body = json.loads(response.text) # Then assert_that(expected_status_code).is_equal_to(response.status_code) assert_that('duplicate').is_equal_to(response_body['issue'][0]['code'])