def test_suite_tree(self, project_function): _, project = project_function.activate() suite.create_suite(project, 'suite1') suite.create_suite(project, 'suite2') suites = Project(project).suite_tree 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_create_suite_invalid_name(self, project_session): _, project = project_session.activate() errors = suite.create_suite(project, 'invalid-name') assert errors == ['Only letters, numbers and underscores are allowed'] errors = suite.create_suite(project, 'suite.') assert errors == ['File name cannot be empty'] errors = suite.create_suite(project, '.suite') assert errors == ['Directory name cannot be empty']
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 [] if content is None: suite.create_suite(project, name) suite.edit_suite(project, name, tests, processes, browsers, environments, tags) else: with open(suite.Suite(project, name).path, 'w+') as f: f.write(content)
def createsuite_command(project, suite_name): if not test_directory.project_exists(project): msg = f'golem createsuite: error: a project with name {project} does not exist' sys.exit(msg) errors = suite_module.create_suite(project, suite_name) if errors: sys.exit('golem createsuite: error: {}'.format(' '.join(errors)))
def _create_project_element(project_name, element_name, element_type): errors = [] _verify_permissions(Permissions.STANDARD, project_name) if element_type == Project.file_types.TEST: errors = test_module.create_test(project_name, element_name) elif element_type == Project.file_types.PAGE: errors = page_module.create_page(project_name, element_name) elif element_type == Project.file_types.SUITE: errors = suite_module.create_suite(project_name, element_name) else: errors.append('Invalid element type {}'.format(element_type)) return jsonify({'errors': errors})
def create_suite(project, name=None, content=None, tests=None, processes=1, browsers=None, environments=None, tags=None): if name is None: name = TestUtils.random_string() browsers = browsers or [] environments = environments or [] tags = tags or [] if content is None: suite.create_suite(project, name) suite.edit_suite(project, name, tests, processes, browsers, environments, tags) else: with open(suite.Suite(project, name).path, 'w+') as f: f.write(content) return name
def test_create_suite(self, project_session, test_utils): _, project = project_session.activate() suite_name = test_utils.random_string() errors = suite.create_suite(project, suite_name) assert errors == [] assert suite_name in Project(project).suites() # verify new suite content with open(Suite(project, suite_name).path) as f: content = f.read() expected = ('\n' 'browsers = []\n\n' 'environments = []\n\n' 'processes = 1\n\n' 'tests = []\n') assert content == expected
def test_create_suite_with_parents(self, project_session, test_utils): _, project = project_session.activate() parents = [test_utils.random_string(), test_utils.random_string()] suite_name = f'{parents[0]}.{parents[1]}.{test_utils.random_string()}' errors = suite.create_suite(project, suite_name) assert errors == [] assert os.path.isfile(Suite(project, suite_name).path) # verify that each parent dir has __init__.py file init_path = os.path.join( Project(project).suite_directory_path, parents[0], '__init__.py') assert os.path.isfile(init_path) init_path = os.path.join( Project(project).suite_directory_path, parents[0], parents[1], '__init__.py') assert os.path.isfile(init_path)
def _create_project_element(project, element_name, element_type): errors = [] if element_type == 'test': errors = test_module.create_test(project, element_name) elif element_type == 'page': errors = page_module.create_page(project, element_name) elif element_type == 'suite': errors = suite_module.create_suite(project, element_name) else: errors.append('Invalid element type {}'.format(element_type)) element = { 'name': element_name.split('.')[-1], 'full_name': element_name } return element, errors
def create_random_suite(project): suite_name = TestUtils.random_string() suite.create_suite(project, suite_name) return suite_name
def test_create_suite_already_exists(self, project_session, test_utils): _, project = project_session.activate() suite_name = test_utils.create_random_suite(project) errors = suite.create_suite(project, suite_name) assert errors == ['A suite with that name already exists']
def create_random_suite(project): # TODO replace with create_suite(name=None) suite_name = TestUtils.random_string() suite.create_suite(project, suite_name) return suite_name