Esempio n. 1
0
def create_new_project(workspace, project):
    file_manager.create_directory(path_list=[workspace, 'projects', project],
                                  add_init=True)
    # TODO, remove, don't create data folder for new projects
    # create_directory(path_list=[workspace, 'projects', project, 'data'], add_init=False)
    _ = [workspace, 'projects', project, 'pages']
    file_manager.create_directory(path_list=_, add_init=True)
    _ = [workspace, 'projects', project, 'reports']
    file_manager.create_directory(path_list=_, add_init=False)
    _ = [workspace, 'projects', project, 'tests']
    file_manager.create_directory(path_list=_, add_init=True)
    _ = [workspace, 'projects', project, 'suites']
    file_manager.create_directory(path_list=_, add_init=True)
    extend_path = os.path.join(workspace, 'projects', project, 'extend.py')
    open(extend_path, 'a').close()

    settings_path = os.path.join(workspace, 'projects', project,
                                 'settings.json')
    with open(settings_path, 'a') as settings_file:
        settings_file.write(settings_manager.REDUCED_SETTINGS_FILE_CONTENT)

    environments_path = os.path.join(workspace, 'projects', project,
                                     'environments.json')
    with open(environments_path, 'a') as environments_file:
        environments_file.write('{}')
    print('Project {} created'.format(project))
Esempio n. 2
0
def create_new_project(workspace, project):
    file_manager.create_directory(path_list=[workspace, 'projects', project],
                                  add_init=True)
    # TODO, remove, don't create data folder for new projects
    # create_directory(path_list=[workspace, 'projects', project, 'data'], add_init=False)
    path_list = [workspace, 'projects', project, 'pages']
    file_manager.create_directory(path_list=path_list, add_init=True)
    path_list = [workspace, 'projects', project, 'reports']
    file_manager.create_directory(path_list=path_list, add_init=False)
    path_list = [workspace, 'projects', project, 'tests']
    file_manager.create_directory(path_list=path_list, add_init=True)
    path_list = [workspace, 'projects', project, 'suites']
    file_manager.create_directory(path_list=path_list, add_init=True)
    extend_path = os.path.join(workspace, 'projects', project, 'extend.py')
    open(extend_path, 'a').close()

    settings_manager.create_project_settings_file(workspace, project)

    for project_base_file in ('environments.json', 'secrets.json'):
        base_file_path = os.path.join(workspace, 'projects', project,
                                      project_base_file)
        with open(base_file_path, 'a') as base_file:
            base_file.write('{}')

    print('Project {} created'.format(project))
Esempio n. 3
0
def duplicate_test(project, name, new_name):
    errors = []
    old_path = Test(project, name).path
    new_path = Test(project, new_name).path
    if name == new_name:
        errors.append('New test name cannot be the same as the original')
    elif not os.path.isfile(old_path):
        errors.append('Test {} does not exist'.format(name))
    elif os.path.isfile(new_path):
        errors.append('A test with that name already exists')
    else:
        errors = validate_project_element_name(new_name)
    if not errors:
        try:
            Project(project).create_packages_for_element(new_name, Project.file_types.TEST)
            file_manager.create_directory(path=os.path.dirname(new_path), add_init=True)
            shutil.copyfile(old_path, new_path)
            # duplicate data file if present
            old_data_path = os.path.splitext(old_path)[0] + '.csv'
            new_data_path = os.path.splitext(new_path)[0] + '.csv'
            if os.path.isfile(old_data_path):
                shutil.copyfile(old_data_path, new_data_path)
        except:
            errors.append('There was an error creating the new test')
    return errors
Esempio n. 4
0
 def _project_with_tags(self, project_class, test_utils):
     """A fixture of a project with tests that contain tags"""
     testdir, project = project_class.activate()
     tests = SimpleNamespace()
     base_content = 'def test(data):\n     pass\n'
     tests.test_alfa_bravo = 'test_alfa_bravo'
     content = 'tags = ["alfa", "bravo"]'
     test_name = '{}.{}'.format('foo', tests.test_alfa_bravo)
     test_utils.create_test(project,
                            test_name,
                            content=base_content + content)
     tests.test_bravo_charlie = 'test_bravo_charlie'
     content = 'tags = ["bravo", "charlie"]'
     test_name = '{}.{}'.format('foo', tests.test_bravo_charlie)
     test_utils.create_test(project,
                            test_name,
                            content=base_content + content)
     tests.test_empty_tags = 'test_empty_tags'
     content = 'tags = []'
     test_utils.create_test(project,
                            tests.test_empty_tags,
                            content=base_content + content)
     tests.test_no_tags = 'test_no_tags'
     content = 'def test(data):\n     pass'
     test_utils.create_test(project,
                            tests.test_no_tags,
                            content=base_content + content)
     path_list = [testdir, 'projects', project, 'tests', 'empty']
     file_manager.create_directory(path_list=path_list, add_init=True)
     project_class.tests = list(tests.__dict__)
     project_class.t = tests
     return project_class
