# -*- coding: utf-8 -*- ## # Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. # copyright # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, # IN PART OR IN WHOLE, # WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # # file tst_create_patient_ID # date 2020/12/27 # author Joseph varghese # # NOTE: # This test is intended to be used to authenticate and authorize patient id in application . import names import test from dialin.ui import utils from dialin.ui import unittests from builtins import str as pyStr from dialin.configuration import utility CHARACTER_PATIENT_ID = ["qwerty","sampleid","abcdefghijklmnop","patientid", "username"] ALPHANUMERIC_PATIENT_ID = ["sample@123", "AJHDJ-BH78","678GHJ"] def keyboard_object_map_helper(text): """ Method for setting custom object property's for keyboard keys @return: required object property's for keys """ if isinstance(text, pyStr): names.keboard_input["text"] = text return names.keboard_input else: test.log(f"Invalid \"text\": {text} for object.") names.keyboard_input["text"] = "Q" def user_input_clear_option(): """ Tests to clear retained patient id @return: N/A """ patient_id_input = waitForObject(names.input_patient_id) patient_id = str(patient_id_input.text) patient_id_length = len(patient_id) while (patient_id_length != 0): type(waitForObject(names.input_patient_id), "") type(waitForObject(names.input_patient_id), "") patient_id_length = patient_id_length - 1 def authentication_of_valid_patient_id_through_keypad(expected_value): """ Tests verifies valid patient id set through application keyboard setup . @return: N/A """ patient_id_input = waitForObject(names.input_patient_id) mouseClick(patient_id_input) patient_id = list(expected_value) for text in patient_id: keyboard_value = keyboard_object_map_helper(text) mouseClick(waitForObject(keyboard_value)) utils.waitForGUI(.2) test.compare(expected_value, (patient_id_input.text)) test.log(f"Patient id should be -> {expected_value}") mouseClick(waitForObject(names.confirm_button)) custom_treatment = waitForObject(names.custom_treatment) test.compare("Create a Custom Treatment", custom_treatment.text) test.log(f"user successfully authenticated through user id {expected_value} using keypad.") mouseClick(waitForObject(names.back_button)) def authentication_of_valid_patient_id_through_user_input(expected_value): """ Tests verifies valid patient id set through user's input. @return: N/A """ patient_id_input = waitForObject(names.input_patient_id) mouseClick(waitForObject(patient_id_input)) type(waitForObject(names.input_patient_id), expected_value) test.compare(expected_value, (patient_id_input.text)) test.log(f"Patient id should be -> {expected_value}") mouseClick(waitForObject(names.confirm_button)) custom_treatment = waitForObject(names.custom_treatment) test.compare("Create a Custom Treatment", custom_treatment.text) test.log(f"user successfully authenticated through user id {expected_value}.") mouseClick(waitForObject(names.back_button)) def authentication_of_invalid_patient_id_through_user_input(expected_value): """ Tests verifies invalid patient id set through user's input. @return: N/A """ patient_id_input = waitForObject(names.input_patient_id) mouseClick(waitForObject(patient_id_input)) type(waitForObject(names.input_patient_id), expected_value) if expected_value is not patient_id_input.text or patient_id_input.text is None: test.passes(f"Patient ID -> {expected_value} should be invalid") else: test.xfail(f"Patient ID {expected_value} is valid") user_input_clear_option() def main(): utils.tstStart("tst_authentication") utility.launch_application("Authentication and authorization using patient ID") unittests.test_python_version() mouseClick(waitForObject(names.input_patient_id)) for patient_id in CHARACTER_PATIENT_ID: authentication_of_valid_patient_id_through_keypad(patient_id) authentication_of_valid_patient_id_through_user_input(patient_id) for patient_id in ALPHANUMERIC_PATIENT_ID: authentication_of_valid_patient_id_through_user_input(patient_id) utils.tstDone()