Esempio n. 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 = os.path.join(session.testdir, 'projects', project, 'reports',
                        'single_tests', 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_parser.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 = report_parser.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) as log_file:
                sets[set_name]['log'] = log_file.readlines()
    result['sets'] = sets
    return jsonify(result)
Esempio n. 2
0
def report_test(project, suite, execution, test_case, test_set):
    if not user.has_permissions_to_project(g.user.id, project, root_path, 'report'):
        return render_template('not_permission.html')
    test_case_data = report_parser.get_test_case_data(root_path, project, test_case,
                                                      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_case, test_set=test_set,
                           test_case_data=test_case_data)
Esempio n. 3
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 = report_parser.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
Esempio n. 4
0
def check_test_case_run_result():
    if request.method == 'POST':
        project = request.form['project']
        test_case_name = request.form['testCaseName']
        timestamp = request.form['timestamp']

        path = os.path.join(root_path, 'projects', project, 'reports',
                            'single_tests', test_case_name, timestamp)
        sets = []
        result = {
            'reports': [],
            'logs': [],
            'complete': False
        }

        if os.path.isdir(path):
            for elem in os.listdir(path):
                if os.path.isdir(os.path.join(path, elem)):
                    sets.append(elem) 

        # is execution finished?
        result['complete'] = report_parser.is_execution_finished(path, sets)

        for data_set in sets:
            report_path = os.path.join(path, data_set, 'report.json')
            if os.path.exists(report_path):
                test_case_data = report_parser.get_test_case_data(root_path,
                                                                  project,
                                                                  test_case_name,
                                                                  execution=timestamp,
                                                                  test_set=data_set,
                                                                  is_single=True)
                result['reports'].append(test_case_data)

            log_path = os.path.join(path, data_set, 'execution_info.log')
            if os.path.exists(log_path):
                with open(log_path) as log_file:
                    log = log_file.readlines()
                    result['logs'].append(log)

        return json.dumps(result)
Esempio n. 5
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'
    """
    from golem import gui
    app = gui.app
    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 = report_parser.get_date_time_from_timestamp(execution)
    css = {}
    js = {}
    boostrap_path = os.path.join(app.static_folder, 'css', 'bootstrap', 'bootstrap.min.css')
    datatables_js = os.path.join(app.static_folder, 'js', 'external', 'datatable', 'datatables.min.js')
    css['bootstrap'] = open(boostrap_path).read()
    css['main'] = open(os.path.join(app.static_folder, 'css', 'main.css')).read()
    css['report'] = open(os.path.join(app.static_folder, 'css', 'report.css')).read()
    js['jquery'] = open(os.path.join(app.static_folder, 'js', 'external', 'jquery.min.js')).read()
    js['datatables'] = open(datatables_js).read()
    js['bootstrap'] = open(os.path.join(app.static_folder, 'js', 'external', 'bootstrap.min.js')).read()
    js['main'] = open(os.path.join(app.static_folder, 'js', 'main.js')).read()
    js['report_execution'] = open(os.path.join(app.static_folder, 'js', 'report_execution.js')).read()
    execution_data = report_parser.get_execution_data(project=project, suite=suite, execution=execution)
    detail_test_data = {}
    for test in execution_data['tests']:
        test_detail = report_parser.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') 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