Пример #1
0
def report_test_status():
    project = request.args['project']
    test_name = request.args['test']
    timestamp = request.args['timestamp']
    _verify_permissions(Permissions.REPORTS_ONLY, project)
    path = exec_report.single_test_execution_path(project, test_name,
                                                  timestamp)
    result = {'sets': {}, 'is_finished': False}
    sets = {}
    if os.path.isdir(path):
        for elem in os.listdir(path):
            if os.path.isdir(os.path.join(path, elem)):
                sets[elem] = {'log': [], 'report': None}
    result['is_finished'] = report.is_execution_finished(path, sets)
    for set_name in sets:
        report_path = os.path.join(path, set_name, 'report.json')
        if os.path.exists(report_path):
            test_data = test_report.get_test_case_data(project,
                                                       test_name,
                                                       execution=timestamp,
                                                       test_set=set_name,
                                                       is_single=True)
            sets[set_name]['report'] = test_data
        log_path = os.path.join(path, set_name, 'execution_info.log')
        if os.path.exists(log_path):
            with open(log_path, encoding='utf-8') as log_file:
                sets[set_name]['log'] = log_file.readlines()
    result['sets'] = sets
    return jsonify(result)
Пример #2
0
def report_test_json(project, suite, execution, test, test_set):
    test_data = test_report.get_test_case_data(project,
                                               test,
                                               suite=suite,
                                               execution=execution,
                                               test_set=test_set,
                                               is_single=False)
    return jsonify(test_data)
Пример #3
0
def report_test(project, suite, execution, test, test_set):
    test_data = test_report.get_test_case_data(project,
                                               test,
                                               suite=suite,
                                               execution=execution,
                                               test_set=test_set,
                                               is_single=False)
    return render_template('report/report_test.html',
                           project=project,
                           suite=suite,
                           execution=execution,
                           test_case=test,
                           test_set=test_set,
                           test_case_data=test_data)
Пример #4
0
    def test_get_test_case_data(self, project_class, test_utils):
        _, project = project_class.activate()
        exc = test_utils.execute_random_suite(project)
        test_name = exc['exec_data']['tests'][0]['name']
        test_set = exc['exec_data']['tests'][0]['test_set']

        test_data = get_test_case_data(project, test_name, exc['suite_name'],
                                       exc['timestamp'], test_set)

        assert test_data['name'] == exc['tests'][0]
        assert isinstance(test_data['debug_log'], list) and len(
            test_data['debug_log'])
        assert isinstance(test_data['info_log'], list) and len(
            test_data['info_log'])
        assert test_data['has_finished'] is True
Пример #5
0
def report_test_set():
    project = request.args['project']
    suite = request.args['suite']
    execution = request.args['execution']
    test_full_name = request.args['testName']
    test_set = request.args['testSet']
    _verify_permissions(Permissions.REPORTS_ONLY, project)
    test_detail = test_report.get_test_case_data(project, test_full_name, suite=suite,
                                                 execution=execution, test_set=test_set,
                                                 is_single=False, encode_screenshots=True)
    response = jsonify(test_detail)
    if test_detail['has_finished']:
        response.cache_control.max_age = 604800
        response.cache_control.public = True
    return response
Пример #6
0
def generate_html_report(project, suite, execution, report_directory=None,
                         report_name=None, no_images=False):
    """Generate static HTML report.
    Report is generated in <report_directory>/<report_name>
    By default it's generated in <testdir>/projects/<project>/reports/<suite>/<timestamp>
    Default name is 'report.html' and 'report-no-images.html'
    """
    if not report_directory:
        report_directory = os.path.join(session.testdir, 'projects', project,
                                        'reports', suite, execution)
    if not report_name:
        if no_images:
            report_name = 'report-no-images'
        else:
            report_name = 'report'

    formatted_date = utils.get_date_time_from_timestamp(execution)
    app = gui.create_app()
    static_folder = app.static_folder
    # css paths
    css_folder = os.path.join(static_folder, 'css')
    boostrap_css = os.path.join(css_folder, 'bootstrap', 'bootstrap.min.css')
    main_css = os.path.join(css_folder, 'main.css')
    report_css = os.path.join(css_folder, 'report.css')
    # js paths
    js_folder = os.path.join(static_folder, 'js')
    main_js = os.path.join(js_folder, 'main.js')
    jquery_js = os.path.join(js_folder, 'external', 'jquery.min.js')
    datatables_js = os.path.join(js_folder, 'external', 'datatable', 'datatables.min.js')
    bootstrap_js = os.path.join(js_folder, 'external', 'bootstrap.min.js')
    report_execution_js = os.path.join(js_folder, 'report_execution.js')

    css = {
        'bootstrap': open(boostrap_css, encoding='utf-8').read(),
        'main': open(main_css, encoding='utf-8').read(),
        'report': open(report_css, encoding='utf-8').read()
    }
    js = {
        'jquery': open(jquery_js, encoding='utf-8').read(),
        'datatables': open(datatables_js, encoding='utf-8').read(),
        'bootstrap': open(bootstrap_js, encoding='utf-8').read(),
        'main': open(main_js, encoding='utf-8').read(),
        'report_execution': open(report_execution_js).read()
    }

    execution_data = exec_report.get_execution_data(project=project, suite=suite, execution=execution)
    detail_test_data = {}
    for test in execution_data['tests']:
        test_detail = test_report.get_test_case_data(project, test['full_name'], suite=suite,
                                                     execution=execution, test_set=test['test_set'],
                                                     is_single=False, encode_screenshots=True,
                                                     no_screenshots=no_images)
        detail_test_data[test['test_set']] = test_detail
    with app.app_context():
        html_string = render_template('report/report_execution_static.html', project=project,
                                      suite=suite, execution=execution, execution_data=execution_data,
                                      detail_test_data=detail_test_data, formatted_date=formatted_date,
                                      css=css, js=js, static=True)
    _, file_extension = os.path.splitext(report_name)
    if not file_extension:
        report_name = '{}.html'.format(report_name)
    destination = os.path.join(report_directory, report_name)

    if not os.path.exists(os.path.dirname(destination)):
        os.makedirs(os.path.dirname(destination), exist_ok=True)

    try:
        with open(destination, 'w', encoding='utf-8') as f:
            f.write(html_string)
    except IOError as e:
        if e.errno == errno.EACCES:
            print('ERROR: cannot write to {}, PermissionError (Errno 13)'
                  .format(destination))
        else:
            print('ERROR: There was an error writing to {}'.format(destination))

    return html_string