Пример #1
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))
Пример #2
0
def projects_view(project):
    if not user.has_permissions_to_project(g.user.id, project, root_path, 'gui'):
        return render_template('not_permission.html')
    elif not utils.project_exists(root_path, project):
        abort(404, 'This page does not exists.')
    else:
        projects = utils.get_projects(root_path)
        return render_template('index.html', projects=projects)
Пример #3
0
 def test_golem_createproject(self, testdir_session, test_utils):
     os.chdir(testdir_session.path)
     project = 'testproject1'
     cmd = 'golem createproject {}'.format(project)
     result = test_utils.run_command(cmd)
     assert result == 'Project {} created'.format(project)
     projects = utils.get_projects(testdir_session.path)
     assert project in projects
Пример #4
0
 def run(self, test_execution, args):
     if args.project not in utils.get_projects(test_execution.root_path):
         raise CommandException(
             'Error: a project with that name does not exist')
     errors = suite_module.new_suite(test_execution.root_path, args.project,
                                     args.suite)
     if errors:
         raise CommandException('\n'.join(errors))
Пример #5
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 proj in utils.get_projects():
         expected += '\n  {}'.format(proj)
     assert result == expected
Пример #6
0
def createsuite_command(project, suite_name):
    if project not in utils.get_projects(test_execution.root_path):
        msg = ('golem createsuite: error: a project with name {} '
               'does not exist'.format(project))
        sys.exit(msg)
    errors = suite_module.new_suite(test_execution.root_path, project, [],
                                    suite_name)
    if errors:
        sys.exit('golem createsuite: error: {}'.format(' '.join(errors)))
Пример #7
0
def createproject_command(project):
    root_path = test_execution.root_path

    if project in utils.get_projects(root_path):
        msg = ('golem createproject: error: a project with name \'{}\' already exists'
               .format(project))
        sys.exit(msg)
    else:
        utils.create_new_project(root_path, project)
Пример #8
0
 def run(self, test_execution, args):
     if args.project not in utils.get_projects(
             test_execution.root_path):
         raise CommandException(
             'Error: a project with that name does not exist')
     errors = suite_module.new_suite(test_execution.root_path,
                                     args.project, args.suite)
     if errors:
         raise CommandException('\n'.join(errors))
