def run_suite(self, suite):
        """Run a suite.
        `suite` can be a path to a Python file or an import path.
        Both relative to the suites folder.
        Example:
            test = 'folder/suite.py'
            test = 'folder.suite'
        """
        # TODO
        if suite.endswith('.py'):
            filename, _ = os.path.splitext(suite)
            suite = '.'.join(os.path.normpath(filename).split(os.sep))

        suite_obj = suite_module.Suite(self.project, suite)

        self.tests = suite_obj.tests
        if len(self.tests) == 0:
            print('No tests found for suite {}'.format(suite))

        self.suite.processes = suite_obj.processes
        self.suite.browsers = suite_obj.browsers
        self.suite.envs = suite_obj.environments
        self.suite.tags = suite_obj.tags
        module = suite_obj.get_module()
        self.suite.before = getattr(module, 'before', None)
        self.suite.after = getattr(module, 'after', None)
        self.suite_name = suite
        self.is_suite = True
        self._prepare()
Ejemplo n.º 2
0
def suite_code_view(project, suite):
    suite_obj = suite_module.Suite(project, suite)
    if not suite_obj.exists:
        abort(404, f'The suite {suite} does not exist')
    _, error = utils.import_module(suite_obj.path)
    return render_template('suite_code.html', project=project, suite_name=suite,
                           code=suite_obj.code, error=error)
Ejemplo n.º 3
0
def suite_code_save():
    project = request.json['project']
    suite_name = request.json['suiteName']
    content = request.json['content']
    _verify_permissions(Permissions.STANDARD, project)
    suite_module.edit_suite_code(project, suite_name, content)
    path = suite_module.Suite(project, suite_name).path
    _, error = utils.import_module(path)
    return jsonify({'error': error})
Ejemplo n.º 4
0
 def create_suite(project, name, content=None, tests=None,
                  processes=1, browsers=None, environments=None, tags=None):
     browsers = browsers or []
     environments = environments or []
     tags = tags or []
     if content is None:
         suite.create_suite(project, name)
         suite.edit_suite(project, name, tests, processes, browsers, environments, tags)
     else:
         with open(suite.Suite(project, name).path, 'w+') as f:
             f.write(content)
Ejemplo n.º 5
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, cli_log_level=None):
    execution_runner = ExecutionRunner(browsers, processes, environments, interactive,
                                       timestamp, reports, report_folder, report_name, tags)
    if project:
        if test_directory.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
            # override cli_log_level setting if provided by the CLI
            if cli_log_level:
                session.settings['cli_log_level'] = cli_log_level.upper()
            if test_query:
                norm_query = utils.normalize_query(test_query)
                if suite_module.Suite(project, norm_query).exists:
                    execution_runner.run_suite(norm_query)
                elif test.Test(project, norm_query).exists:
                    execution_runner.run_test(norm_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)
                tests = Project(project).test_tree
                print('Tests:')
                utils.display_tree_structure_command_line(tests['sub_elements'])
                suites = Project(project).suite_tree
                print('\nTest Suites:')
                # TODO print suites in structure
                for suite in 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 test_directory.get_projects():
            print('  {}'.format(project))
Ejemplo n.º 6
0
def suite_view(project, suite):
    suite_obj = suite_module.Suite(project, suite)
    if not suite_obj.exists:
        abort(404, f'The suite {suite} does not exist')
    all_tests = Project(project).test_tree
    default_browser = session.settings['default_browser']
    return render_template('suite.html', project=project,
                           all_test_cases=all_tests['sub_elements'],
                           selected_tests=suite_obj.tests, suite=suite,
                           processes=suite_obj.processes, browsers=suite_obj.browsers,
                           default_browser=default_browser,
                           environments=suite_obj.environments, tags=suite_obj.tags)
Ejemplo n.º 7
0
 def create_suite(project,
                  name=None,
                  content=None,
                  tests=None,
                  processes=1,
                  browsers=None,
                  environments=None,
                  tags=None):
     if name is None:
         name = TestUtils.random_string()
     browsers = browsers or []
     environments = environments or []
     tags = tags or []
     if content is None:
         suite.create_suite(project, name)
         suite.edit_suite(project, name, tests, processes, browsers,
                          environments, tags)
     else:
         with open(suite.Suite(project, name).path, 'w+') as f:
             f.write(content)
     return name
Ejemplo n.º 8
0
def project_suite_exists():
    project = request.args['project']
    suite_name = request.args['suite']
    _verify_permissions(Permissions.READ_ONLY, project)
    return jsonify(suite_module.Suite(project, suite_name).exists)