示例#1
0
 def test_golem_createproject(self, testdir_session, test_utils):
     testdir_session.activate()
     os.chdir(testdir_session.path)
     project = test_utils.random_string()
     result = test_utils.run_command(f'golem createproject {project}')
     assert result == f'Project {project} created'
     projects = test_directory.get_projects()
     assert project in projects
示例#2
0
 def test_golem_run_no_args(self, project_session, test_utils):
     testdir, _ = project_session.activate()
     os.chdir(testdir)
     result = test_utils.run_command('golem run')
     expected = messages.RUN_USAGE_MSG
     expected += '\nProjects:'
     for project in test_directory.get_projects():
         expected += '\n  {}'.format(project)
     assert result == expected
示例#3
0
 def test_golem_createproject(self, testdir_session, test_utils):
     testdir_session.activate()
     os.chdir(testdir_session.path)
     project = test_utils.random_string()
     cmd = 'golem createproject {}'.format(project)
     result = test_utils.run_command(cmd)
     assert result == 'Project {} created'.format(project)
     projects = test_directory.get_projects()
     assert project in projects
示例#4
0
def index():
    """If user is admin or has '*' in report permissions they will
    have access to every project. Otherwise limit the project
    list to gui_permissions
    """
    projects = test_directory.get_projects()
    if not current_user.is_superuser:
        user_projects = current_user.project_list
        projects = [p for p in user_projects if p in projects]
    return render_template('index.html', projects=projects)
示例#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))
示例#6
0
def get_last_execution_timestamps(projects=None,
                                  execution=None,
                                  limit=None,
                                  last_days=None):
    """Get the last n execution timestamps from all the executions of
    a list of projects.

    If projects is not provided, all projects will be selected.
    If execution is provided, projects should be a list of one.

    Timestamps are in descending order.
    """
    start_timestamp = None
    if last_days is not None and last_days != 0:
        start_datetime = datetime.today() - timedelta(days=last_days)
        start_timestamp = utils.get_timestamp(start_datetime)

    last_timestamps = {}
    # if no projects provided, select every project
    if not projects:
        projects = test_directory.get_projects()
    for project in projects:
        last_timestamps[project] = {}
        report_path = Project(project).report_directory_path
        # if execution is not provided, select all executions
        if execution and os.path.isdir(os.path.join(report_path, execution)):
            executions = [execution]
        else:
            executions = next(os.walk(report_path))[1]
        for e in executions:
            exec_path = os.path.join(report_path, e)
            timestamps = next(os.walk(exec_path))[1]
            timestamps = sorted(timestamps, reverse=True)
            if limit is not None:
                limit = int(limit)
                timestamps = timestamps[:limit]
            if start_timestamp is not None:
                timestamps = [t for t in timestamps if t >= start_timestamp]
            if len(timestamps):
                last_timestamps[project][e] = timestamps
            else:
                last_timestamps[project][e] = []

    return last_timestamps
示例#7
0
def get_last_executions(projects=None, suite=None, limit=5):
    """Get the last n executions from all the suites of
    a list of projects.

    If projects is not provided, all projects will be selected.
    If suite is provided, projects should be a list of one.
    Returns a list of executions (timestamps strings)
    in descending order for each suite with executions
    for each selected project.
    """
    last_executions = {}
    # if no projects provided, select every project
    if not projects:
        projects = test_directory.get_projects()
    for project in projects:
        last_executions[project] = {}
        report_path = Project(project).report_directory_path
        executed_suites = []
        # if suite is not provided, select all suites with executions
        if suite:
            if os.path.isdir(os.path.join(report_path, suite)):
                executed_suites = [suite]
        else:
            executed_suites = next(os.walk(report_path))[1]
            executed_suites = [
                x for x in executed_suites if x != 'single_tests'
            ]
        for s in executed_suites:
            suite_path = os.path.join(report_path, s)
            suite_executions = next(os.walk(suite_path))[1]
            suite_executions = sorted(suite_executions)
            limit = int(limit)
            suite_executions = suite_executions[-limit:]
            if len(suite_executions):
                last_executions[project][s] = suite_executions
            else:
                last_executions[project][s] = []
    return last_executions
示例#8
0
 def test_get_projects_no_project(self, testdir_function):
     testdir_function.activate()
     projects = test_directory.get_projects()
     assert projects == []
示例#9
0
 def test_get_projects(self, testdir_function):
     testdir_function.activate()
     create_project('project1')
     create_project('project2')
     projects = test_directory.get_projects()
     assert projects.sort() == ['project1', 'project2'].sort()
示例#10
0
def projects():
    return jsonify(test_directory.get_projects())
示例#11
0
 def project_list(self):
     projects = list(self.projects.keys())
     if self.is_superuser or '*' in projects:
         projects = test_directory.get_projects()
     return projects
示例#12
0
 def get():
     if ProjectsCache._projects is None:
         ProjectsCache._projects = test_directory.get_projects()
     return ProjectsCache._projects