Пример #9
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
    """
    if current_user.is_admin or '*' in current_user.gui_permissions:
        projects = utils.get_projects(test_execution.root_path)
    else:
        projects = current_user.gui_permissions
    return render_template('index.html', projects=projects)
Пример #10
0
 def test_golem_run_no_args(self, project_session, test_utils):
     path = project_session['testdir']
     project = project_session['name']
     os.chdir(path)
     result = test_utils.run_command('golem run')
     expected = messages.RUN_USAGE_MSG
     expected += '\nProjects:'
     for proj in utils.get_projects(path):
         expected += '\n  {}'.format(proj)
     assert result == expected
Пример #11
0
def report_dashboard():
    """If user is admin or has '*' in report permissions they will
    have access to every project report. Otherwise limit the project
    list to report_permissions"""
    if current_user.is_admin or '*' in current_user.report_permissions:
        projects = utils.get_projects(test_execution.root_path)
    else:
        projects = current_user.report_permissions
    return render_template('report/report_dashboard.html', projects=projects,
                           project=None, suite='')
Пример #12
0
    def run(self, test_execution, args):
        root_path = test_execution.root_path

        if args.project in utils.get_projects(root_path):
            msg = 'Error: a project with the name \'{}\' already exists'.format(
                args.project)
            raise CommandException(msg)
        # elif args.project == 'demo':
        #     utils.create_demo_project(root_path)
        else:
            utils.create_new_project(root_path, args.project)
Пример #13
0
    def run(self, test_execution, args):
        root_path = test_execution.root_path

        if args.project in utils.get_projects(root_path):
            msg = 'Error: a project with the name \'{}\' already exists'.format(
                args.project
            )
            raise CommandException(msg)
        # elif args.project == 'demo':
        #     utils.create_demo_project(root_path)
        else:
            utils.create_new_project(root_path, args.project)
Пример #14
0
    def run(self, test_execution, args):
        root_path = test_execution.root_path

        if args.project not in utils.get_projects(root_path):
            raise CommandException(
                'Error: a project with that name does not exist')
        dot_path = args.test.split('.')
        test_name = dot_path.pop()
        errors = test_case.new_test_case(root_path, args.project, dot_path,
                                         test_name)
        if errors:
            raise CommandException('\n'.join(errors))
Пример #15
0
def createtest_command(project, test):
    root_path = test_execution.root_path

    if project not in utils.get_projects(root_path):
        msg = ('golem createtest: error: a project with name {} '
               'does not exist'.format(project))
        sys.exit(msg)
    dot_path = test.split('.')
    test_name = dot_path.pop()
    errors = test_case.new_test_case(root_path, project, dot_path, test_name)
    if errors:
        sys.exit('golem createtest: error: {}'.format(' '.join(errors)))
Пример #16
0
    def run(self, test_execution, args):
        root_path = test_execution.root_path

        if args.project not in utils.get_projects(root_path):
            raise CommandException(
                'Error: a project with that name does not exist'
            )
        dot_path = args.test.split('.')
        test_name = dot_path.pop()
        errors = test_case.new_test_case(root_path, args.project,
                                         dot_path, test_name)
        if errors:
            raise CommandException('\n'.join(errors))
Пример #17
0
def new_project():
    if request.method == 'POST':
        project_name = request.form['projectName']
        project_name = project_name.strip().replace(' ', '_')
        errors = []
        if len(project_name) < 3:
            errors.append('Project name is too short')
        elif len(project_name) > 50:
            errors.append('Project name is too long')
        elif len(project_name) != len(project_name.strip()):
            errors.append('Leading and trailing spaces are not allowed')
        elif project_name in utils.get_projects(root_path):
            errors.append('A project with that name already exists')
        else:
            utils.create_new_project(root_path, project_name)
        return json.dumps({'errors': errors, 'project_name': project_name})
Пример #18
0
def new_project():
    if request.method == 'POST':
        project_name = request.form['projectName']

        project_name = project_name.strip().replace(' ', '_')

        errors = []
        if len(project_name) < 3:
            errors.append('Project name is too short')
        elif len(project_name) > 50:
            errors.append('Project name is too long')
        elif len(project_name) != len(project_name.strip()):
            errors.append('Leading and trailing spaces are not allowed')
        elif project_name in utils.get_projects(root_path):
            errors.append('A project with that name already exists')
        else:
            utils.create_new_project(root_path, project_name)
        return json.dumps({'errors': errors, 'project_name': project_name})
Пример #19
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))
Пример #20
0
def index():
    projects = utils.get_projects(root_path)
    return render_template('index.html', projects=projects)
Пример #21
0
 def test_get_projects(self, testdir_function):
     testdir = testdir_function.path
     utils.create_new_project(testdir, 'project1')
     utils.create_new_project(testdir, 'project2')
     projects = utils.get_projects(testdir)
     assert projects.sort() == ['project1', 'project2'].sort()
Пример #22
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
        # test_execution.minimize = args.minimize

        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
                test_execution.settings = settings_manager.get_project_settings(
                    args.project, test_execution.settings)
                if utils.test_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 utils.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))
Пример #23
0
 def test_get_projects(self, testdir_function):
     testdir_function.activate()
     utils.create_new_project('project1')
     utils.create_new_project('project2')
     projects = utils.get_projects()
     assert projects.sort() == ['project1', 'project2'].sort()
Пример #24
0
 def test_get_projects_no_project(self, testdir_function):
     projects = utils.get_projects(testdir_function.path)
     assert projects == []
Пример #25
0
 def test_get_projects_no_project(self, testdir_function):
     testdir_function.activate()
     projects = utils.get_projects()
     assert projects == []
Пример #26
0
 def test_get_projects(self, project_fixture, testdir_fixture):
     projects = utils.get_projects(testdir_fixture['path'])
     assert project_fixture['name'] in projects
Пример #27
0
 def test_get_projects(self, project_fixture):
     projects = utils.get_projects(project_fixture['test_directory_fixture']['full_path'])
     assert project_fixture['project_name'] in projects
Пример #28
0
 def test_get_projects(self, project_fixture, testdir_fixture):
     projects = utils.get_projects(testdir_fixture['path'])
     assert project_fixture['name'] in projects
Пример #29
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
                test_execution.settings = settings_manager.get_project_settings(root_path, args.project)
                if utils.test_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 utils.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))
Пример #30
0
def index():
    projects = utils.get_projects(root_path)
    return render_template('index.html', projects=projects)
Пример #31
0
def execute_from_command_line(root_path):

    parser = cli.get_golem_parser()
    args = parser.parse_args()

    # set test_execution values
    test_execution.root_path = root_path
    test_execution.settings = utils.get_global_settings()

    import golem.core
    golem.core.temp = test_execution.settings

    # main action == gui
    if args.main_action == 'gui':
        gui_start.run_gui()
        sys.exit()

    # main action == run
    if args.main_action == 'run':
        if not args.project:
            print 'Usage:', parser.usage, '\n\n', 'Project List:'
            for proj in utils.get_projects(root_path):
                print '> {}'.format(proj)
            sys.exit()
        # check if selected project does not exist
        elif not args.project in utils.get_projects(root_path):
            sys.exit('Error: the project {0} does not exist'
                     .format(test_execution.project))
        else:
            test_execution.project = args.project

            # check if test_or_suite value is present
            if not args.test_or_suite:
                print 'Usage:', parser.usage
                print '\nTest Cases:'
                test_cases = utils.get_test_cases(root_path,
                                                  test_execution.project)
                utils.display_tree_structure_command_line(test_cases)
                print '\nTest Suites:'
                test_suites = utils.get_suites(root_path,
                                               test_execution.project)
                utils.display_tree_structure_command_line(test_suites)
                sys.exit()

            # check if test_or_suite value matches an existing test suite
            elif utils.test_suite_exists(root_path,
                                       test_execution.project,
                                       args.test_or_suite):
                test_execution.suite = args.test_or_suite
                # execute test suite
                test_runner.run_suite(root_path,
                                      test_execution.project,
                                      test_execution.suite)

            # check if test_or_suite value matches an existing test case
            elif utils.test_case_exists(root_path,
                                        test_execution.project,
                                        args.test_or_suite):
                test_execution.test = args.test_or_suite
                # execute test case
                test_runner.run_single_test_case(root_path,
                                                 test_execution.project,
                                                 test_execution.test)
            
            else:
                # test_or_suite does not match any existing suite or test
                sys.exit('Error: the value {0} does not match an existing '
                         'suite or test'
                         .format(args.test_or_suite))

    # main action == startproject
    if args.main_action == 'startproject':
        sys.exit('To be defined')

    # main action == createuser
    if args.main_action == 'createuser':
        sys.exit('To be defined')