Esempio n. 5
0
 def test_create_directory_with_init(self, dir_function):
     path = dir_function.path
     file_manager.create_directory(path_list=[path, 'a', 'b', 'c'], add_init=True)
     expected_dir = os.path.join(path, 'a', 'b', 'c')
     assert os.path.isdir(expected_dir)
     init_file_path = os.path.join(expected_dir, '__init__.py')
     assert os.path.exists(init_file_path)
Esempio n. 6
0
def new_page_object(root_path, project, parents, page_name, add_parents=False):
    """Create a new page object.
    Parents is a list of directories and subdirectories where the
    page should be stored.
    If add_parents is True, the parent directories will be added
    if they do not exist."""
    errors = []
    full_page_path = os.path.join(root_path, 'projects', project, 'pages',
                                  os.sep.join(parents),
                                  '{}.py'.format(page_name))
    if os.path.isfile(full_page_path):
        errors.append('A page file with that name already exists')
    if not errors:
        page_path = os.path.join(root_path, 'projects', project, 'pages',
                                 os.sep.join(parents))
        if not os.path.exists(page_path):
            if add_parents:
                base_path = pages_base_dir(root_path, project)
                for parent in parents:
                    base_path = os.path.join(base_path, parent)
                    if not os.path.exists(base_path):
                        file_manager.create_directory(path=base_path,
                                                      add_init=True)
            else:
                errors.append('Directory for new page does not exist')
    if not errors:
        with open(full_page_path, 'w') as po_file:
            po_file.write('')
    return errors
Esempio n. 7
0
def new_test_case(project, parents, tc_name):
    """Create a new empty test case."""
    test_case_content = ("\n"
                         "description = ''\n\n"
                         "tags = []\n\n"
                         "pages = []\n\n"
                         "def setup(data):\n"
                         "    pass\n\n"
                         "def test(data):\n"
                         "    pass\n\n"
                         "def teardown(data):\n"
                         "    pass\n\n")
    errors = []
    # check if a file already exists
    base_path = os.path.join(session.testdir, 'projects', project, 'tests')
    full_path = os.path.join(base_path, os.sep.join(parents))
    filepath = os.path.join(full_path, '{}.py'.format(tc_name))
    if os.path.isfile(filepath):
        errors.append('A test with that name already exists')
    if not errors:
        # create the directory structure if it does not exist
        if not os.path.isdir(full_path):
            for parent in parents:
                base_path = os.path.join(base_path, parent)
                file_manager.create_directory(path=base_path, add_init=True)

        with open(filepath, 'w') as test_file:
            test_file.write(test_case_content)
        print('Test {} created for project {}'.format(tc_name, project))
    return errors
Esempio n. 8
0
 def test_create_directory_path(self, dir_function):
     base_dir = dir_function.path
     expected_dir = os.path.join(base_dir, 'd', 'e', 'f')
     file_manager.create_directory(path=expected_dir, add_init=True)
     assert os.path.isdir(expected_dir)
     init_file_path = os.path.join(expected_dir, '__init__.py')
     assert os.path.exists(init_file_path)
Esempio n. 9
0
 def test_create_directory_path_list(self, dir_function):
     base_dir = dir_function.path
     file_manager.create_directory(path_list=[base_dir, 'a', 'b', 'c'],
                                   add_init=False)
     expected_dir = os.path.join(base_dir, 'a', 'b', 'c')
     assert os.path.isdir(expected_dir)
     init_file_path = os.path.join(expected_dir, '__init__.py')
     assert not os.path.exists(init_file_path)
Esempio n. 10
0
 def test_create_directory_path(self, random_project_fixture):
     project = random_project_fixture['name']
     testdir = random_project_fixture['testdir']
     base_dir = page_object.pages_base_dir(testdir, project)
     expected_dir = os.path.join(base_dir, 'd', 'e', 'f')
     file_manager.create_directory(path=expected_dir, add_init=True)
     assert os.path.isdir(expected_dir)
     init_file_path = os.path.join(expected_dir, '__init__.py')
     assert os.path.exists(init_file_path)
