def test_test(): database.reinit() query_text = 'select * from test where uid = %s' requests = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'request.json'))['Requests'] results = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'result.json'))['Results'] response = api_request.ApiRequest.do_doctor_request(requests[0]) assert response.status_code == 200 responseContent = json.loads(response.content) assert len(responseContent['Tests']) == 1 testUID = responseContent['Tests'][0]['Uid'] req = requests[1] req['API'] = req['API'] + testUID response = api_request.ApiRequest.do_doctor_request(req) assert response.status_code == 200 responseContent = json.loads(response.content) assert responseContent['Name'] == results[0]['Name'] assert responseContent['Specialty'] == results[0]['Specialty'] assert responseContent['Questions'] == results[0]['Questions'] req = requests[2] req['API'] = req['API'] + testUID response = api_request.ApiRequest.do_doctor_request(req) assert response.status_code == 200 query = database.query(query_text, testUID) assert len(query) == 0
def test_filled_tests(): database.reinit() query_text = 'select * from filled_test where uid = %s' requests = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'request.json'))['Requests'] results = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'result.json'))['Results'] response = api_request.ApiRequest.do_doctor_request(requests[0]) assert response.status_code == 200 responseContent = json.loads(response.content) filledTestUid = responseContent['Uid'] query = database.query(query_text, filledTestUid) assert len(query) == 1 assert query[0][1] == results[0]['ExaminationUid'] assert query[0][2] == results[0]['TestUid'] assert query[0][3] == results[0]['Answers'] response = api_request.ApiRequest.do_doctor_request(requests[1]) assert response.status_code == 200 responseContent = json.loads(response.content) assert len(responseContent['FilledTests']) == 2 assert responseContent['FilledTests'][1]['TestName'] == results[1][ 'TestName'] assert responseContent['FilledTests'][1]['PatientName'] == results[1][ 'PatientName'] assert responseContent['FilledTests'][1]['PatientUid'] == results[1][ 'PatientUid'] req = requests[2] req['API'] = req['API'] + filledTestUid response = api_request.ApiRequest.do_doctor_request(req) assert response.status_code == 200 responseContent = json.loads(response.content) assert responseContent['TestName'] == results[2]['TestName'] assert responseContent['TestUid'] == results[2]['TestUid'] assert responseContent['ExaminationUID'] == results[2]['ExaminationUID'] assert responseContent['Answers'] == results[2]['Answers'] req = requests[3] req['API'] = req['API'] + filledTestUid response = api_request.ApiRequest.do_doctor_request(req) assert response.status_code == 200 query = database.query(query_text, filledTestUid) assert len(query) == 0
def test_examination(): database.reinit() query_text = 'select * from examination where uid = %s' requests = json_utils.parse_json(os.path.join(os.path.dirname(__file__), 'request.json'))['Requests'] results = json_utils.parse_json(os.path.join(os.path.dirname(__file__), 'result.json'))['Results'] response = api_request.ApiRequest.do_nurse_request(requests[0]) assert response.status_code== 200 responseContent = json.loads(response.content) examinationUID = responseContent['Uid'] query = database.query(query_text, examinationUID) assert len(query)==1 assert query[0][1] == results[0]['DoctorUid'] assert query[0][2] == results[0]['DoctorName'] assert query[0][3] == results[0]['PatientUid'] assert query[0][4] == results[0]['PatientName'] examinationDate = datetime.datetime.strptime(results[0]['ExaminationDate'], '%Y-%m-%dT%H:%M:%SZ') assert query[0][5] == examinationDate.date() response = api_request.ApiRequest.do_nurse_request(requests[1]) assert response.status_code== 200 responseContent = json.loads(response.content) assert len(responseContent['Examinations'])==2 assert responseContent['Examinations'][1]['DoctorUid'] == results[0]['DoctorUid'] assert responseContent['Examinations'][1]['DoctorFullName'] == results[0]['DoctorName'] assert responseContent['Examinations'][1]['PatientUid'] == results[0]['PatientUid'] assert responseContent['Examinations'][1]['PatientFullName'] == results[0]['PatientName'] assert responseContent['Examinations'][1]['ExaminationDate'] == results[0]['ExaminationDate'] response = api_request.ApiRequest.do_doctor_request(requests[2]) assert response.status_code== 200 responseContent = json.loads(response.content) assert len(responseContent['Examinations']) == 2 req = requests[3] req['API'] = req['API'] + examinationUID response = api_request.ApiRequest.do_nurse_request(req) assert response.status_code== 200 query = database.query(query_text, examinationUID) assert len(query)==0
def test_change_pass(): database.reinit() requests = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'request.json'))['Requests'] response = api_request.ApiRequest.do_admin_request(requests[0]) assert response.status_code == 200 response = api_request.ApiRequest.do_admin_request(requests[1]) assert response.status_code == 200 response = api_request.ApiRequest.do_admin_request(requests[2]) assert response.status_code == 200
def test_login_logout(): database.reinit() query_text = 'select * from login_session where system_user_uid = %s and token = %s' requests = json_utils.parse_json(os.path.join(os.path.dirname(__file__), 'request.json'))['Requests'] response = api_request.ApiRequest.login_test_request(requests[0]) assert response.status_code== 200 responseContent = json.loads(response.content) userUID = responseContent['UserUID'] auth = responseContent['Authorization'] query = database.query(query_text, userUID, auth) assert len(query) == 1 response = api_request.ApiRequest.login_test_request(requests[1],auth) assert response.status_code== 200 query = database.query(query_text, userUID, auth) assert len(query) == 0 response = api_request.ApiRequest.login_test_request(requests[2]) assert response.status_code== 401
def test_employee(): database.reinit() query_text = 'select * from employee where uid = %s' second_query_text = 'select * from person where uid = %s' requests = json_utils.parse_json(os.path.join(os.path.dirname(__file__), 'request.json'))['Requests'] results = json_utils.parse_json(os.path.join(os.path.dirname(__file__), 'result.json'))['Results'] response = api_request.ApiRequest.do_admin_request(requests[0]) assert response.status_code== 200 responseContent = json.loads(response.content) employeeUID = responseContent['Uid'] query = database.query(query_text, employeeUID) assert len(query)==1 personUID = query[0][1] assert query[0][2] == results[0]['WorkDocumentId'] assert query[0][3] == results[0]['RoleId'] query = database.query(second_query_text, personUID) assert query[0][1] == results[0]['Name'] assert query[0][2] == results[0]['Surname'] assert query[0][3] == results[0]['JMBG'] response = api_request.ApiRequest.do_admin_request(requests[1]) assert response.status_code== 200 responseContent = json.loads(response.content) employeeUID = responseContent['Uid'] query = database.query(query_text, employeeUID) assert len(query)==1 personUID = query[0][1] assert query[0][2] == results[1]['WorkDocumentId'] assert query[0][3] == results[1]['RoleId'] query = database.query(second_query_text, personUID) assert query[0][1] == results[1]['Name'] assert query[0][2] == results[1]['Surname'] assert query[0][3] == results[1]['JMBG'] req = requests[2] req['API'] = req['API'] + employeeUID response = api_request.ApiRequest.do_admin_request(req) assert response.status_code== 200 query = database.query(query_text, employeeUID) assert len(query)==1 personUID = query[0][1] assert query[0][2] == results[2]['WorkDocumentId'] assert query[0][3] == results[2]['RoleId'] query = database.query(second_query_text, personUID) assert query[0][1] == results[2]['Name'] assert query[0][2] == results[2]['Surname'] assert query[0][3] == results[2]['JMBG'] response = api_request.ApiRequest.do_admin_request(requests[3]) assert response.status_code== 200 responseContent = json.loads(response.content) # Four employees are added on initialization and two in this test assert len(responseContent['Employees']) == 6 assert responseContent['Employees'][5]['WorkDocumentId'] == results[2]['WorkDocumentId'] assert responseContent['Employees'][5]['Name'] == results[2]['Name'] assert responseContent['Employees'][5]['Surname'] == results[2]['Surname'] assert responseContent['Employees'][5]['RoleId'] == results[2]['RoleId'] req = requests[4] req['API'] = req['API'] + employeeUID response = api_request.ApiRequest.do_admin_request(req) assert response.status_code== 200 responseContent = json.loads(response.content) assert responseContent['Name'] == results[2]['Name'] assert responseContent['Surname'] == results[2]['Surname'] assert responseContent['RoleId'] == results[2]['RoleId'] assert responseContent['JMBG'] == results[2]['JMBG'] assert responseContent['Email'] == results[2]['Email'] response = api_request.ApiRequest.do_nurse_request(requests[5]) assert response.status_code== 200 responseContent = json.loads(response.content) assert len(responseContent['Employees']) == 2 assert responseContent['Employees'][0]['WorkDocumentId'] == results[3]['Employees'][0]['WorkDocumentId'] assert responseContent['Employees'][0]['Name'] == results[3]['Employees'][0]['Name'] assert responseContent['Employees'][0]['Surname'] == results[3]['Employees'][0]['Surname'] assert responseContent['Employees'][1]['WorkDocumentId'] == results[3]['Employees'][1]['WorkDocumentId'] assert responseContent['Employees'][1]['Name'] == results[3]['Employees'][1]['Name'] assert responseContent['Employees'][1]['Surname'] == results[3]['Employees'][1]['Surname'] req = requests[6] req['API'] = req['API'] + employeeUID response = api_request.ApiRequest.do_admin_request(req) assert response.status_code== 200 query = database.query(query_text, employeeUID) assert len(query)==0
def test_user(): database.reinit() query_text = 'select * from system_user where uid = %s' second_query_text = 'select * from employee where uid = %s' requests = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'request.json'))['Requests'] results = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'result.json'))['Results'] response = api_request.ApiRequest.do_admin_request(requests[0]) assert response.status_code == 200 responseContent = json.loads(response.content) userUID = responseContent['Uid'] query = database.query(query_text, userUID) assert len(query) == 1 employeeUID = query[0][1] assert query[0][2] == results[0]['Username'] assert query[0][3] == results[0]['Password'] query = database.query(second_query_text, employeeUID) assert query[0][2] == results[0]['WorkDocumentId'] assert query[0][3] == results[0]['RoleId'] response = api_request.ApiRequest.do_admin_request(requests[1]) assert response.status_code == 200 responseContent = json.loads(response.content) userUID = responseContent['Uid'] query = database.query(query_text, userUID) assert len(query) == 1 employeeUID = query[0][1] assert query[0][2] == results[1]['Username'] assert query[0][3] == results[1]['Password'] query = database.query(second_query_text, employeeUID) assert query[0][2] == results[1]['WorkDocumentId'] assert query[0][3] == results[1]['RoleId'] req = requests[2] req['API'] = req['API'] + userUID response = api_request.ApiRequest.do_admin_request(req) assert response.status_code == 200 query = database.query(query_text, userUID) assert len(query) == 1 employeeUID = query[0][1] assert query[0][2] == results[2]['Username'] assert query[0][3] == results[2]['Password'] query = database.query(second_query_text, employeeUID) assert query[0][2] == results[2]['WorkDocumentId'] assert query[0][3] == results[2]['RoleId'] response = api_request.ApiRequest.do_admin_request(requests[3]) assert response.status_code == 200 responseContent = json.loads(response.content) # Four ussers are added on initialization and two in this test assert len(responseContent['Users']) == 6 req = requests[4] req['API'] = req['API'] + userUID response = api_request.ApiRequest.do_admin_request(req) assert response.status_code == 200 responseContent = json.loads(response.content) assert responseContent['Name'] == results[2]['Name'] assert responseContent['Surname'] == results[2]['Surname'] assert responseContent['RoleId'] == results[2]['RoleId'] req = requests[5] req['API'] = req['API'] + userUID response = api_request.ApiRequest.do_admin_request(req) assert response.status_code == 200 query = database.query(query_text, userUID) assert len(query) == 0
def get_admin_header(): header = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'admin.json')) return header
def get_researcher_header(): header = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'researcher.json')) return header
def get_nurse_header(): header = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'nurse.json')) return header
def get_doctor_header(): header = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'doctor.json')) return header
def test_person(): database.reinit() query_text = 'select * from person where uid = %s' requests = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'request.json'))['Requests'] results = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'result.json'))['Results'] response = api_request.ApiRequest.do_admin_request(requests[0]) assert response.status_code == 200 responseContent = json.loads(response.content) personUID = responseContent['Uid'] query = database.query(query_text, personUID) assert len(query) == 1 assert query[0][1] == results[0]['Name'] assert query[0][2] == results[0]['Surname'] assert query[0][3] == results[0]['JMBG'] date_of_birth = datetime.datetime.strptime(results[0]['DateOfBirth'], '%Y-%m-%dT%H:%M:%SZ') assert query[0][4] == date_of_birth.date() assert query[0][5] == results[0]['Address'] assert query[0][6] == results[0]['Email'] req = requests[1] req['API'] = req['API'] + personUID response = api_request.ApiRequest.do_admin_request(req) assert response.status_code == 200 query = database.query(query_text, personUID) assert len(query) == 1 assert query[0][1] == results[1]['Name'] assert query[0][2] == results[1]['Surname'] assert query[0][3] == results[1]['JMBG'] date_of_birth = datetime.datetime.strptime(results[1]['DateOfBirth'], '%Y-%m-%dT%H:%M:%SZ') assert query[0][4] == date_of_birth.date() assert query[0][5] == results[1]['Address'] assert query[0][6] == results[1]['Email'] response = api_request.ApiRequest.do_admin_request(requests[2]) assert response.status_code == 200 responseContent = json.loads(response.content) # Four persons are added on initialization and one in this test assert len(responseContent['Persons']) == 5 assert responseContent['Persons'][4]['Name'] == results[1]['Name'] assert responseContent['Persons'][4]['Surname'] == results[1]['Surname'] assert responseContent['Persons'][4]['JMBG'] == results[1]['JMBG'] req = requests[3] req['API'] = req['API'] + personUID response = api_request.ApiRequest.do_admin_request(req) assert response.status_code == 200 responseContent = json.loads(response.content) assert responseContent['Name'] == results[1]['Name'] assert responseContent['Surname'] == results[1]['Surname'] assert responseContent['JMBG'] == results[1]['JMBG'] assert responseContent['DateOfBirth'] == results[1]['DateOfBirth'] assert responseContent['Address'] == results[1]['Address'] assert responseContent['Email'] == results[1]['Email'] req = requests[4] req['API'] = req['API'] + personUID response = api_request.ApiRequest.do_admin_request(req) assert response.status_code == 200 query = database.query(query_text, personUID) assert len(query) == 0
def test_patient(): database.reinit() query_text = 'select * from patient where uid = %s' second_query_text = 'select * from person where uid = %s' requests = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'request.json'))['Requests'] results = json_utils.parse_json( os.path.join(os.path.dirname(__file__), 'result.json'))['Results'] response = api_request.ApiRequest.do_nurse_request(requests[0]) assert response.status_code == 200 responseContent = json.loads(response.content) employeeUID = responseContent['Uid'] query = database.query(query_text, employeeUID) assert len(query) == 1 personUID = query[0][1] assert query[0][2] == results[0]['MedicalRecordId'] assert query[0][3] == results[0]['HealthCardId'] query = database.query(second_query_text, personUID) assert query[0][1] == results[0]['Name'] assert query[0][2] == results[0]['Surname'] assert query[0][3] == results[0]['JMBG'] response = api_request.ApiRequest.do_nurse_request(requests[1]) assert response.status_code == 200 responseContent = json.loads(response.content) patientUID = responseContent['Uid'] query = database.query(query_text, patientUID) assert len(query) == 1 personUID = query[0][1] assert query[0][2] == results[1]['MedicalRecordId'] assert query[0][3] == results[1]['HealthCardId'] query = database.query(second_query_text, personUID) assert query[0][1] == results[1]['Name'] assert query[0][2] == results[1]['Surname'] assert query[0][3] == results[1]['JMBG'] req = requests[2] req['API'] = req['API'] + patientUID response = api_request.ApiRequest.do_nurse_request(req) assert response.status_code == 200 query = database.query(query_text, patientUID) assert len(query) == 1 personUID = query[0][1] assert query[0][2] == results[2]['MedicalRecordId'] assert query[0][3] == results[2]['HealthCardId'] query = database.query(second_query_text, personUID) assert query[0][1] == results[2]['Name'] assert query[0][2] == results[2]['Surname'] assert query[0][3] == results[2]['JMBG'] response = api_request.ApiRequest.do_nurse_request(requests[3]) assert response.status_code == 200 responseContent = json.loads(response.content) #Two patients are added on initialization and two now assert len(responseContent['Patients']) == 4 assert responseContent['Patients'][3]['MedicalRecordId'] == results[2][ 'MedicalRecordId'] assert responseContent['Patients'][3]['Name'] == results[2]['Name'] assert responseContent['Patients'][3]['Surname'] == results[2]['Surname'] assert responseContent['Patients'][3]['HealthCardId'] == results[2][ 'HealthCardId'] req = requests[4] req['API'] = req['API'] + patientUID response = api_request.ApiRequest.do_nurse_request(req) assert response.status_code == 200 responseContent = json.loads(response.content) assert responseContent['Name'] == results[2]['Name'] assert responseContent['Surname'] == results[2]['Surname'] assert responseContent['HealthCardId'] == results[2]['HealthCardId'] assert responseContent['JMBG'] == results[2]['JMBG'] assert responseContent['Email'] == results[2]['Email'] req = requests[5] req['API'] = req['API'] + patientUID response = api_request.ApiRequest.do_nurse_request(req) assert response.status_code == 200 query = database.query(query_text, patientUID) assert len(query) == 0