def test_new_suite_already_exists(self, project_session): testdir = project_session['testdir'] project = project_session['name'] suite_name = 'test_save_suite_0005' suite.new_suite(testdir, project, [], suite_name) errors = suite.new_suite(testdir, project, [], suite_name) assert errors == ['a suite with that name already exists']
def test_save_suite_empty(self, project_session): testdir = project_session['testdir'] project = project_session['name'] suite_name = 'test_save_suite_0002' suite.new_suite(testdir, project, [], suite_name) test_cases = [] browsers = [] workers = 2 environments = [] suite.save_suite(testdir, project, suite_name, test_cases, workers, browsers, environments) expected = ("\n" "\n" "browsers = []\n" "\n" "environments = []\n" "\n" "workers = 2\n" "\n" "tests = []\n") path = os.path.join(testdir, 'projects', project, 'suites', suite_name + '.py') with open(path) as suite_file: content = suite_file.read() assert content == expected
def test_save_suite(self, project_session): _, project = project_session.activate() suite_name = 'test_save_suite_0001' suite.new_suite(project, [], suite_name) test_cases = ['test01', 'test02'] browsers = [ 'browser01', 'browser02', ] processes = 2 environments = ['env01', 'env02'] suite.save_suite(project, suite_name, test_cases, processes, browsers, environments, []) expected = ("\n" "\n" "browsers = [\n" " 'browser01',\n" " 'browser02'\n" "]\n" "\n" "environments = [\n" " 'env01',\n" " 'env02'\n" "]\n" "\n" "processes = 2\n" "\n" "tests = [\n" " 'test01',\n" " 'test02'\n" "]\n") path = os.path.join(project_session.path, 'suites', suite_name + '.py') with open(path) as suite_file: content = suite_file.read() assert content == expected
def test_get_suite_module(self, project_function): testdir = project_function['testdir'] project = project_function['name'] suite_name = 'test_suite_006' suite.new_suite(testdir, project, [], suite_name) module = suite.get_suite_module(testdir, project, suite_name) assert type(module) == types.ModuleType
def test_get_suites(self, testdir_fixture, project_fixture): suite.new_suite(testdir_fixture['path'], project_fixture['name'], [], 'suite1') suite.new_suite(testdir_fixture['path'], project_fixture['name'], [], 'suite2') suites = utils.get_suites(testdir_fixture['path'], project_fixture['name']) expected_result = { 'type': 'directory', 'name': 'suites', 'dot_path': '.', 'sub_elements': [{ 'type': 'file', 'name': 'suite1', 'dot_path': 'suite1', 'sub_elements': [] }, { 'type': 'file', 'name': 'suite2', 'dot_path': 'suite2', 'sub_elements': [] }] } assert suites == expected_result
def test_get_suites(self, testdir_fixture, project_fixture): suite.new_suite(testdir_fixture['path'], project_fixture['name'], [], 'suite1') suite.new_suite(testdir_fixture['path'], project_fixture['name'], [], 'suite2') suites = utils.get_suites(testdir_fixture['path'], project_fixture['name']) expected_result = { 'type': 'directory', 'name': 'suites', 'dot_path': '.', 'sub_elements': [ { 'type': 'file', 'name': 'suite1', 'dot_path': 'suite1', 'sub_elements': [] }, { 'type': 'file', 'name': 'suite2', 'dot_path': 'suite2', 'sub_elements': [] } ] } assert suites == expected_result
def test_new_suite_already_exists(self, permanent_project_fixture): testdir = permanent_project_fixture['testdir'] project = permanent_project_fixture['name'] suite_name = 'test_save_suite_0003' suite.new_suite(testdir, project, [], suite_name) errors = suite.new_suite(testdir, project, [], suite_name) assert errors == ['A suite with that name already exists']
def test_get_suites(self, project_class): _, project = project_class.activate() suite.new_suite(project, [], 'suite1') suite.new_suite(project, [], 'suite2') suites = utils.get_suites(project) expected_result = { 'type': 'directory', 'name': 'suites', 'dot_path': '.', 'sub_elements': [{ 'type': 'file', 'name': 'suite1', 'dot_path': 'suite1', 'sub_elements': [] }, { 'type': 'file', 'name': 'suite2', 'dot_path': 'suite2', 'sub_elements': [] }] } assert suites == expected_result
def test_get_suite_module(self, project_function): testdir = project_function.testdir project = project_function.name suite_name = 'test_suite_006' suite.new_suite(testdir, project, [], suite_name) module = suite.get_suite_module(testdir, project, suite_name) assert isinstance(module, types.ModuleType)
def test_get_suite_browsers(self, project_function): _, project = project_function.activate() suite_name = 'test_suite_005' suite.new_suite(project, [], suite_name) browsers = ['browser1', 'browser2'] suite.save_suite(project, suite_name, [], 1, browsers, [], []) result = suite.get_suite_browsers(project, suite_name) assert result == browsers
def test_get_suite_test_cases(self, project_function): _, project = project_function.activate() suite_name = 'test_suite_003' suite.new_suite(project, [], suite_name) tests = ['test_name_01', 'test_name_02'] suite.save_suite(project, suite_name, tests, 1, [], [], []) result = suite.get_suite_test_cases(project, suite_name) assert result == tests
def test_get_suite_environments(self, project_function): _, project = project_function.activate() suite_name = 'test_suite_002' suite.new_suite(project, [], suite_name) environments = ['env1', 'env2'] suite.save_suite(project, suite_name, [], 1, [], environments, []) result = suite.get_suite_environments(project, suite_name) assert result == environments
def test_duplicate_destination_already_exists(self, project_function): testdir = project_function['testdir'] project = project_function['name'] os.chdir(testdir) suite.new_suite(testdir, project, [], 'suite1') suite.new_suite(testdir, project, [], 'suite2') errors = utils.duplicate_element(testdir, project, 'suite', 'suite1', 'suite2') assert errors == ['A file with that name already exists']
def test_get_suite_browsers(self, project_function): testdir = project_function['testdir'] project = project_function['name'] suite_name = 'test_suite_005' suite.new_suite(testdir, project, [], suite_name) browsers = ['browser1', 'browser2'] suite.save_suite(testdir, project, suite_name, [], 1, browsers, []) result = suite.get_suite_browsers(testdir, project, suite_name) assert result == browsers
def test_get_suite_test_cases(self, project_function): testdir = project_function['testdir'] project = project_function['name'] suite_name = 'test_suite_003' suite.new_suite(testdir, project, [], suite_name) tests = ['test_name_01', 'test_name_02'] suite.save_suite(testdir, project, suite_name, tests, 1, [], []) result = suite.get_suite_test_cases(testdir, project, suite_name) assert result == tests
def test_get_suite_amount_of_processes(self, project_function): _, project = project_function.activate() suite_name = 'test_suite_processes_001' suite.new_suite(project, [], suite_name) processes = 2 suite.save_suite(project, suite_name, [], processes, [], [], []) suite_processes = suite.get_suite_amount_of_processes( project, suite_name) assert suite_processes == processes
def test_get_suite_environments(self, project_function): testdir = project_function['testdir'] project = project_function['name'] suite_name = 'test_suite_002' suite.new_suite(testdir, project, [], suite_name) environments = ['env1', 'env2'] suite.save_suite(testdir, project, suite_name, [], 1, [], environments) result = suite.get_suite_environments(testdir, project, suite_name) assert result == environments
def test_get_suite_amount_of_workers(self, project_function): testdir = project_function.testdir project = project_function.name suite_name = 'test_suite_workers_001' suite.new_suite(testdir, project, [], suite_name) worker_amount = 2 suite.save_suite(testdir, project, suite_name, [], worker_amount, [], []) workers = suite.get_suite_amount_of_workers(testdir, project, suite_name) assert workers == worker_amount
def test_delete_suites(self, project_function): _, project = project_function.activate() suite.new_suite(project, [], 'suite1') suite.new_suite(project, [], 'suite2') errors = utils.delete_element(project, 'suite', 'suite1') assert errors == [] path = os.path.join(project_function.path, 'suites', 'suite1.py') assert not os.path.exists(path) path = os.path.join(project_function.path, 'suites', 'suite2.py') assert os.path.exists(path)
def test_get_suite_test_cases_get_all(self, project_function): _, project = project_function.activate() test_case.new_test_case(project, [], 'test_name_01') test_case.new_test_case(project, ['a', 'b'], 'test_name_02') suite_name = 'test_suite_004' suite.new_suite(project, [], suite_name) tests = ['*'] suite.save_suite(project, suite_name, tests, 1, [], [], []) result = suite.get_suite_test_cases(project, suite_name) expected = ['test_name_01', 'a.b.test_name_02'] assert result == expected
def test_duplicate_suite(self, project_function): testdir = project_function['testdir'] project = project_function['name'] os.chdir(testdir) suite.new_suite(testdir, project, [], 'suite1') errors = utils.duplicate_element(testdir, project, 'suite', 'suite1', 'sub.suite2') assert errors == [] path = os.path.join(testdir, 'projects', project, 'suites', 'suite1.py') assert os.path.isfile(path) path = os.path.join(testdir, 'projects', project, 'suites', 'sub', 'suite2.py') assert os.path.isfile(path)
def test_new_suite_with_parents_already_exist(self, project_session): _, project = project_session.activate() suite_name1 = 'test_save_suite_0006' suite_name2 = 'test_save_suite_0007' parents = ['asf01'] suite.new_suite(project, parents, suite_name1) errors = suite.new_suite(project, parents, suite_name2) path = os.path.join(project_session.path, 'suites', os.sep.join(parents), suite_name2 + '.py') assert errors == [] assert os.path.isfile(path)
def test_duplicate_suite(self, project_function): _, project = project_function.activate() suite.new_suite(project, [], 'suite1') errors = utils.duplicate_element(project, 'suite', 'suite1', 'sub.suite2') assert errors == [] path = os.path.join(project_function.path, 'suites', 'suite1.py') assert os.path.isfile(path) path = os.path.join(project_function.path, 'suites', 'sub', 'suite2.py') assert os.path.isfile(path)
def test_delete_suites(self, project_function): testdir = project_function.testdir project = project_function.name os.chdir(testdir) suite.new_suite(testdir, project, [], 'suite1') suite.new_suite(testdir, project, [], 'suite2') errors = utils.delete_element(testdir, project, 'suite', 'suite1') assert errors == [] path = os.path.join(project_function.path, 'suites', 'suite1.py') assert not os.path.exists(path) path = os.path.join(project_function.path, 'suites', 'suite2.py') assert os.path.exists(path)
def test_new_suite_with_parents_already_exist(self, project_session): testdir = project_session['testdir'] project = project_session['name'] suite_name1 = 'test_save_suite_0006' suite_name2 = 'test_save_suite_0007' parents = ['asf01'] suite.new_suite(testdir, project, parents, suite_name1) errors = suite.new_suite(testdir, project, parents, suite_name2) path = os.path.join(testdir, 'projects', project, 'suites', os.sep.join(parents), suite_name2 + '.py') assert errors == [] assert os.path.isfile(path)
def create_suite(testdir, project, parents, name, content=None, tests=None): if content is None and tests is not None: content = 'tests = {}'.format(str(tests)) suite.new_suite(testdir, project, parents, name) path = os.path.join(testdir, 'projects', project, 'suites', os.sep.join(parents), name + '.py') with open(path, 'w+') as f: f.write(content)
def new_tree_element(): if request.method == 'POST': project = request.form['project'] elem_type = request.form['elementType'] is_dir = json.loads(request.form['isDir']) full_path = request.form['fullPath'] add_parents = request.form['addParents'] full_path = full_path.replace(' ', '_') dot_path = full_path errors = [] full_path = full_path.split('.') element_name = full_path.pop() parents = full_path # verify that the string only contains letters, numbers # dashes or underscores for c in element_name: if not c.isalnum() and not c in ['-', '_']: errors.append('Only letters, numbers, \'-\' and \'_\' are allowed') break if not errors: if elem_type == 'test': if is_dir: errors = file_manager.new_directory_of_type(root_path, project, parents, element_name, dir_type='tests') else: errors = test_case.new_test_case(root_path, project, parents, element_name) # changelog.log_change(root_path, project, 'CREATE', 'test', # full_path, g.user.username) elif elem_type == 'page': if is_dir: errors = file_manager.new_directory_of_type(root_path, project, parents, element_name, dir_type='pages') else: errors = page_object.new_page_object(root_path, project, parents, element_name, add_parents=add_parents) elif elem_type == 'suite': if is_dir: errors = file_manager.new_directory_of_type(root_path, project, parents, element_name, dir_type='suites') else: errors = suite_module.new_suite(root_path, project, parents, element_name) element = { 'name': element_name, 'full_path': dot_path, 'type': elem_type, 'is_directory': is_dir } return json.dumps({'errors': errors, 'project_name': project, 'element': element})
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))
def createsuite_command(project, suite_name): if not utils.project_exists(project): msg = ('golem createsuite: error: a project with name {} ' 'does not exist'.format(project)) sys.exit(msg) errors = suite_module.new_suite(project, [], suite_name) if errors: sys.exit('golem createsuite: error: {}'.format(' '.join(errors)))
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)))
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))
def new_tree_element(): if request.method == 'POST': project = request.form['project'] elem_type = request.form['elementType'] is_dir = json.loads(request.form['isDir']) full_path = request.form['fullPath'] add_parents = request.form['addParents'] full_path = full_path.replace(' ', '_') dot_path = full_path errors = [] full_path = full_path.split('.') element_name = full_path.pop() parents = full_path # verify that the string only contains letters, numbers # dashes or underscores for c in element_name: if not c.isalnum() and not c in ['-', '_']: errors.append('Only letters, numbers, \'-\' and \'_\' are allowed') break if not errors: if elem_type == 'test': if is_dir: errors = io_manager.new_directory(root_path, project, parents, element_name, dir_type='tests') else: errors = test_case.new_test_case(root_path, project, parents, element_name) # changelog.log_change(root_path, project, 'CREATE', 'test', # full_path, g.user.username) elif elem_type == 'page': if is_dir: errors = io_manager.new_directory(root_path, project, parents, element_name, dir_type='pages') else: errors = page_object.new_page_object(root_path, project, parents, element_name, add_parents=add_parents) elif elem_type == 'suite': if is_dir: errors = io_manager.new_directory(root_path, project, parents, element_name, dir_type='suites') else: errors = suite_module.new_suite(root_path, project, parents, element_name) element = { 'name': element_name, 'full_path': dot_path, 'type': elem_type, 'is_directory': is_dir } return json.dumps({'errors': errors, 'project_name': project, 'element': element})
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 [] suite_name, parents = utils.separate_file_from_parents(name) if content is None: suite.new_suite(project, parents, suite_name) suite.save_suite(project, name, tests, processes, browsers, environments, tags) else: path = suite.suite_file_path(project, name) with open(path, 'w+') as f: f.write(content)