Esempio n. 11
0
def duplicate_element(project, element_type, original_file_dot_path, new_file_dot_path):
    errors = []
    if element_type == 'test':
        folder = 'tests'
    elif element_type == 'page':
        folder = 'pages'
    elif element_type == 'suite':
        folder = 'suites'
    else:
        errors.append('Element type is incorrect')
    if not errors:
        if original_file_dot_path == new_file_dot_path:
            errors.append('New file cannot be the same as the original')
        for c in new_file_dot_path.replace('.', ''):
            if not c.isalnum() and c != '_':
                errors.append('Only letters, numbers and underscores are allowed')
                break

    if not errors:
        root_path = os.path.join(session.testdir, 'projects', project)
        original_file_rel_path = original_file_dot_path.replace('.', os.sep) + '.py'
        original_file_full_path = os.path.join(root_path, folder, original_file_rel_path)
        new_file_rel_path = new_file_dot_path.replace('.', os.sep) + '.py'
        new_file_full_path = os.path.join(root_path, folder, new_file_rel_path)
        if os.path.exists(new_file_full_path):
            errors.append('A file with that name already exists')

    if not errors:
        try:
            file_manager.create_directory(path=os.path.dirname(new_file_full_path), add_init=True)
            shutil.copyfile(original_file_full_path, new_file_full_path)
        except:
            errors.append('There was an error creating the new file')

    if not errors and element_type == 'test':
        # TODO deprecate data folder
        try:
            original_data_rel_path = original_file_dot_path.replace('.', os.sep) + '.csv'
            original_data_full_path = os.path.join(root_path, 'data', original_data_rel_path)
            new_data_rel_path = new_file_dot_path.replace('.', os.sep) + '.csv'
            new_data_full_path = os.path.join(root_path, 'data', new_data_rel_path)
            os.makedirs(os.path.dirname(new_data_full_path), exist_ok=True)
            shutil.copyfile(original_data_full_path, new_data_full_path)
        except:
            pass
        try:
            original_data_rel_path = original_file_dot_path.replace('.', os.sep) + '.csv'
            original_data_full_path = os.path.join(root_path, 'tests', original_data_rel_path)
            new_data_rel_path = new_file_dot_path.replace('.', os.sep) + '.csv'
            new_data_full_path = os.path.join(root_path, 'tests', new_data_rel_path)
            file_manager.create_directory(path=os.path.dirname(new_data_full_path), add_init=True)
            shutil.copyfile(original_data_full_path, new_data_full_path)
        except:
            pass

    return errors
Esempio n. 12
0
 def test_create_directory_path_list(self, random_project_fixture):
     project = random_project_fixture['name']
     testdir = random_project_fixture['testdir']
     base_dir = page_object.pages_base_dir(testdir, project)
     file_manager.create_directory(path_list=[base_dir, 'a', 'b', 'c'],
                                   add_init=False)
     expected_dir = os.path.join(base_dir, 'a', 'b', 'c')
     assert os.path.isdir(expected_dir)
     init_file_path = os.path.join(expected_dir, '__init__.py')
     assert not os.path.exists(init_file_path)
Esempio n. 13
0
    def test_golem_run_directory_no_tests_present(self, project_function):
        project = project_function.name
        with pytest.raises(SystemExit) as excinfo:
            commands.run_command(project=project, test_query='.')
        msg = ('No tests were found in {}'.format(os.path.join('tests', '')))
        assert str(excinfo.value) == msg

        path = os.path.join(project_function.path, 'tests', 'foo')
        file_manager.create_directory(path=path, add_init=True)
        with pytest.raises(SystemExit) as excinfo:
            commands.run_command(project=project, test_query='foo')
        msg = ('No tests were found in {}'.format(os.path.join('tests',
                                                               'foo')))
        assert str(excinfo.value) == msg
Esempio n. 14
0
 def test_golem_run_directory_no_tests_present(self, project_function,
                                               capsys):
     _, project = project_function.activate()
     # run all tests, there are no tests in project
     commands.run_command(project=project, test_query='.')
     msg = 'No tests were found in {}'.format(os.path.join('tests', ''))
     out, err = capsys.readouterr()
     assert msg in out
     # run tests in an empty directory
     path = os.path.join(project_function.path, 'tests', 'foo')
     file_manager.create_directory(path=path, add_init=True)
     commands.run_command(project=project, test_query='foo')
     msg = 'No tests were found in {}'.format(os.path.join('tests', 'foo'))
     out, err = capsys.readouterr()
     assert msg in out
Esempio n. 15
0
def create_project(project_name):
    project = Project(project_name)
    file_manager.create_directory(path=project.path, add_init=True)
    file_manager.create_directory(path=project.test_directory_path, add_init=True)
    file_manager.create_directory(path=project.page_directory_path, add_init=True)
    file_manager.create_directory(path=project.suite_directory_path, add_init=True)
    file_manager.create_directory(path=project.report_directory_path, add_init=True)
    extend_path = os.path.join(project.path, 'extend.py')
    open(extend_path, 'a').close()

    settings_manager.create_project_settings_file(project_name)

    for project_base_file in ('environments.json', 'secrets.json'):
        base_file_path = os.path.join(project.path, project_base_file)
        with open(base_file_path, 'a') as base_file:
            base_file.write('{}')

    print('Project {} created'.format(project_name))
