Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
0
def save_test_case_code():
    if request.method == 'POST':
        project = request.json['project']
        test_case_name = request.json['testCaseName']
        table_test_data = request.json['testData']
        content = request.json['content']
        test_case.save_test_case_code(root_path, project, test_case_name,
                                      content, table_test_data)
        path = test_case.generate_test_case_path(root_path, project, test_case_name)
        _, error = utils.import_module(path)
        return json.dumps({'error': error})
Beispiel #5
0
def save_test_case_code():
    if request.method == 'POST':
        projectname = request.json['project']
        test_case_name = request.json['testCaseName']
        table_test_data = request.json['testData']
        content = request.json['content'] 

        # test_data.save_test_data(root_path, projectname, test_case_name, test_data)
        test_case.save_test_case_code(root_path, projectname, test_case_name,
                                      content, table_test_data)
        path = test_case.generate_test_case_path(root_path, projectname, test_case_name)
        error = utils.validate_python_file_syntax(path)

        return json.dumps({'error': error})
Beispiel #6
0
def save_test_case_code():
    if request.method == 'POST':
        projectname = request.json['project']
        test_case_name = request.json['testCaseName']
        table_test_data = request.json['testData']
        content = request.json['content']

        # test_data.save_test_data(root_path, projectname, test_case_name, test_data)
        test_case.save_test_case_code(root_path, projectname, test_case_name,
                                      content, table_test_data)
        path = test_case.generate_test_case_path(root_path, projectname, test_case_name)
        error = utils.validate_python_file_syntax(path)

        return json.dumps({'error': error})
Beispiel #7
0
 def import_modules(self):
     if '/' in self.test_name:
         self.test_name = self.test_name.replace('/', '.')
     path = test_case.generate_test_case_path(self.workspace, self.project,
                                              self.test_name)
     test_module, error = utils.import_module(path)
     if error:
         actions._add_error(message=error.splitlines()[-1],
                            description=error)
         self.result['result'] = ResultsEnum.CODE_ERROR
     else:
         self.test_module = test_module
         # import logger into the test module
         setattr(self.test_module, 'logger', execution.logger)
         # import actions into the test module
         for action in dir(actions):
             setattr(self.test_module, action, getattr(actions, action))
         # store test description
         if hasattr(self.test_module, 'description'):
             execution.description = self.test_module.description
         try:
             # import each page into the test_module
             if hasattr(self.test_module, 'pages'):
                 base_path = os.path.join(self.workspace, 'projects',
                                          self.project, 'pages')
                 for page in self.test_module.pages:
                     self.test_module = import_page_into_test_module(
                         base_path, self.test_module, page.split('.'))
         except Exception as e:
             message = '{}: {}'.format(e.__class__.__name__, e)
             trcbk = traceback.format_exc()
             actions._add_error(message=message, description=trcbk)
             self.result['result'] = ResultsEnum.CODE_ERROR
     if self.result['result'] == ResultsEnum.CODE_ERROR:
         self.finalize()
     else:
         self.run_setup()