Ejemplo n.º 1
0
def test_case_view(project, test_case_name):
    # check if user has permissions for this project
    if not user.has_permissions_to_project(g.user.id, project, root_path,
                                           'gui'):
        return render_template('not_permission.html')

    # check if the file is locked
    # is_locked_by = lock.is_file_locked(root_path, project, test_case_name)
    # print(is_locked_by, g.user.username)
    # if is_locked_by and is_locked_by != g.user.username:
    #     abort(404, 'This file is locked by someone else.')
    # else:
    tc_name, parents = utils.separate_file_from_parents(test_case_name)
    path = test_case.generate_test_case_path(root_path, project,
                                             test_case_name)
    error = utils.validate_python_file_syntax(path)
    if error:
        return render_template('test_builder/test_case_syntax_error.html',
                               project=project,
                               full_test_case_name=test_case_name)
    else:
        test_case_contents = test_case.get_test_case_content(
            root_path, project, test_case_name)
        test_data = test_data_module.get_test_data(root_path, project,
                                                   test_case_name)
        return render_template('test_builder/test_case.html',
                               project=project,
                               test_case_contents=test_case_contents,
                               test_case_name=tc_name,
                               full_test_case_name=test_case_name,
                               test_data=test_data)
Ejemplo n.º 2
0
    def test_get_test_case_content(self, testdir_fixture,
                                   random_project_fixture):

        test_name = 'some_test_case'
        root_path = random_project_fixture['testdir_fixture']['path']
        project = random_project_fixture['name']
        path = os.path.join(root_path, 'projects', project, 'tests',
                            test_name + '.py')
        with open(path, 'w') as ff:
            ff.write(SAMPLE_TEST_CONTENT)
        test_content = test_case.get_test_case_content(root_path, project,
                                                       test_name)
        assert test_content['description'] == 'some description'
        assert test_content['pages'] == ['page1', 'page2']
        assert test_content['steps']['setup'] == [{
            'method_name': 'page1.func1',
            'parameters': []
        }]
        assert test_content['steps']['test'] == [{
            'method_name': 'page2.func2',
            'parameters': ["'a'", "'b'"]
        }, {
            'method_name': 'click',
            'parameters': ['page2.elem1']
        }]
        assert test_content['steps']['teardown'] == []
Ejemplo n.º 3
0
def test_case_view(project, test_case_name):
    # check if the file is locked
    # is_locked_by = lock.is_file_locked(root_path, project, test_case_name)
    # print(is_locked_by, g.user.username)
    # if is_locked_by and is_locked_by != g.user.username:
    #     abort(404, 'This file is locked by someone else.')
    # else:
    test_exists = test_case.test_case_exists(test_execution.root_path, project,
                                             test_case_name)
    if not test_exists:
        abort(404, 'The test {} does not exist'.format(test_case_name))
    tc_name, parents = utils.separate_file_from_parents(test_case_name)
    path = test_case.generate_test_case_path(root_path, project, test_case_name)
    _, error = utils.import_module(path)
    if error:
        url = url_for('test_case_code_view', project=project, test_case_name=test_case_name)
        content = ('<h4>There are errors in the test</h4>'
                   '<p>There are errors and the test cannot be displayed, '
                   'open the test code editor to solve them.</p>'
                   '<a class="btn btn-default" href="{}">Open Test Code</a>'
                   .format(url))
        return render_template('common_element_error.html', project=project,
                               item_name=test_case_name, content=content)
    else:
        test_case_contents = test_case.get_test_case_content(root_path, project,
                                                             test_case_name)
        test_data = test_data_module.get_test_data(root_path, project, test_case_name,
                                                   repr_strings=True)
        return render_template('test_builder/test_case.html', project=project,
                               test_case_contents=test_case_contents,
                               test_case_name=tc_name,
                               full_test_case_name=test_case_name,
                               test_data=test_data)
Ejemplo n.º 4
0
def test_case_view(project, test_case_name):
    # check if user has permissions for this project
    if not user.has_permissions_to_project(g.user.id, project, root_path, 'gui'):
        return render_template('not_permission.html')

    # check if the file is locked
    # is_locked_by = lock.is_file_locked(root_path, project, test_case_name)
    # print(is_locked_by, g.user.username)
    # if is_locked_by and is_locked_by != g.user.username:
    #     abort(404, 'This file is locked by someone else.')
    # else:
    tc_name, parents = utils.separate_file_from_parents(test_case_name)
    path = test_case.generate_test_case_path(root_path, project, test_case_name)
    error = utils.validate_python_file_syntax(path)
    if error:
        return render_template('test_builder/test_case_syntax_error.html',
                               project=project,
                               full_test_case_name=test_case_name)
    else:
        test_case_contents = test_case.get_test_case_content(root_path, project,
                                                             test_case_name)
        test_data = test_data_module.get_test_data(root_path, project, test_case_name)
        return render_template('test_builder/test_case.html', project=project,
                               test_case_contents=test_case_contents,
                               test_case_name=tc_name,
                               full_test_case_name=test_case_name,
                               test_data=test_data)
