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 test_new_directory_of_type_already_exist(self, project_class): testdir = project_class['testdir'] project = project_class['name'] file_manager.new_directory_of_type(testdir, project, [], 'new_suites_dir_two', 'suites') errors = file_manager.new_directory_of_type(testdir, project, [], 'new_suites_dir_two', 'suites') assert errors == ['A directory with that name already exists']
def test_new_directory_of_type_already_exist(self, project_class): _, project = project_class.activate() file_manager.new_directory_of_type(project, [], 'new_suites_dir_two', 'suites') errors = file_manager.new_directory_of_type(project, [], 'new_suites_dir_two', 'suites') assert errors == ['A directory with that name already exists']
def test_new_directory_of_type_already_exist(self, random_project_fixture): project = random_project_fixture['name'] testdir = random_project_fixture['testdir'] file_manager.new_directory_of_type(testdir, project, [], 'new_suites_dir_two', 'suites') errors = file_manager.new_directory_of_type(testdir, project, [], 'new_suites_dir_two', 'suites') assert errors == ['A directory with that name already exists']
def test_new_directory_of_type_invalid_type(self, random_project_fixture): project = random_project_fixture['name'] testdir = random_project_fixture['testdir'] errors = file_manager.new_directory_of_type(testdir, project, [], 'new_suites_dir', 'invalid_type') assert errors == ['invalid_type is not a valid dir_type']
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'] 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 or underscores if len(element_name) == 0: errors.append('Name cannot be empty') else: for c in element_name: if not c.isalnum() and c != '_': errors.append('Only letters, numbers and underscores are allowed') break if not errors: if elem_type == 'test': if is_dir: errors = file_manager.new_directory_of_type(project, parents, element_name, dir_type='tests') else: errors = test_case.new_test_case(project, parents, element_name) elif elem_type == 'page': if is_dir: errors = file_manager.new_directory_of_type(project, parents, element_name, dir_type='pages') else: errors = page_object.new_page_object(project, parents, element_name) elif elem_type == 'suite': if is_dir: errors = file_manager.new_directory_of_type(project, parents, element_name, dir_type='suites') else: errors = suite_module.new_suite(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 test_new_directory_of_type_suites(self, project_class): _, project = project_class.activate() errors = file_manager.new_directory_of_type(project, [], 'new_suites_dir', 'suites') expected_dir = os.path.join(project_class.path, 'suites', 'new_suites_dir') expected_init_path = os.path.join(expected_dir, '__init__.py') assert os.path.isdir(expected_dir) assert os.path.isfile(expected_init_path) assert errors == []
def test_new_directory_of_type_pages(self, project_class): testdir = project_class.testdir project = project_class.name errors = file_manager.new_directory_of_type(testdir, project, [], 'new_pages_dir', 'pages') expected_dir = os.path.join(project_class.path, 'pages', 'new_pages_dir') expected_init_path = os.path.join(expected_dir, '__init__.py') assert os.path.isdir(expected_dir) assert os.path.isfile(expected_init_path) assert errors == []
def test_new_directory_of_type_suites(self, project_class): testdir = project_class['testdir'] project = project_class['name'] errors = file_manager.new_directory_of_type(testdir, project, [], 'new_suites_dir', 'suites') expected_dir = os.path.join(testdir, 'projects', project, 'suites', 'new_suites_dir') expected_init_path = os.path.join(expected_dir, '__init__.py') assert os.path.isdir(expected_dir) assert os.path.isfile(expected_init_path) assert errors == []
def test_new_directory_of_type_pages(self, random_project_fixture): project = random_project_fixture['name'] testdir = random_project_fixture['testdir'] errors = file_manager.new_directory_of_type(testdir, project, [], 'new_pages_dir', 'pages') expected_dir = os.path.join(testdir, 'projects', project, 'pages', 'new_pages_dir') expected_init_path = os.path.join(expected_dir, '__init__.py') assert os.path.isdir(expected_dir) assert os.path.isfile(expected_init_path) assert errors == []
def test_new_directory_of_type_invalid_type(self, project_class): errors = file_manager.new_directory_of_type(project_class.testdir, project_class.name, [], 'new_suites_dir', 'invalid_type') assert errors == ['invalid_type is not a valid dir_type']
def test_new_directory_of_type_invalid_type(self, project_class): testdir = project_class['testdir'] project = project_class['name'] errors = file_manager.new_directory_of_type(testdir, project, [], 'new_suites_dir', 'invalid_type') assert errors == ['invalid_type is not a valid dir_type']
def test_new_directory_of_type_invalid_type(self, project_class): _, project = project_class.activate() errors = file_manager.new_directory_of_type(project, [], 'new_suites_dir', 'invalid_type') assert errors == ['invalid_type is not a valid dir_type']