Exemplo n.º 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)
Exemplo n.º 2
0
def run_command(project='',
                test_query='',
                browsers=None,
                processes=1,
                environments=None,
                interactive=False,
                timestamp=None,
                reports=None,
                report_folder=None,
                report_name=None,
                tags=None):
    execution_runner = ExecutionRunner(browsers, processes, environments,
                                       interactive, timestamp, reports,
                                       report_folder, report_name, tags)
    if project:
        if utils.project_exists(project):
            execution_runner.project = project
            session.settings = settings_manager.get_project_settings(project)
            # add --interactive value to settings to make
            # it available from inside a test
            session.settings['interactive'] = interactive
            if test_query:
                if suite_module.suite_exists(project, test_query):
                    execution_runner.run_suite(test_query)
                elif test_case.test_case_exists(project, test_query):
                    execution_runner.run_test(test_query)
                else:
                    if test_query == '.':
                        test_query = ''
                    path = os.path.join(session.testdir, 'projects', project,
                                        'tests', test_query)
                    if os.path.isdir(path):
                        execution_runner.run_directory(test_query)
                    else:
                        msg = ('golem run: error: the value {} does not match '
                               'an existing test, suite or directory'.format(
                                   test_query))
                        sys.exit(msg)
            else:
                print(messages.RUN_USAGE_MSG)
                test_cases = utils.get_test_cases(project)
                print('Test Cases:')
                utils.display_tree_structure_command_line(
                    test_cases['sub_elements'])
                test_suites = utils.get_suites(project)
                print('\nTest Suites:')
                # TODO print suites in structure
                for suite in test_suites['sub_elements']:
                    print('  ' + suite['name'])
        else:
            msg = ('golem run: error: the project {} does not exist'.format(
                project))
            sys.exit(msg)
    elif interactive:
        interactive_module.interactive(session.settings, browsers)
    else:
        print(messages.RUN_USAGE_MSG)
        print('Projects:')
        for project in utils.get_projects():
            print('  {}'.format(project))
Exemplo n.º 3
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)
Exemplo n.º 4
0
def test_case_code_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 = os.path.join(session.testdir, 'projects', project,
                        'tests', os.sep.join(parents), tc_name + '.py')
    test_case_contents = test_case.get_test_case_code(path)
    _, error = utils.import_module(path)
    external_data = test_data_module.get_external_test_data(project, test_case_name)
    test_data_setting = session.settings['test_data']
    return render_template('test_builder/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, error=error)
Exemplo n.º 5
0
    def run(self, test_execution, args):
        test_execution.thread_amount = args.threads
        test_execution.cli_drivers = args.browsers
        test_execution.cli_environments = args.environments
        test_execution.timestamp = args.timestamp
        test_execution.interactive = args.interactive

        root_path = test_execution.root_path
        if args.project and args.test_or_suite:

            if not args.project in utils.get_projects(root_path):
                msg = [
                    'Error: the project {0} does not exist'.format(
                        args.project), '', 'Usage:', self._parser.usage, '',
                    'Projects:'
                ]
                for proj in utils.get_projects(root_path):
                    msg.append('  {}'.format(proj))
                raise CommandException('\n'.join(msg))
            else:
                test_execution.project = args.project
                _ = settings_manager.get_project_settings(
                    root_path, args.project)
                test_execution.settings = _
                if suite_module.suite_exists(root_path, test_execution.project,
                                             args.test_or_suite):
                    test_execution.suite = args.test_or_suite
                    # execute test suite
                    start_execution.run_test_or_suite(
                        root_path,
                        test_execution.project,
                        suite=test_execution.suite)
                elif test_case.test_case_exists(root_path,
                                                test_execution.project,
                                                args.test_or_suite):
                    test_execution.test = args.test_or_suite
                    # execute test case
                    start_execution.run_test_or_suite(root_path,
                                                      test_execution.project,
                                                      test=test_execution.test)
                else:
                    # test_or_suite does not match any existing suite or test
                    msg = [('Error: the value {0} does not match an existing '
                            'suite or test'.format(args.test_or_suite)), '',
                           'Usage:', self._parser.usage]
                    raise CommandException('\n'.join(msg))

        elif not args.project and not args.test_or_suite and test_execution.interactive:
            from golem.test_runner import interactive
            interactive.interactive(test_execution.settings,
                                    test_execution.cli_drivers)

        elif not args.project:
            msg = ['Usage:', self._parser.usage, '', 'Projects:']
            for proj in utils.get_projects(root_path):
                msg.append('  {}'.format(proj))
            raise CommandException('\n'.join(msg))

        elif args.project and not args.test_or_suite:
            msg = ['Usage: {}'.format(self._parser.usage), '', 'Test Cases:']
            print('\n'.join(msg))
            test_cases = utils.get_test_cases(root_path, args.project)
            utils.display_tree_structure_command_line(
                test_cases['sub_elements'])
            print('\nTest Suites:')
            test_suites = utils.get_suites(root_path, args.project)
            for suite in test_suites['sub_elements']:
                print('  ' + suite['name'])
            raise CommandException()
        else:
            # test_or_suite does not match any existing suite or test
            raise CommandException(
                'Error: the value {0} does not match an existing '
                'suite or test'.format(args.test_or_suite))
Exemplo n.º 6
0
def run_command(project='', test_or_suite='', browsers=[], threads=1,
                environments=[], interactive=False, timestamp=None):
    test_execution.thread_amount = threads
    test_execution.cli_drivers = browsers
    test_execution.cli_environments = environments
    test_execution.timestamp = timestamp
    test_execution.interactive = interactive
    root_path = test_execution.root_path
    if project:
        existing_projects = utils.get_projects(root_path)
        if project in existing_projects:
            test_execution.project = project
            settings = settings_manager.get_project_settings(root_path, project)
            test_execution.settings = settings
            # settings are accessible from a test
            # test_execution is not accessible from a test
            # the test needs to know if interactive is true
            test_execution.settings['interactive'] = interactive
            if test_or_suite:
                if suite_module.suite_exists(root_path, test_execution.project,
                                         test_or_suite):
                    test_execution.suite = test_or_suite
                    # execute test suite
                    start_execution.run_test_or_suite(root_path,
                                                      test_execution.project,
                                                      suite=test_execution.suite)
                elif test_case.test_case_exists(root_path, test_execution.project,
                                                test_or_suite):
                    test_execution.test = test_or_suite
                    # execute test case
                    start_execution.run_test_or_suite(root_path,
                                                      test_execution.project,
                                                      test=test_execution.test)
                else:
                    # TODO run directory
                    # test_or_suite does not match any existing suite or test
                    msg = ('golem run: error: the value {0} does not match an existing '
                           'test or suite'.format(test_or_suite))
                    sys.exit(msg)
            else:
                print(messages.RUN_USAGE_MSG)
                test_cases = utils.get_test_cases(root_path, project)
                print('Test Cases:')
                utils.display_tree_structure_command_line(test_cases['sub_elements'])
                test_suites = utils.get_suites(root_path, project)
                print('\nTest Suites:')
                # TODO print suites in structure
                for suite in test_suites['sub_elements']:
                    print('  ' + suite['name'])
        else:
            msg = ('golem run: error: the project {0} does not exist'.format(project))
            sys.exit(msg)

    elif test_execution.interactive:
        interactive_module.interactive(test_execution.settings,
                                       test_execution.cli_drivers)
    else:
        print(messages.RUN_USAGE_MSG)
        print('Projects:')
        for proj in utils.get_projects(root_path):
            print('  {}'.format(proj))