Index: tst_main_treatment_pressure/test.py =================================================================== diff -u -re3f67a6e78d267bb99596ba1ce439c6fe7d89a25 -rcdc2b6ae80bb42957f9e1e225f5f64140614efd6 --- tst_main_treatment_pressure/test.py (.../test.py) (revision e3f67a6e78d267bb99596ba1ce439c6fe7d89a25) +++ tst_main_treatment_pressure/test.py (.../test.py) (revision cdc2b6ae80bb42957f9e1e225f5f64140614efd6) @@ -16,9 +16,14 @@ from builtins import int as pyInt from configuration.config import * from configuration.utility import * +from configuration import application_init from dialin.ui import utils from dialin.ui.hd_simulator import HDSimulator +from configuration import utility +from dialin.common.msg_ids import MsgIds +from dialin.common import msg_defs + in_range_color = "#ffffff" out_of_range_color = "#c53b33" ART_LOW_VAL_MINUS_120 = -120 @@ -46,7 +51,35 @@ ACCEPTED = 0 hd_simulator = HDSimulator() +# the values for testing the slider and logging for pressure limit adjustment dialog +ADJUST_PRESSURE_LIMIT_TEST_VALUES = [ + {"arterial_window":120, "venous_window" : 100, "venous_asymmetric":20}, + {"arterial_window":120, "venous_window" : 140, "venous_asymmetric":35}, + {"arterial_window":200, "venous_window" : 120, "venous_asymmetric":20}, + {"arterial_window":160, "venous_window" : 100, "venous_asymmetric":25}, + ] + +def test_custom_treatment_slider(slider_object, value, slider_parameter, parameter, x_mouseclick_shift = 0): + ## TODO need to move the implementation of this function to a single spot, update all tests to use that single function + ## since all the function calls are doing the same thing! + """ + Method to set slider handle based on custom values + @param slider_object : (dictionary) object of treatment parameters + @param value : (int)value to be set on slider + @param slider_parameter : (list) consist combination of slider minimum value, slider buffer and width buffer + @param parameter : (str) parameter name + """ + minimum_slider_value = slider_parameter[0] + slider_buffer = slider_parameter[1] + width_buffer = slider_parameter[2] + slider_width = ((value - minimum_slider_value)/slider_buffer) * width_buffer + x_mouseclick_shift + slider_obj = utility.get_object_from_names(slider_object, error_message=parameter+" slider object missing") + if slider_obj is not None: + mouseClick(slider_obj, float(slider_width) , 3, Qt.LeftButton) + utils.waitForGUI(0.5) + test.compare(slider_obj.value, value, str(parameter)+" slider value should set to " +str(value)) + def verify_arterial_and_venous_value_in_main_treatment_screen(accepted, art_low, art_high, ven_low, ven_high): """ Method to verify Arterial low and high @@ -644,57 +677,193 @@ close_the_pop_up() test.endSection() +# TODO need to copy to utility sice this function is also used in other testcases, should consolidate +def verify_log(msg_id=None, msg=None, param=None): + """ + This function verifies the UI log's. + @param msg_id - (string) expected message_id's. + @param msg - (string) message to be displayed on log. + @param param - (list) parameters for msg_id's. + """ + test.startSection("Verification of UI log based on message : " + str(msg)) + param = ','.join(str(param)) if param is not None else param + utils.waitForGUI(2) + ack = False + if not msg_id in msg_defs.ACK_NOT_REQUIRED and msg_id != None: + ack = True + message_extracted = utility.get_current_log_details(message_ack=ack, message_text=msg) + test.log(str(message_extracted)) + if None in message_extracted: + test.fail("Message not found in log file.") + test.endSection() + return + if ack == True: + test.verify((config.ACK_REQ_STATUS in message for message in message_extracted), "ack request is verified") + test.verify((config.ACK_BAK_STATUS in message for message in message_extracted), "ack back is verified") + message_id_hex = builtins.hex(builtins.int(msg_id)) + message_id_str = builtins.str(message_id_hex).upper() + test.verify((message_id_str in message for message in message_extracted), "message ID is verified") + if param is not None: + test.verify((param in message for message in message_extracted), "parameters are verified") + test.endSection() + +def test_pressure_limit_adjust(arterial_window, venous_window, venous_asymmetric): + test.startSection(f"Testing slider value for arterial ({arterial_window}), venous window ({venous_window}), and venous asymmetric ({venous_asymmetric})") + open_pressure_pop_up() + test_custom_treatment_slider(names.o_arterial_slider, arterial_window, config.TREATMENT_PRESSURE_ADJUSTMENT_VALUES["arterial_window"], + config.TREATMENT_PRESSURE_ADJUSTMENT_TITLE) + test_custom_treatment_slider(names.o_venous_slider, venous_window, config.TREATMENT_PRESSURE_ADJUSTMENT_VALUES["venous_window"], + config.TREATMENT_PRESSURE_ADJUSTMENT_TITLE) + test_custom_treatment_slider(names.o_venous_asymmetric_slider, venous_asymmetric, config.TREATMENT_PRESSURE_ADJUSTMENT_VALUES["venous_asymmetric"], + config.TREATMENT_PRESSURE_ADJUSTMENT_TITLE) + click_on_confirm_btn() + test.endSection() +def test_adjust_pressure_limit_slider_and_logs_entry(): + """ + This verifies that when the pressure limits are adjusted, the application + logs the changes + """ + test.startSection("Verify the log entry exists for adjusted pressure limits") + for index in range(0, len(ADJUST_PRESSURE_LIMIT_TEST_VALUES), 1): + target_arterial_window = ADJUST_PRESSURE_LIMIT_TEST_VALUES[index]["arterial_window"] + target_venous_window = ADJUST_PRESSURE_LIMIT_TEST_VALUES[index]["venous_window"] + target_venous_asymmetric=ADJUST_PRESSURE_LIMIT_TEST_VALUES[index]["venous_asymmetric"] + + # set and check the slider values + test_pressure_limit_adjust(arterial_window = target_arterial_window, + venous_window = target_venous_window, + venous_asymmetric = target_venous_asymmetric) + #check log entry + verify_log(msg_id = MsgIds.MSG_ID_UI_PRESSURE_LIMITS_CHANGE_REQUEST.value, msg = "AdjustPressuresLimits", + param = [target_arterial_window, target_venous_window, target_venous_asymmetric]) + + test.endSection() + +def test_adjust_pressure_limit_dialog_closes(): + """ + This test checks to make sure that the dialog closes after the UI receives a response + """ + test.startSection("Testing pressure limit adjust dialog closure when HD accepts values") + open_pressure_pop_up() + + # using first of the test values as the values for this test + target_arterial_window = ADJUST_PRESSURE_LIMIT_TEST_VALUES[0]["arterial_window"] + target_venous_window = ADJUST_PRESSURE_LIMIT_TEST_VALUES[0]["venous_window"] + target_venous_asymmetric=ADJUST_PRESSURE_LIMIT_TEST_VALUES[0]["venous_asymmetric"] + + test_pressure_limit_adjust(arterial_window = target_arterial_window, venous_window = target_venous_window, venous_asymmetric = target_venous_asymmetric) + + # mock a response back from HD to UI to close dialog + hd_simulator.cmd_send_treatment_adjust_pressures_limit_response(accepted = 1, reason = 0, + art_pressure_limit_window = target_arterial_window, + ven_pressure_limit_window = target_venous_window, + ven_pressure_asym_limit_window = target_venous_asymmetric) + utils.waitForGUI(0.5) # wait for GUi update + + + # this is a bit reverse, when a dialog is not visible the "waitForObjectExists" throws an exception + # indicating that the dialog does not exist, so using this as check. + try: + dialog_object = waitForObjectExists(names.o_modalDialog, 200) + test.fail("Pop up is still visible") + except LookupError: + test.passes("Pop up not visible") + + test.endSection() + +def test_pressure_displayed_in_treatment_screen_range_bar(): + TREATMENT_PRESSURE_ADJUSTMENT_HD_TEST_VALUES = [ + {"is_arterial_pressure_in_range":True, "arterial_pressure": 100, "arterial_limit_low":-300, "arterial_limit_high":120, + "is_venous_pressure_in_range" : True, "venous_pressure": 140, "venous_limit_low":-100, "venous_limit_high":250, + "blood_pump_occlusion" : 1, "pressure_limit_state":2, }, + {"is_arterial_pressure_in_range":False, "arterial_pressure": -200, "arterial_limit_low":-150, "arterial_limit_high":120, + "is_venous_pressure_in_range" : True, "venous_pressure": 140, "venous_limit_low":-100, "venous_limit_high":250, + "blood_pump_occlusion" : 1, "pressure_limit_state":2, }, + {"is_arterial_pressure_in_range":True, "arterial_pressure": 110, "arterial_limit_low":100, "arterial_limit_high":120, + "is_venous_pressure_in_range" : False, "venous_pressure": -100, "venous_limit_low":-50, "venous_limit_high":250, + "blood_pump_occlusion" : 1, "pressure_limit_state":2, }, + {"is_arterial_pressure_in_range":False, "arterial_pressure": -130, "arterial_limit_low":-140, "arterial_limit_high":120, + "is_venous_pressure_in_range" : False, "venous_pressure": 200, "venous_limit_low":-100, "venous_limit_high":150, + "blood_pump_occlusion" : 1, "pressure_limit_state":2, }, + ] + for index in range(0, len(TREATMENT_PRESSURE_ADJUSTMENT_HD_TEST_VALUES), 1): + test.startSection("Checking the value of the range bar in pressure on the treatment screen - dataset # {}".format(index)) + + is_arterial_pressure_value_in_range = TREATMENT_PRESSURE_ADJUSTMENT_HD_TEST_VALUES[index]["is_arterial_pressure_in_range"] + is_venous_pressure_value_in_range = TREATMENT_PRESSURE_ADJUSTMENT_HD_TEST_VALUES[index]["is_venous_pressure_in_range"] + target_arterial_pressure = TREATMENT_PRESSURE_ADJUSTMENT_HD_TEST_VALUES[index]["arterial_pressure"] + target_venous_pressure = TREATMENT_PRESSURE_ADJUSTMENT_HD_TEST_VALUES[index]["venous_pressure"] + target_blood_pump_occlusion = TREATMENT_PRESSURE_ADJUSTMENT_HD_TEST_VALUES[index]["blood_pump_occlusion"] + target_pressure_state = TREATMENT_PRESSURE_ADJUSTMENT_HD_TEST_VALUES[index]["pressure_limit_state"] + target_arterial_min_limit = TREATMENT_PRESSURE_ADJUSTMENT_HD_TEST_VALUES[index]["arterial_limit_low"] + target_arterial_max_limit = TREATMENT_PRESSURE_ADJUSTMENT_HD_TEST_VALUES[index]["arterial_limit_high"] + target_venous_min_limit = TREATMENT_PRESSURE_ADJUSTMENT_HD_TEST_VALUES[index]["venous_limit_low"] + target_venous_max_limit = TREATMENT_PRESSURE_ADJUSTMENT_HD_TEST_VALUES[index]["venous_limit_high"] + + # mock the HD data sent to UI + hd_simulator.cmd_set_pressure_occlusion_data(arterial_prs = target_arterial_pressure, venous_prs = target_venous_pressure, + blood_pump_occlusion = target_blood_pump_occlusion, pressure_state= target_pressure_state, + art_min_limit = target_arterial_min_limit, art_max_limit = target_arterial_max_limit, + ven_min_limit = target_venous_min_limit, ven_max_limit = target_venous_max_limit) + + utils.waitForGUI(1) + + # check the range bar's upper and lower bounds + arterial_rangeBar = utility.get_object_from_names(names.o_treatmentHome_arterialRangeBar_RangeBar, error_message="arterial rangeBar object is missing") + if arterial_rangeBar is not None: + test.compare(arterial_rangeBar.lowerBound, target_arterial_min_limit, "Checking lower bound of arterial pressure range bar") + test.compare(arterial_rangeBar.upperBound, target_arterial_max_limit, "Checking upper bound of arterial pressure range bar") + + #check the marker value for the arterial pressure + arterial_rangeBar_marker_text_object = utility.get_object_from_names(names.o_treatmentHome_pressure_arterial_marker_text, error_message="arterial pressure marker label object is missing") + if arterial_rangeBar_marker_text_object is not None: + test.compare(arterial_rangeBar_marker_text_object.text, str(target_arterial_pressure), "Expecting arterial pressure to be displayed") + # base on the data set, check the color of the marker text + if is_arterial_pressure_value_in_range is not True: + test.compare(arterial_rangeBar_marker_text_object.color.name, config.OUT_OF_RANGE_COLOR, "Expecting color to be " + config.OUT_OF_RANGE_COLOR) + else: + test.compare(arterial_rangeBar_marker_text_object.color.name, config.TREATMENT_PRESSURE_IN_RANGE_COLOR, "Expecting color to be " + config.TREATMENT_PRESSURE_IN_RANGE_COLOR) + + # check the range bar's upper and lower bounds + venous_rangeBar = utility.get_object_from_names(names.o_treatmentHome_venousRangeBar_RangeBar, error_message="venous rangeBar object is missing") + if venous_rangeBar is not None: + test.compare(venous_rangeBar.lowerBound, target_venous_min_limit, "Checking lower bound of venous pressure range bar") + test.compare(venous_rangeBar.upperBound, target_venous_max_limit, "Checking upper bound of venous pressure range bar") + + #check the marker value for the venous pressure + venous_rangeBar_marker_text_object = utility.get_object_from_names(names.o_treatmentHome_pressure_venous_marker_text, error_message="venous pressure marker label object is missing") + if venous_rangeBar_marker_text_object is not None: + test.compare(venous_rangeBar_marker_text_object.text, str(target_venous_pressure), "Expecting venous pressure to be displayed") + # base on the data set, check the color of the marker text + if is_venous_pressure_value_in_range is not True: + test.compare(venous_rangeBar_marker_text_object.color.name, config.OUT_OF_RANGE_COLOR, "Expecting color to be " + config.OUT_OF_RANGE_COLOR) + else: + test.compare(venous_rangeBar_marker_text_object.color.name, config.TREATMENT_PRESSURE_IN_RANGE_COLOR, "Expecting color to be " + config.TREATMENT_PRESSURE_IN_RANGE_COLOR) + + utils.waitForGUI(1) + test.endSection() + def main(): utils.tstStart(__file__) - startApplication(AUT_NAME) + application_init.setup_post_log_successful_start() + startApplication(config.AUT_NAME_ONLY +" -q") # need to have acknowledging enabled + hd_simulator.cmd_send_power_on_self_test_version_request() hd_simulator.cmd_set_treatment_states_data(sub_mode=2, uf_state=0, saline_state=0, heparin_state=0, rinseback_state=0, recirculate_state=0, blood_prime_state=0, treatment_end_state=0, treatment_stop_state=0, dialysis_state=0) - verify_the_constants() - - # set_arterial_low_and_high_limits_using_slider() - # set_venous_low_and_high_limits_using_slider() - - set_arterial_pressure_and_verify_the_color() - set_venous_pressure_and_verify_the_color() + # Pressure dialog related + # verify_the_constants() + # test_adjust_pressure_limit_slider_and_logs_entry() + # test_adjust_pressure_limit_dialog_closes() - verify_pressures_on_treatment_and_pop_up_screen(accepted=ACCEPTED, reason=0, - art_low=ART_LOW_VAL_MINUS_120, art_high=ART_HIGH_VAL_160, - ven_low=VENOUS_LOW_VAL_MINUS_310, ven_high=VENOUS_HIGH_VAL_170) - - verify_adjusted_pressures_on_treatment_and_pop_up_screen(accepted=ACCEPTED, reason=0, - art_low=ART_LOW_VAL_MINUS_120, art_high=ART_HIGH_VAL_160, - ven_low=VENOUS_LOW_VAL_MINUS_310, ven_high=VENOUS_HIGH_VAL_170) - -# verify_pressures_on_treatment_and_pop_up_screen(accepted=REJECTED, reason=39, -# art_low=ART_LOW_VAL_MINUS_200, art_high=ART_HIGH_VAL_70, -# ven_low=VENOUS_LOW_VAL_MINUS_200, ven_high=VENOUS_HIGH_VAL_150) -# -# verify_adjusted_pressures_on_treatment_and_pop_up_screen(accepted=REJECTED, reason=39, -# art_low=ART_LOW_VAL_MINUS_200, art_high=ART_HIGH_VAL_70, -# ven_low=VENOUS_LOW_VAL_MINUS_200, ven_high=VENOUS_HIGH_VAL_150) - - verify_pressures_on_treatment_and_pop_up_screen(accepted=ACCEPTED, reason=0, - art_low=ART_LOW_VAL_MINUS_80, art_high=ART_HIGH_VAL_175, - ven_low=VENOUS_LOW_VAL_110, ven_high=VENOUS_HIGH_VAL_250) + # Pressure values shown on the treatment screen + test_pressure_displayed_in_treatment_screen_range_bar() - verify_pressures_on_treatment_and_pop_up_screen(accepted=ACCEPTED, reason=0, - art_low=ART_LOW_VAL_MINUS_80, art_high=ART_HIGH_VAL_175, - ven_low=VENOUS_LOW_VAL_110, ven_high=VENOUS_HIGH_VAL_250) - -# verify_pressures_on_treatment_and_pop_up_screen(accepted=REJECTED, reason=21, -# art_low=ART_LOW_VAL_MINUS_30, art_high=ART_HIGH_VAL_100, -# ven_low=VENOUS_LOW_VAL_MINUS_390, ven_high=VENOUS_HIGH_VAL_300) -# -# verify_pressures_on_treatment_and_pop_up_screen(accepted=REJECTED, reason=21, -# art_low=ART_LOW_VAL_MINUS_30, art_high=ART_HIGH_VAL_100, -# ven_low=VENOUS_LOW_VAL_MINUS_390, ven_high=VENOUS_HIGH_VAL_300) - utils.tstDone()