Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PyCon 8.80 KB | None | 0 0
  1. def _finalize_test_case_from_verdict(test_group: str, verdicts: data_parser.TestCaseFinalization, test_case: data_storage.TestCase, info_for_txn: data_storage.TransactionInformation = None):
  2.     """
  3.     Attempts to finalize a test case that either completed OK or terminated abnormally somewhere
  4.  
  5.     Input  : data required for finalizing, see types above
  6.  
  7.     Return  : None
  8.  
  9.     Date       Who       ISsue & Comment
  10.     xxxx.xx.xx ArtursA   (REBVATS-732) Function created
  11.     xxxx.xx.xx ArtursA   (REBVATS-1096) Moved data related to reports generation to a separate method.
  12.     xxxx.xx.xx ArtursA   (REBVATS-1096) Moved logic that handles BTT verdict here
  13.     2016.11.08 IvarsG    (REBVATS-1363) Added more detailed info if verdict is OK but VATS still has fails.
  14.     2016.11.10 ArtursA1  (REBVATS-1346) Added test_group field
  15.     2016.11.09 IvarsG    (REBVATS-1353) Added "non_automatable" verdict outcome handling.
  16.     2017.01.11 IgorsB    (REBVATS-1544) Added verdicts and test_case None type validation
  17.     """
  18.     was_failed = True
  19.     verdict_header = "BTT Verdict: "
  20.     result_for_zephyr = None
  21.      
  22.    
  23.     if verdicts is None:
  24.         user_message_centered("TEST CASE FAILED")
  25.         user_message_centered("NO VERDICT FROM BTT - Check data that has been sent to BTT")
  26.         ats_addons.set_failure_reason("No verdict received from BTT")
  27.         result_for_zephyr = 2
  28.     elif verdicts.outcome == "non_automatable":
  29.         user_message_centered("TEST CASE NON AUTOMATABLE")
  30.         verdict_header = ats_addons.BLOCKED_STATUS_TEXT + ": "
  31.         was_failed = False
  32.         result_for_zephyr = 2
  33.     elif not info_for_txn:
  34.         user_message_centered("TEST CASE FAILED")
  35.         user_message_centered("TRANSACTION INFO NOT SUPPLIED. CONSULT BTT LOGS")
  36.         result_for_zephyr = 2
  37.     elif verdicts.outcome not in ["passed", "inconclusive"]:
  38.         user_message_centered("TEST CASE FAILED")
  39.         user_message_centered("DATA REQUESTED WAS:" + str(info_for_txn.requested_data))
  40.         result_for_zephyr = 2
  41.     else:
  42.         user_message_centered("TEST CASE PASSED")
  43.         if ats._ats__check_fails > 0:
  44.             ats_addons.set_failure_reason(". VATS check fail count before reset: " + str(ats._ats__check_fails))
  45.             ats._ats__check_fails = 0
  46.         was_failed = False
  47.         result_for_zephyr = 1
  48.        
  49.     if verdicts is not None and test_case is not None:
  50.         _make_reports_entry(verdict_header + verdicts.outcome, test_case.get_readable_name(), test_case.get_readable_test_plan(), test_group, was_failed)
  51.     else:
  52.         LOG("Got NoneType object: verdicts = "+str(verdicts)+" | test_case = "+str(test_case))
  53.  
  54.     return result_for_zephyr
  55.  
  56. def _run_test_case(test_group: str, test_case: data_storage.TestCase, brand):
  57.     """
  58.     Method that runs an individual test case from start to finish and leaves the automation server in a
  59.     state where it can perform new test cases
  60.  
  61.     Input   : test_case - test case to be run
  62.             : brand - card brand to which this test case belongs
  63.             : test_group - theoretical "test group" that this test belongs to.
  64.  
  65.     Return  : verdicts
  66.  
  67.     Date       Who       Issue & Comment
  68.     xxxx.xx.xx ArtursA   (REBVATS-732) Function created
  69.     xxxx.xx.xx ArtursA   (REBVATS-899) Split param handling logic away from InfoForFosVats constructor, added call to new method
  70.     xxxx.xx.xx ArtursA   (REBVATS-1096) Removed handling in case no response.
  71.     2016.11.08 IvarsG    (REBVATS-1354) Moved global flag clearance before this function call.
  72.     2016.11.09 IvarsG    (REBVATS-1353) Added test case finalization handling in response on test case initialization.
  73.     """
  74.     get_user().back_to_main_menu()
  75.     verdicts = None
  76.     info_for_txn = None
  77.  
  78.     response, verdicts = btt_protocol_base.initiate_test_case(brand, *test_case.get_data_for_initiate_transaction())
  79.     if verdicts is None:
  80.         while response.get("message_type") == "Initiate Transaction":
  81.             info_for_txn = data_storage.TransactionInformation()
  82.             info_for_txn.parse_transaction_information(response)
  83.             info_for_txn.test_case_name = test_case.get_readable_name()
  84.             info_for_txn.brand = brand
  85.             if data_storage.TransactionInformationBackup.transaction_count > 0:
  86.                 data_storage.TransactionInformationBackup.get_amounts(info_for_txn)
  87.             test_case.assign_transaction_info(info_for_txn)
  88.             verdicts, response = _do_transaction(info_for_txn, test_case)
  89.     data_storage.TransactionInformationBackup.transaction_count = 0
  90.     result_for_zephyr =_finalize_test_case_from_verdict(test_group, verdicts, test_case, info_for_txn)
  91.    
  92.                    
  93.     LOG("Sending status of test to Zefir...")
  94.     test_case_issue_id = zefir.is_test_case_on_list(test_case)
  95.     zefir.execute_issue_in_zephyr(test_case_issue_id, result_for_zephyr)
  96.     print ("Status for given testcase sent to Zefir")
  97.    
  98.     return verdicts
  99.  
  100. def run_test_cases(brand, interface,  list_of_test_cases):
  101.     """
  102.     Main runner function for BTT Automation
  103.  
  104.     Input   : brand - card brand for which the test case will be initiated
  105.             :type list_of_test_cases: list[data_storage.TestCase]
  106.  
  107.     Return  : N/A
  108.  
  109.     Date       Who         Issue & Comment
  110.     xxxx.xx.xx ArtursA     (REBVATS-732) Function created
  111.     xxxx.xx.xx ArtursA     (REBVATS-1096) Added specific handling for Invalid BTT message exceptions.
  112.     xxxx.xx.xx ArtursA     (REBVATS-1096) Set outcome status when making report entry.
  113.     xxxx.xx.xx ArtursA     (REBVATS-1113) Add MCCLIST to files to activate, MCC will be used to route txn to host sim.
  114.     xxxx.xx.xx ArtursA     (REBVATS-992) Added log splitting logic.
  115.     2016.08.25 ArtursA     (REBVATS-1156) Moved logfile splitting to on_test_cycle_end
  116.     2016.09.13 IgorsB      (REBVATS-935) Added CFG_RUN_BTT_AUTOMATION setting and removing
  117.     2016.09.21 IgorsB      (REBVATS-1181) Added test case searching in blocked list, added blocked test case adding into report with corresponding type and reason
  118.     2016.11.08 IvarsG      (REBVATS-1354) Moved global flag clearance here to make sure they are always cleared.
  119.     2016.11.10 ArtursA1    (REBVATS-1346) Added setting of test_group
  120.     2016.12.09 IgorsB      (REBVATS-1198) Added blocked test cases list getting
  121.     2016.12.12 ArtursA1    (REBVATS-1487) Initialize values for limit enums
  122.     2016.12.21 ArtursA1    (REBVATS-1420) Reworked how "blocked" test cases work
  123.     2017.01.16 IvarsG      (REBVATS-1521) Added current interface as log file prefix.
  124.     2017.01.23 IvarsG      (REBVATS-1521) Added interface covertion to upper to match common style.
  125.     """
  126.     get_helpers().prepare_terminal_for_btt_tests()
  127.  
  128.  
  129.     # We have no intention of using the Card Simulator server here, update config to reflect that
  130.     original_cssp_status = get_config_value(CFG_USE_COLLIS)
  131.     set_config_value(CFG_USE_COLLIS, CFG_OFF)
  132.     set_config_value(CFG_USE_BTT_AUTOMATION, CFG_ON)
  133.  
  134.     total_test_cases = len(list_of_test_cases)
  135.     current_test_case = 0
  136.  
  137.     test_group = utils.format_brand_and_interface(brand, interface)
  138.  
  139.     global_modules.transaction_limits.initialize_all(brand)
  140.  
  141.     for test_case in list_of_test_cases:
  142.         ats._ats__check_passes = 0
  143.         ats._ats__check_fails = 0
  144.         ats_addons.clear_all_failure_reasons()
  145.         ats_addons.script_start_time = perf_counter()
  146.  
  147.         current_test_case += 1
  148.         test_case_name = test_case.get_readable_name()
  149.         log_helpers.log_test_case_start_to_log_system(utils.get_log_file_prefix(interface).upper(), test_case_name, current_test_case, total_test_cases)
  150.  
  151.         test_case_blocked, blocked_reason = btt_automation.blocked_test_list.is_test_case_blocked(test_case, brand)
  152.  
  153.         if not test_case_blocked:
  154.             try:
  155.                 _run_test_case(test_group, test_case, brand)
  156.             except btt_protocol_base.BttInvalidMessageError as error:
  157.                 LOG(str(error) + ". Detailed: " + error.get_detailed_error_text())
  158.                 _make_reports_entry(str(error), test_case_name, test_case.get_readable_test_plan(), test_group, True, )
  159.                 btt_protocol_base.terminate_testing()
  160.             except Exception as e:
  161.                 _make_reports_entry("Terminated abnormally! [{0}]".format(e), test_case_name, test_case.get_readable_test_plan(), test_group, True)
  162.                 btt_protocol_base.terminate_testing()
  163.                 LOG(get_exception_string())
  164.         else:
  165.             user_message_centered("TEST CASE BLOCKED - " + blocked_reason)
  166.             _make_reports_entry(ats_addons.BLOCKED_STATUS_TEXT + " - " + blocked_reason, test_case_name, test_case.get_readable_test_plan(), test_group,  False)
  167.  
  168.         log_helpers.log_test_case_end_to_log_system(utils.get_log_file_prefix(interface).upper(), test_case_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement