示例#1
0
def run_test_logic(c,
                   failed_playbooks,
                   integrations,
                   playbook_id,
                   succeed_playbooks,
                   test_message,
                   test_options,
                   slack,
                   circle_ci,
                   build_number,
                   server_url,
                   build_name,
                   is_mock_run=False):
    status, inc_id = test_integration(c, integrations, playbook_id,
                                      test_options, is_mock_run)
    if status == PB_Status.COMPLETED:
        print_color('PASS: {} succeed'.format(test_message), LOG_COLORS.GREEN)
        succeed_playbooks.append(playbook_id)

    elif status == PB_Status.NOT_SUPPORTED_VERSION:
        print('PASS: {} skipped - not supported version'.format(test_message))
        succeed_playbooks.append(playbook_id)

    else:
        print_error('Failed: {} failed'.format(test_message))
        playbook_id_with_mock = playbook_id
        if not is_mock_run:
            playbook_id_with_mock += " (Mock Disabled)"
        failed_playbooks.append(playbook_id_with_mock)
        notify_failed_test(slack, circle_ci, playbook_id, build_number, inc_id,
                           server_url, build_name)

    succeed = status == PB_Status.COMPLETED or status == PB_Status.NOT_SUPPORTED_VERSION
    return succeed
示例#2
0
def run_test_logic(tests_settings, c, failed_playbooks, integrations, playbook_id, succeed_playbooks,
                   test_message, test_options, slack, circle_ci, build_number, server_url, build_name,
                   prints_manager, thread_index=0, is_mock_run=False):
    status, inc_id = test_integration(c, server_url, integrations, playbook_id, prints_manager, test_options,
                                      is_mock_run, thread_index=thread_index)
    # c.api_client.pool.close()
    if status == PB_Status.COMPLETED:
        prints_manager.add_print_job('PASS: {} succeed'.format(test_message), print_color, thread_index,
                                     message_color=LOG_COLORS.GREEN)
        succeed_playbooks.append(playbook_id)

    elif status == PB_Status.NOT_SUPPORTED_VERSION:
        not_supported_version_message = 'PASS: {} skipped - not supported version'.format(test_message)
        prints_manager.add_print_job(not_supported_version_message, print, thread_index)
        succeed_playbooks.append(playbook_id)

    else:
        error_message = 'Failed: {} failed'.format(test_message)
        prints_manager.add_print_job(error_message, print_error, thread_index)
        playbook_id_with_mock = playbook_id
        if not is_mock_run:
            playbook_id_with_mock += " (Mock Disabled)"
        failed_playbooks.append(playbook_id_with_mock)
        if not tests_settings.is_local_run:
            notify_failed_test(slack, circle_ci, playbook_id, build_number, inc_id, server_url, build_name)

    succeed = status == PB_Status.COMPLETED or status == PB_Status.NOT_SUPPORTED_VERSION
    return succeed
示例#3
0
def mock_run(tests_settings, c, proxy, failed_playbooks, integrations, playbook_id, succeed_playbooks,
             test_message, test_options, slack, circle_ci, build_number, server_url, build_name, start_message,
             prints_manager, thread_index=0):
    rerecord = False

    if proxy.has_mock_file(playbook_id):
        start_mock_message = '{} (Mock: Playback)'.format(start_message)
        prints_manager.add_print_job(start_mock_message, print, thread_index)
        proxy.start(playbook_id, thread_index=thread_index, prints_manager=prints_manager)
        # run test
        status, inc_id = test_integration(c, server_url, integrations, playbook_id, prints_manager, test_options,
                                          is_mock_run=True, thread_index=thread_index)
        # use results
        proxy.stop()
        if status == PB_Status.COMPLETED:
            succeed_message = 'PASS: {} succeed'.format(test_message)
            prints_manager.add_print_job(succeed_message, print_color, thread_index, LOG_COLORS.GREEN)
            succeed_playbooks.append(playbook_id)
            end_mock_message = '------ Test {} end ------\n'.format(test_message)
            prints_manager.add_print_job(end_mock_message, print, thread_index)

            return

        elif status == PB_Status.NOT_SUPPORTED_VERSION:
            not_supported_version_message = 'PASS: {} skipped - not supported version'.format(test_message)
            prints_manager.add_print_job(not_supported_version_message, print, thread_index)
            succeed_playbooks.append(playbook_id)
            end_mock_message = '------ Test {} end ------\n'.format(test_message)
            prints_manager.add_print_job(end_mock_message, print, thread_index)

            return
        elif status == PB_Status.FAILED_DOCKER_TEST:
            error_message = 'Failed: {} failed'.format(test_message)
            prints_manager.add_print_job(error_message, print_error, thread_index)
            failed_playbooks.append(playbook_id)
            end_mock_message = '------ Test {} end ------\n'.format(test_message)
            prints_manager.add_print_job(end_mock_message, print, thread_index)

            return
        else:
            mock_failed_message = "Test failed with mock, recording new mock file. (Mock: Recording)"
            prints_manager.add_print_job(mock_failed_message, print, thread_index)
            rerecord = True
    else:
        mock_recording_message = start_message + ' (Mock: Recording)'
        prints_manager.add_print_job(mock_recording_message, print, thread_index)

    # Mock recording - no mock file or playback failure.
    succeed = run_and_record(tests_settings, c, proxy, failed_playbooks, integrations, playbook_id, succeed_playbooks,
                             test_message, test_options, slack, circle_ci, build_number, server_url, build_name,
                             prints_manager, thread_index=thread_index)

    if rerecord and succeed:
        proxy.rerecorded_tests.append(playbook_id)
    test_end_message = '------ Test {} end ------\n'.format(test_message)
    prints_manager.add_print_job(test_end_message, print, thread_index)
示例#4
0
def mock_run(c, proxy, failed_playbooks, integrations, playbook_id,
             succeed_playbooks, test_message, test_options, slack, circle_ci,
             build_number, server_url, build_name, start_message):
    rerecord = False

    if proxy.has_mock_file(playbook_id):
        print('{} (Mock: Playback)'.format(start_message))
        proxy.start(playbook_id)
        # run test
        status, inc_id = test_integration(c,
                                          integrations,
                                          playbook_id,
                                          test_options,
                                          is_mock_run=True)
        # use results
        proxy.stop()
        if status == PB_Status.COMPLETED:
            print_color('PASS: {} succeed'.format(test_message),
                        LOG_COLORS.GREEN)
            succeed_playbooks.append(playbook_id)
            print('------ Test {} end ------\n'.format(test_message))

            return

        elif status == PB_Status.NOT_SUPPORTED_VERSION:
            print('PASS: {} skipped - not supported version'.format(
                test_message))
            succeed_playbooks.append(playbook_id)
            print('------ Test {} end ------\n'.format(test_message))

            return

        else:
            print(
                "Test failed with mock, recording new mock file. (Mock: Recording)"
            )
            rerecord = True
    else:
        print(start_message + ' (Mock: Recording)')

    # Mock recording - no mock file or playback failure.
    succeed = run_and_record(c, proxy, failed_playbooks, integrations,
                             playbook_id, succeed_playbooks, test_message,
                             test_options, slack, circle_ci, build_number,
                             server_url, build_name)

    if rerecord and succeed:
        proxy.rerecorded_tests.append(playbook_id)
    print('------ Test {} end ------\n'.format(test_message))