def test_rename_test_with_data_file(self, project_session, test_utils): """Assert when a test has a data file the data file is renamed as well""" _, project = project_session.activate() test_name = test_utils.create_random_test(project) new_test_name = test_utils.random_string() data_path = os.path.splitext(Test(project, test_name).path)[0] + '.csv' with open(data_path, 'w+') as f: f.write('') new_data_path = os.path.splitext(Test(project, new_test_name).path)[0] + '.csv' test_module.rename_test(project, test_name, new_test_name) assert not os.path.isfile(data_path) assert os.path.isfile(new_data_path)
def test_rename_dest_exists(self, project_session, test_utils): _, project = project_session.activate() dir = test_utils.random_string() name_one = test_utils.random_string() test_one = '{}.{}'.format(dir, name_one) name_two = test_utils.random_string() test_two = '{}.{}'.format(dir, name_two) test_utils.create_test(project, test_one) test_utils.create_test(project, test_two) # rename test to existing test name errors = test_module.rename_test(project, test_one, test_two) assert errors == ['A file with that name already exists'] # rename test to same name errors = test_module.rename_test(project, test_one, test_one) assert errors == ['A file with that name already exists']
def test_rename_test_src_does_not_exist(self, project_session, test_utils): _, project = project_session.activate() test_name = test_utils.random_string() new_test_name = test_utils.random_string() errors = test_module.rename_test(project, test_name, new_test_name) assert errors == ['Test {} does not exist'.format(test_name)] assert new_test_name not in Project(project).tests()
def test_rename(): project = request.json['project'] test_name = request.json['fullFilename'] new_test_name = request.json['newFullFilename'] _verify_permissions(Permissions.STANDARD, project) errors = test_module.rename_test(project, test_name, new_test_name) return jsonify({'errors': errors})
def test_rename_test_test_is_open(self, project_session, test_utils): """Try to rename a test while it is open""" _, project = project_session.activate() test_name = test_utils.create_random_test(project) new_test_name = test_utils.random_string() with open(Test(project, test_name).path) as f: errors = test_module.rename_test(project, test_name, new_test_name) assert errors == ['There was an error renaming file']
def test_rename_test(self, project_session, test_utils): _, project = project_session.activate() test_name = test_utils.create_random_test(project) new_test_name = test_utils.random_string() errors = test_module.rename_test(project, test_name, new_test_name) assert errors == [] tests = Project(project).tests() assert test_name not in tests assert new_test_name in tests
def test_rename_test_error(self, project_session, test_utils): _, project = project_session.activate() test_name = test_utils.create_random_test(project) new_test_name = 'new-name' errors = test_module.rename_test(project, test_name, new_test_name) assert errors == ['Only letters, numbers and underscores are allowed'] tests = Project(project).tests() assert test_name in tests assert new_test_name not in tests
def _rename_project_element(element_type): project = request.json['project'] name = request.json['fullFilename'] new_name = request.json['newFullFilename'] errors = [] _verify_permissions(Permissions.STANDARD, project) if element_type == Project.file_types.TEST: errors = test_module.rename_test(project, name, new_name) elif element_type == Project.file_types.PAGE: errors = page_module.rename_page(project, name, new_name) elif element_type == Project.file_types.SUITE: errors = suite_module.rename_suite(project, name, new_name) else: errors.append('Invalid element type {}'.format(element_type)) return jsonify({'errors': errors})
def test_rename_test_invalid_name(self, project_session, test_utils): _, project = project_session.activate() test_name = test_utils.create_random_test(project) # invalid chars new_test_name = 'new-name' errors = test_module.rename_test(project, test_name, new_test_name) assert errors == ['Only letters, numbers and underscores are allowed'] tests = Project(project).tests() assert test_name in tests assert new_test_name not in tests # empty filename new_test_name = 'test.' errors = test_module.rename_test(project, test_name, new_test_name) assert errors == ['File name cannot be empty'] tests = Project(project).tests() assert test_name in tests assert new_test_name not in tests # empty directory new_test_name = 'test..test' errors = test_module.rename_test(project, test_name, new_test_name) assert errors == ['Directory name cannot be empty'] tests = Project(project).tests() assert test_name in tests assert new_test_name not in tests
def test_rename_test_in_folder(self, project_session, test_utils): _, project = project_session.activate() dir = test_utils.random_string() name = test_utils.random_string() test_name = '{}.{}'.format(dir, name) test_utils.create_test(project, test_name) # rename within same folder new_name = test_utils.random_string() new_test_name = '{}.{}'.format(dir, new_name) errors = test_module.rename_test(project, test_name, new_test_name) assert errors == [] tests = Project(project).tests() assert test_name not in tests assert new_test_name in tests # rename to another non existent folder test_name = new_test_name name = new_name new_dir = test_utils.random_string() new_test_name = '{}.{}'.format(new_dir, name) errors = test_module.rename_test(project, test_name, new_test_name) assert errors == [] tests = Project(project).tests() assert test_name not in tests assert new_test_name in tests