Esempio n. 16
0
def create_test_dir(workspace):
    file_manager.create_directory(path_list=[workspace], add_init=True)
    file_manager.create_directory(path_list=[workspace, 'projects'],
                                  add_init=True)
    file_manager.create_directory(path_list=[workspace, 'drivers'],
                                  add_init=False)

    golem_start_py_content = ("import os\n\n"
                              "from golem.main import execute_from_command_line"
                              "\n\n"
                              "if __name__ == '__main__':\n"
                              "    execute_from_command_line(os.getcwd())\n")
    golem_start_py_path = os.path.join(workspace, 'golem_start.py')
    with open(golem_start_py_path, 'a') as golem_start_py_file:
        golem_start_py_file.write(golem_start_py_content)

    settings_manager.create_global_settings_file(workspace)

    users_path = os.path.join(workspace, 'users.json')
    open(users_path, 'a').close()
    create_user(workspace, 'admin', 'admin', True, ["*"], ["*"])

    print('New golem test directory created at {}'.format(workspace))
    print('Use credentials to access the GUI module:')
    print('user: admin')
    print('password: admin')
Esempio n. 17
0
def create_new_project(project):
    testdir = session.testdir
    file_manager.create_directory(path_list=[testdir, 'projects', project], add_init=True)
    path_list = [testdir, 'projects', project, 'pages']
    file_manager.create_directory(path_list=path_list, add_init=True)
    path_list = [testdir, 'projects', project, 'reports']
    file_manager.create_directory(path_list=path_list, add_init=False)
    path_list = [testdir, 'projects', project, 'tests']
    file_manager.create_directory(path_list=path_list, add_init=True)
    path_list = [testdir, 'projects', project, 'suites']
    file_manager.create_directory(path_list=path_list, add_init=True)
    extend_path = os.path.join(testdir, 'projects', project, 'extend.py')
    open(extend_path, 'a').close()

    settings_manager.create_project_settings_file(project)

    for project_base_file in ('environments.json', 'secrets.json'):
        base_file_path = os.path.join(testdir, 'projects', project, project_base_file)
        with open(base_file_path, 'a') as base_file:
            base_file.write('{}')

    print('Project {} created'.format(project))
Esempio n. 18
0
def new_suite(root_path, project, parents, suite_name):
    """Create a new empty suite."""
    suite_content = ('\n'
                     'apps = []\n\n'
                     'environments = []\n\n'
                     'workers = 1\n\n'
                     'tests = []\n')
    errors = []
    base_path = os.path.join(root_path, 'projects', project, 'suites')
    full_path = os.path.join(base_path, os.sep.join(parents))
    filepath = os.path.join(full_path, '{}.py'.format(suite_name))
    if os.path.isfile(filepath):
        errors.append('A suite with that name already exists')
    if not errors:
        # create the directory structure if it does not exist
        if not os.path.isdir(full_path):
            for parent in parents:
                base_path = os.path.join(base_path, parent)
                file_manager.create_directory(path=base_path, add_init=True)
        with open(filepath, 'w') as suite_file:
            suite_file.write(suite_content)
        print('Suite {} created for project {}'.format(suite_name, project))
    return errors
def create_test_directory(testdir):
    file_manager.create_directory(path_list=[testdir], add_init=True)
    file_manager.create_directory(path_list=[testdir, 'projects'],
                                  add_init=True)
    file_manager.create_directory(path_list=[testdir, 'drivers'],
                                  add_init=False)
    settings_manager.create_global_settings_file(testdir)
    create_testdir_golem_file(testdir)
    session.testdir = testdir
    Users.create_super_user('admin', 'admin')
Esempio n. 20
0
def create_test_dir(testdir):
    file_manager.create_directory(path_list=[testdir], add_init=True)
    file_manager.create_directory(path_list=[testdir, 'projects'],
                                  add_init=True)
    file_manager.create_directory(path_list=[testdir, 'drivers'],
                                  add_init=False)

    settings_manager.create_global_settings_file(testdir)

    create_testdir_golem_file(testdir)

    users_path = os.path.join(testdir, 'users.json')
    open(users_path, 'a').close()
    create_user('admin', 'admin', True, ["*"], ["*"], testdir=testdir)

    print('New golem test directory created at {}'.format(testdir))
    print('Use credentials to access the GUI module:')
    print('user: admin')
    print('password: admin')