Ejemplo n.º 5
0
def test_case_view(project, test_case_name):
    test_exists = test_case.test_case_exists(project, test_case_name)
    if not test_exists:
        abort(404, 'The test {} does not exist'.format(test_case_name))
    tc_name, parents = utils.separate_file_from_parents(test_case_name)
    path = test_case.test_file_path(project, test_case_name)
    _, error = utils.import_module(path)
    if error:
        url = url_for('test_case_code_view', project=project, test_case_name=test_case_name)
        content = ('<h4>There are errors in the test</h4>'
                   '<p>There are errors and the test cannot be displayed, '
                   'open the test code editor to solve them.</p>'
                   '<a class="btn btn-default" href="{}">Open Test Code</a>'
                   .format(url))
        return render_template('common_element_error.html', project=project,
                               item_name=test_case_name, content=content)
    else:
        test_case_contents = test_case.get_test_case_content(project, test_case_name)
        test_data = test_data_module.get_test_data(project, test_case_name,
                                                   repr_strings=True)
        return render_template('test_builder/test_case.html', project=project,
                               test_case_contents=test_case_contents,
                               test_case_name=tc_name,
                               full_test_case_name=test_case_name,
                               test_data=test_data)
Ejemplo n.º 6
0
 def test_get_test_case_content_empty_test(self, project_function):
     _, project = project_function.activate()
     test_name = 'some_test_case'
     test_case.new_test_case(project, [], test_name)
     test_content = test_case.get_test_case_content(project, test_name)
     assert test_content['description'] == ''
     assert test_content['pages'] == []
     assert test_content['steps']['setup'] == []
     assert test_content['steps']['test'] == []
     assert test_content['steps']['teardown'] == []
Ejemplo n.º 7
0
def test_case_code_view(project, test_case_name):
    # check if user has permissions for this project
    if not user.has_permissions_to_project(g.user.id, project, root_path, 'gui'):
        return render_template('not_permission.html')

    tc_name, parents = utils.separate_file_from_parents(test_case_name)
    test_case_contents = test_case.get_test_case_content(project, test_case_name)
    test_data = utils.get_test_data_dict_list(root_path, project, test_case_name)

    return render_template('test_case_code.html', project=project, 
                           test_case_contents=test_case_contents, test_case_name=tc_name,
                           full_test_case_name=test_case_name, test_data=test_data)
Ejemplo n.º 8
0
 def test_get_test_case_content(self, project_class):
     test_name = 'some_test_case'
     path = os.path.join(project_class.path, 'tests', test_name + '.py')
     with open(path, 'w') as ff:
         ff.write(SAMPLE_TEST_CONTENT)
     test_content = test_case.get_test_case_content(project_class.testdir, project_class.name, test_name)
     assert test_content['description'] == 'some description'
     assert test_content['pages'] == ['page1', 'page2']
     assert test_content['steps']['setup'] == [{'method_name': 'page1.func1', 'parameters': []}]
     expected_test_steps = [{'method_name': 'page2.func2', 'parameters': ["'a'", "'b'"]},
                            {'method_name': 'click', 'parameters': ['page2.elem1']}]
     assert test_content['steps']['test'] == expected_test_steps
     assert test_content['steps']['teardown'] == []
Ejemplo n.º 9
0
def test_case_view(project, test_case_name):
    # check if user has permissions for this project
    if not user.has_permissions_to_project(g.user.id, project, root_path, 'gui'):
        return render_template('not_permission.html')

    # check if the file is locked
    # is_locked_by = lock.is_file_locked(root_path, project, test_case_name)
    # print(is_locked_by, g.user.username)
    # if is_locked_by and is_locked_by != g.user.username:
    #     abort(404, 'This file is locked by someone else.')
    # else:
    tc_name, parents = utils.separate_file_from_parents(test_case_name)
    test_case_contents = test_case.get_test_case_content(project, test_case_name)
    test_data = utils.get_test_data_dict_list(root_path, project, test_case_name)

    return render_template('test_case.html', project=project,
                           test_case_contents=test_case_contents, test_case_name=tc_name,
                           full_test_case_name=test_case_name, test_data=test_data)
Ejemplo n.º 10
0
def test_case_code_view(project, test_case_name):
    # check if user has permissions for this project
    if not user.has_permissions_to_project(g.user.id, project, root_path,
                                           'gui'):
        return render_template('not_permission.html')

    tc_name, parents = utils.separate_file_from_parents(test_case_name)
    test_case_contents = test_case.get_test_case_content(
        root_path, project, test_case_name)
    external_data = test_data_module.get_external_test_data(
        root_path, project, test_case_name)
    test_data_setting = test_execution.settings['test_data']
    return render_template('test_case_code.html',
                           project=project,
                           test_case_contents=test_case_contents,
                           test_case_name=tc_name,
                           full_test_case_name=test_case_name,
                           test_data=external_data,
                           test_data_setting=test_data_setting)