# -*- 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_post # @author (last) Papiya Mandal # @date (last) 19-04-2022 # import names from builtins import int as pyInt from configuration import config from configuration import application_init as application_init from dialin.ui import utils from dialin.ui.dg_simulator import DGSimulator from dialin.ui.hd_simulator import HDSimulator application_context = None hd_simulator = HDSimulator() dg_simulator = DGSimulator() MSGS_AND_CONDITIONS = { 9: [True, False], 5: [True, False], 2: [True, False], 4: [True, False], 8: [True, False], 1: [False, False], 3: [True, False], 13: [True, False], 15: [True, False], 11: [True, False], 18: [True, False], 12: [True, False], 20: [True, False], 10: [True, False], 14: [True, False], 6: [False, False], 17: [True, False], 7: [True, False], 21: [True, True], 16: [False, True], 19: [True, True], 22: [True, True], } def post_a_message_and_verify_progress_and_completion(msgs_and_conditions): """ Method to post message and verify the progress and completion @param msgs_and_conditions - (list) list of messages and conditions @return - None """ for msg, conditions in msgs_and_conditions.items(): final_msg = conditions[0] final_msg_posted = conditions[1] hd_simulator.cmd_send_hd_post(msg, final_msg, final_msg_posted) dg_simulator.cmd_send_dg_post(msg, final_msg, final_msg_posted) utils.waitForGUI(1) verify_the_progress(value=msg, final_msg_posted=final_msg_posted) verify_final_message_posted(final_msg=final_msg, final_msg_posted=final_msg_posted) def verify_the_progress(value, final_msg_posted) -> None: """ Method to verify the progress @param value - (int) single message @final_msg_posted - (bool) True/False @return - None """ progress = pyInt(get_progress()) if final_msg_posted is True: test.xcompare(value, progress, "Final value {} should not reflect on the progress bar".format(value)) elif final_msg_posted is False: test.compare(value, progress, "{} should reflect on progress bar".format(value)) def get_progress(): """ Method to obtain progress @return: Progress value """ progress_bar = waitForObjectExists(names.o_progress_bar) return progress_bar.value def verify_ui_version(): """ Method to verify ui version of application. """ version = hd_simulator.get_ui_version() test.xcompare(version, "current_version", "To do current version") def verify_final_message_posted(final_msg=None, final_msg_posted=None) -> None: """ method to verify the indication of final message posted @param final_msg - (bool) final message(True/False) @param final_msg_posted - (bool) if this is the final post message(True/False) @return - None """ test.startSection("Verifying the status") if final_msg == True and final_msg_posted == True: if object.exists(names.o_done_indicator): done_indicator = waitForObject(names.o_done_indicator) test.compare(done_indicator.enabled, True, "Done, Final value passed") elif (final_msg == False and final_msg_posted == True) : if object.exists(names.o_fail_indicator): fail_indicator = waitForObject(names.o_fail_indicator) test.compare(fail_indicator.enabled, True, "Failed, Final value not passed") elif (final_msg == True and final_msg_posted == False) or (final_msg == False and final_msg_posted == False): if object.exists(names.o_busy_indicator): busy_indicator = waitForObject(names.o_busy_indicator) test.compare(busy_indicator.enabled, True, "Waiting for a value") test.endSection() def test_sucessfully_load_everything_path(): test.startSection("Testing successfully loading everything - happy path") is_create_mock_file = application_init.generate_mock_app_post_log_file(canBus_passed = True, eth0_passed = True, sdCard_passed = True, rtc_passed = True, wifi_passed = True, bt_passed = True, touch_passed = True, shasum_passed = True, cloudSync_passed= True, build_version = "123.123.123", build_id = "20230628230011") if is_create_mock_file: application_context = startApplication(config.AUT_NAME) hd_simulator.cmd_send_power_on_self_test_version_request() post_a_message_and_verify_progress_and_completion(MSGS_AND_CONDITIONS) check_log() verify_ui_version() application_context.detach() #close the application else: test.fail("Unable to create the mock app post file") test.endSection() def check_log(): #TODO need to add body #get_message_from_log(file_name, message_text, check_ack_bak = False): utils.waitForGUI(10) def test_individual_fail_components_path(): listOfStates = [True,True,True,True,True,True,True,True,True] for index in range(0, len(listOfStates)): test.startSection(f"Failing single post element index : {index}") listOfStates[index] = False # set the next target fail is_create_mock_file = application_init.generate_mock_app_post_log_file(canBus_passed = listOfStates[0], eth0_passed = listOfStates[1], sdCard_passed = listOfStates[2], rtc_passed = listOfStates[3], wifi_passed = listOfStates[4], bt_passed = listOfStates[5], touch_passed = listOfStates[6], shasum_passed = listOfStates[7], cloudSync_passed= listOfStates[8], build_version = "123.123.123", build_id = "20230628230011") if is_create_mock_file: application_context = startApplication(config.AUT_NAME) hd_simulator.cmd_send_power_on_self_test_version_request() check_log() else: test.fail("Unable to create the mock app post file") application_init.remove_mock_app_post_log_file() listOfStates[index] = True # reset state test.endSection() application_context.detach() # close the application def test_missing_post_log_file(): #delete the post.log file if it exists test.startSection("Remove post.log file - missing log case") application_init.remove_mock_app_post_log_file() application_context = startApplication(config.AUT_NAME) hd_simulator.cmd_send_power_on_self_test_version_request() check_log() application_context.detach() #close the application test.endSection() def test_different_build_version_string(): test.log("Note: Cannot test invalid major and minor of the version since it's unsigned int >=0") build_versions_under_test = [{ "build_version" :"0.0.41", "isValid" :True}, { "build_version" :"1.4.21", "isValid":False}, { "build_version" :"123.123.41", "isValid":True}, { "build_version" :"2.1.1", "isValid":False}, { "build_version" :"10.10.100", "isValid":True}, { "build_version" :"1.4.25", "isValid":False}] for index in range(len(build_versions_under_test)): version_testing = build_versions_under_test[index]["build_version"] expected_valid_state = build_versions_under_test[index]["isValid"] test.startSection(f"Test version {version_testing} expect : {expected_valid_state}") is_create_mock_file = application_init.generate_mock_app_post_log_file(canBus_passed = True, eth0_passed = True, sdCard_passed = True, rtc_passed = True, wifi_passed = True, bt_passed = True, touch_passed = True, shasum_passed = True, cloudSync_passed= True, build_version = version_testing, build_id = "20230628230011") if is_create_mock_file: application_context = startApplication(config.AUT_NAME) hd_simulator.cmd_send_power_on_self_test_version_request() #TODO need to check for the alarm triggered: 0300,UI,AlarmTriggered,HD UI POST OS version compatibility failure. #TODO need to use expected_valid_state to determine the message expected in the logs check_log() application_context.detach() #close the application else: test.fail("Unable to create the mock app post file") test.endSection() def main(): utils.tstStart(__file__) test_sucessfully_load_everything_path() utils.tstDone() test_individual_fail_components_path() test_different_build_version_string() test_missing_post_log_file()