Ejemplo n.º 1
0
 def test_define_execution_list_multiple_envs(self, project_function_clean):
     """Verify that the execution list is generated properly when the execution
     has multiple envs
     """
     _, project = project_function_clean.activate()
     # create test one
     test_name_one = 'test_one_003'
     test.create_test(project, test_name_one)
     # create two environments in environments.json
     env_data = {"stage": {"url": "xxx"}, "preview": {"url": "yyy"}}
     env_data_json = json.dumps(env_data)
     environment_manager.save_environments(project, env_data_json)
     execution_runner = exc_runner.ExecutionRunner(project)
     execution_runner.tests = [test_name_one]
     execution_runner.execution.processes = 1
     execution_runner.execution.browsers = ['chrome']
     execution_runner.execution.envs = ['stage', 'preview']
     exec_list = execution_runner._define_execution_list()
     assert exec_list[0].data_set == {
         'env': {
             'url': 'xxx',
             'name': 'stage'
         }
     }
     assert exec_list[0].env == 'stage'
     assert exec_list[1].data_set == {
         'env': {
             'url': 'yyy',
             'name': 'preview'
         }
     }
     assert exec_list[1].env == 'preview'
Ejemplo n.º 2
0
 def test_define_execution_list_multiple_data_sets(self,
                                                   project_function_clean):
     """Verify that the execution list is generated properly when a test
     has multiple data sets
     """
     _, project = project_function_clean.activate()
     test_name = 'test_002'
     test.create_test(project, test_name)
     tdata = [{
         'col1': 'a',
         'col2': 'b'
     }, {
         'col1': 'c',
         'col2': 'd',
     }]
     test_data.save_csv_test_data(project, test_name, tdata)
     execution_runner = exc_runner.ExecutionRunner(project)
     execution_runner.tests = [test_name]
     execution_runner.execution.processes = 1
     execution_runner.execution.browsers = ['chrome']
     execution_runner.execution.envs = []
     execution_list = execution_runner._define_execution_list()
     assert execution_list[0].data_set == {'col1': 'a', 'col2': 'b'}
     assert isinstance(execution_list[0].set_name,
                       str) and execution_list[0].set_name != ''
     assert execution_list[1].data_set == {'col1': 'c', 'col2': 'd'}
     assert isinstance(execution_list[1].set_name,
                       str) and execution_list[1].set_name != ''
Ejemplo n.º 3
0
 def test_define_execution_list_multiple_tests(self,
                                               project_function_clean):
     """Verify that the execution list is generated properly when there
     are multiple tests in the list
     """
     _, project = project_function_clean.activate()
     # create test one
     test_name_one = 'test_one_001'
     test.create_test(project, test_name_one)
     tdata = [{
         'col1': 'a',
         'col2': 'b'
     }, {
         'col1': 'c',
         'col2': 'd',
     }]
     test_data.save_csv_test_data(project, test_name_one, tdata)
     # create test two
     test_name_two = 'test_two_001'
     test.create_test(project, test_name_two)
     execution_runner = exc_runner.ExecutionRunner(project)
     execution_runner.tests = [test_name_one, test_name_two]
     execution_runner.execution.processes = 1
     execution_runner.execution.browsers = ['chrome']
     execution_runner.execution.envs = []
     exec_list = execution_runner._define_execution_list()
     assert exec_list[0].name == 'test_one_001'
     assert exec_list[0].data_set == {'col1': 'a', 'col2': 'b'}
     assert exec_list[1].name == 'test_one_001'
     assert exec_list[1].data_set == {'col1': 'c', 'col2': 'd'}
     assert exec_list[2].name == 'test_two_001'
     assert exec_list[2].data_set == {}
Ejemplo n.º 4
0
 def test_create_test_invalid_name(self, project_session):
     _, project = project_session.activate()
     # invalid chars
     invalid_names = ['te-st', 'te st', 'te?st', 'test. .test']
     for name in invalid_names:
         errors = test_module.create_test(project, name)
         assert errors == [
             'Only letters, numbers and underscores are allowed'
         ]
     # empty directory
     invalid_names = [
         '.test',
         'test..test',
     ]
     for name in invalid_names:
         errors = test_module.create_test(project, name)
         assert errors == ['Directory name cannot be empty']
     # empty file name
     invalid_names = [
         '',
         'test.',
     ]
     for name in invalid_names:
         errors = test_module.create_test(project, name)
         assert errors == ['File name cannot be empty']
Ejemplo n.º 5
0
 def create_test(project, name, content=None):
     if content is None:
         content = ('def test(data):\n'
                    '    print("hello")\n')
     test.create_test(project, name)
     test.edit_test_code(project, name, content, table_test_data=[])
     return test.Test(project, name).path
Ejemplo n.º 6
0
 def test_define_execution_list_multiple_drivers(self,
                                                 project_function_clean):
     """Verify that the execution list is generated properly when there
     are multiple drivers in the list
     """
     _, project = project_function_clean.activate()
     # create test one
     test_name_one = 'test_one_004'
     test.create_test(project, test_name_one)
     # create test two
     test_name_two = 'test_two_004'
     test.create_test(project, test_name_two)
     execution_runner = exc_runner.ExecutionRunner(project)
     execution_runner.tests = [test_name_one, test_name_two]
     execution_runner.execution.processes = 1
     execution_runner.execution.browsers = ['chrome', 'firefox']
     execution_runner.execution.envs = []
     execution_list = execution_runner._define_execution_list()
     # expected_list = [
     #     SimpleNamespace(name='test_one_004', data_set={}, secrets={}, browser='chrome', reportdir=None, env=None, set_name=''),
     #     SimpleNamespace(name='test_one_004', data_set={}, secrets={}, browser='firefox', reportdir=None, env=None, set_name=''),
     #     SimpleNamespace(name='test_two_004', data_set={}, secrets={}, browser='chrome', reportdir=None, env=None, set_name=''),
     #     SimpleNamespace(name='test_two_004', data_set={}, secrets={}, browser='firefox', reportdir=None, env=None, set_name='')
     # ]
     # assert execution_list == expected_list
     assert len(execution_list) == 4
     assert execution_list[0].browser == 'chrome'
     assert execution_list[1].browser == 'firefox'
     assert execution_list[2].browser == 'chrome'
     assert execution_list[3].browser == 'firefox'
Ejemplo n.º 7
0
 def test_create_test_into_folder(self, project_session, test_utils):
     _, project = project_session.activate()
     random_dir = test_utils.random_string()
     # to folder
     test_name = '{}.test001'.format(random_dir)
     errors = test_module.create_test(project, test_name)
     assert errors == []
     # verify that each parent dir has __init__.py file
     init_path = os.path.join(
         Project(project).test_directory_path, random_dir, '__init__.py')
     assert test_name in Project(project).tests()
     assert os.path.isfile(init_path)
     # to sub-folder
     random_dir = test_utils.random_string()
     random_subdir = test_utils.random_string()
     test_name = '{}.{}.test001'.format(random_dir, random_subdir)
     errors = test_module.create_test(project, test_name)
     assert errors == []
     assert test_name in Project(project).tests()
     # verify that each parent dir has __init__.py file
     init_path = os.path.join(
         Project(project).test_directory_path, random_dir, '__init__.py')
     assert os.path.isfile(init_path)
     init_path = os.path.join(
         Project(project).test_directory_path, random_dir, random_subdir,
         '__init__.py')
     assert os.path.isfile(init_path)
Ejemplo n.º 8
0
 def test_define_execution_list_multiple_tests(self,
                                               project_function_clean):
     """Verify that the execution list is generated properly when there
     are multiple tests in the list
     """
     _, project = project_function_clean.activate()
     # create test one
     test_name_one = 'test_one_001'
     test.create_test(project, test_name_one)
     tdata = [{
         'col1': 'a',
         'col2': 'b'
     }, {
         'col1': 'c',
         'col2': 'd',
     }]
     test_data.save_external_test_data_file(project, test_name_one, tdata)
     # create test two
     test_name_two = 'test_two_001'
     test.create_test(project, test_name_two)
     execution_runner = exc_runner.ExecutionRunner()
     execution_runner.tests = [test_name_one, test_name_two]
     execution_runner.execution.processes = 1
     execution_runner.execution.browsers = ['chrome']
     execution_runner.execution.envs = []
     execution_runner.project = project
     execution_list = execution_runner._define_execution_list()
     expected_list = [
         SimpleNamespace(name='test_one_001',
                         data_set={
                             'col1': 'a',
                             'col2': 'b'
                         },
                         secrets={},
                         browser='chrome',
                         reportdir=None,
                         env=None),
         SimpleNamespace(name='test_one_001',
                         data_set={
                             'col1': 'c',
                             'col2': 'd'
                         },
                         secrets={},
                         browser='chrome',
                         reportdir=None,
                         env=None),
         SimpleNamespace(name='test_two_001',
                         data_set={},
                         secrets={},
                         browser='chrome',
                         reportdir=None,
                         env=None)
     ]
     assert execution_list == expected_list
Ejemplo n.º 9
0
 def test_define_execution_list_multiple_tests_datasets_drivers_envs(
         self, project_function_clean):
     """Verify that the execution list is generated properly when there
     are multiple tests, data sets, drivers and environments
     """
     _, project = project_function_clean.activate()
     # create test one
     test_name_one = 'test_one_005'
     test.create_test(project, test_name_one)
     # test data for test one
     tdata = [{'col1': 'a'}, {'col1': 'b'}]
     test_data.save_csv_test_data(project, test_name_one, tdata)
     # create test two
     test_name_two = 'test_two_005'
     test.create_test(project, test_name_two)
     # create two environments
     env_data = {"stage": {"url": "xxx"}, "preview": {"url": "yyy"}}
     env_data_json = json.dumps(env_data)
     environment_manager.save_environments(project, env_data_json)
     execution_runner = exc_runner.ExecutionRunner(project)
     execution_runner.tests = [test_name_one, test_name_two]
     execution_runner.execution.processes = 1
     execution_runner.execution.browsers = ['chrome', 'firefox']
     execution_runner.execution.envs = ['stage', 'preview']
     ex = execution_runner._define_execution_list()
     assert ex[0].browser == 'chrome' and ex[0].env == 'stage' and \
            ex[0].data_set == {'col1': 'a', 'env': {'url': 'xxx', 'name': 'stage'}}
     assert ex[1].browser == 'firefox' and ex[1].env == 'stage' and \
            ex[1].data_set == {'col1': 'a', 'env': {'url': 'xxx', 'name': 'stage'}}
     assert ex[2].browser == 'chrome' and ex[2].env == 'preview' and \
            ex[2].data_set == {'col1': 'a', 'env': {'url': 'yyy', 'name': 'preview'}}
     assert ex[3].browser == 'firefox' and ex[3].env == 'preview' and \
            ex[3].data_set == {'col1': 'a', 'env': {'url': 'yyy', 'name': 'preview'}}
     assert ex[4].browser == 'chrome' and ex[4].env == 'stage' and \
            ex[4].data_set == {'col1': 'b', 'env': {'url': 'xxx', 'name': 'stage'}}
     assert ex[5].browser == 'firefox' and ex[5].env == 'stage' and \
            ex[5].data_set == {'col1': 'b', 'env': {'url': 'xxx', 'name': 'stage'}}
     assert ex[6].browser == 'chrome' and ex[6].env == 'preview' and \
            ex[6].data_set == {'col1': 'b', 'env': {'url': 'yyy', 'name': 'preview'}}
     assert ex[7].browser == 'firefox' and ex[7].env == 'preview' and \
            ex[7].data_set == {'col1': 'b', 'env': {'url': 'yyy', 'name': 'preview'}}
     assert ex[8].browser == 'chrome' and ex[8].env == 'stage' and \
            ex[8].data_set == {'env': {'url': 'xxx', 'name': 'stage'}}
     assert ex[9].browser == 'firefox' and ex[9].env == 'stage' and \
            ex[9].data_set == {'env': {'url': 'xxx', 'name': 'stage'}}
     assert ex[10].browser == 'chrome' and ex[10].env == 'preview' and \
            ex[10].data_set == {'env': {'url': 'yyy', 'name': 'preview'}}
     assert ex[11].browser == 'firefox' and ex[11].env == 'preview' and \
            ex[11].data_set == {'env': {'url': 'yyy', 'name': 'preview'}}
Ejemplo n.º 10
0
 def test_create_test(self, project_session, test_utils):
     _, project = project_session.activate()
     test_name = test_utils.random_string()
     errors = test_module.create_test(project, test_name)
     test = Test(project, test_name)
     assert test.exists
     assert errors == []
     assert test.code == NEW_TEST_CONTENT
Ejemplo n.º 11
0
def createtest_command(project, test_name):
    if not test_directory.project_exists(project):
        msg = f'golem createtest: error: a project with name {project} does not exist'
        sys.exit(msg)
    test_name = test_name.replace(os.sep, '.')
    errors = test.create_test(project, test_name)
    if errors:
        sys.exit('golem createtest: error: {}'.format(' '.join(errors)))
Ejemplo n.º 12
0
 def test_create_test(self, project_session, test_utils):
     _, project = project_session.activate()
     test_name = test_utils.random_string()
     errors = test_module.create_test(project, test_name)
     path = Test(project, test_name).path
     assert os.path.isfile(path)
     assert errors == []
     test_code = Test(project, test_name).code
     assert test_code == NEW_TEST_CONTENT
Ejemplo n.º 13
0
 def test_define_execution_list_multiple_data_sets(self,
                                                   project_function_clean):
     """Verify that the execution list is generated properly when a test
     has multiple data sets
     """
     _, project = project_function_clean.activate()
     test_name = 'test_002'
     test.create_test(project, test_name)
     tdata = [{
         'col1': 'a',
         'col2': 'b'
     }, {
         'col1': 'c',
         'col2': 'd',
     }]
     test_data.save_external_test_data_file(project, test_name, tdata)
     execution_runner = exc_runner.ExecutionRunner()
     execution_runner.tests = [test_name]
     execution_runner.execution.processes = 1
     execution_runner.execution.browsers = ['chrome']
     execution_runner.execution.envs = ['']
     execution_runner.project = project_function_clean.name
     execution_list = execution_runner._define_execution_list()
     expected_list = [
         SimpleNamespace(name=test_name,
                         data_set={
                             'col1': 'a',
                             'col2': 'b'
                         },
                         secrets={},
                         browser='chrome',
                         reportdir=None),
         SimpleNamespace(name=test_name,
                         data_set={
                             'col1': 'c',
                             'col2': 'd'
                         },
                         secrets={},
                         browser='chrome',
                         reportdir=None)
     ]
     assert execution_list == expected_list
Ejemplo n.º 14
0
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})
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
 def test_test_tree(self, project_function):
     _, project = project_function.activate()
     test.create_test(project, 'subdir1.subdir2.test3')
     test.create_test(project, 'subdir1.test2')
     test.create_test(project, 'test1')
     tests = Project(project).test_tree
     expected = {
         'type':
         'directory',
         'name':
         'tests',
         'dot_path':
         '',
         'sub_elements': [{
             'type':
             'directory',
             'name':
             'subdir1',
             'dot_path':
             'subdir1',
             'sub_elements': [{
                 'type':
                 'directory',
                 'name':
                 'subdir2',
                 'dot_path':
                 'subdir1.subdir2',
                 'sub_elements': [{
                     'type': 'file',
                     'name': 'test3',
                     'dot_path': 'subdir1.subdir2.test3',
                     'sub_elements': []
                 }]
             }, {
                 'type': 'file',
                 'name': 'test2',
                 'dot_path': 'subdir1.test2',
                 'sub_elements': []
             }]
         }, {
             'type': 'file',
             'name': 'test1',
             'dot_path': 'test1',
             'sub_elements': []
         }]
     }
     assert tests == expected
Ejemplo n.º 17
0
 def create_random_test(project):
     test_name = TestUtils.random_string(10)
     test.create_test(project, test_name)
     return test_name
Ejemplo n.º 18
0
 def test_define_execution_list_multiple_tests_datasets_drivers_envs(
         self, project_function_clean):
     """Verify that the execution list is generated properly when there
     are multiple tests, data sets, drivers and environments
     """
     _, project = project_function_clean.activate()
     # create test one
     test_name_one = 'test_one_005'
     test.create_test(project, test_name_one)
     # test data for test one
     tdata = [{'col1': 'a'}, {'col1': 'b'}]
     test_data.save_external_test_data_file(project, test_name_one, tdata)
     # create test two
     test_name_two = 'test_two_005'
     test.create_test(project, test_name_two)
     # create two environments
     env_data = {"stage": {"url": "xxx"}, "preview": {"url": "yyy"}}
     env_data_json = json.dumps(env_data)
     environment_manager.save_environments(project, env_data_json)
     execution_runner = exc_runner.ExecutionRunner()
     execution_runner.tests = [test_name_one, test_name_two]
     execution_runner.execution.processes = 1
     execution_runner.execution.browsers = ['chrome', 'firefox']
     execution_runner.execution.envs = ['stage', 'preview']
     execution_runner.project = project
     execution_list = execution_runner._define_execution_list()
     expected_list = [
         SimpleNamespace(browser='chrome',
                         data_set={
                             'col1': 'a',
                             'env': {
                                 'url': 'xxx',
                                 'name': 'stage'
                             }
                         },
                         secrets={},
                         name='test_one_005',
                         reportdir=None,
                         env='stage'),
         SimpleNamespace(browser='firefox',
                         data_set={
                             'col1': 'a',
                             'env': {
                                 'url': 'xxx',
                                 'name': 'stage'
                             }
                         },
                         secrets={},
                         name='test_one_005',
                         reportdir=None,
                         env='stage'),
         SimpleNamespace(browser='chrome',
                         data_set={
                             'col1': 'a',
                             'env': {
                                 'url': 'yyy',
                                 'name': 'preview'
                             }
                         },
                         secrets={},
                         name='test_one_005',
                         reportdir=None,
                         env='preview'),
         SimpleNamespace(browser='firefox',
                         data_set={
                             'col1': 'a',
                             'env': {
                                 'url': 'yyy',
                                 'name': 'preview'
                             }
                         },
                         secrets={},
                         name='test_one_005',
                         reportdir=None,
                         env='preview'),
         SimpleNamespace(browser='chrome',
                         data_set={
                             'col1': 'b',
                             'env': {
                                 'url': 'xxx',
                                 'name': 'stage'
                             }
                         },
                         secrets={},
                         name='test_one_005',
                         reportdir=None,
                         env='stage'),
         SimpleNamespace(browser='firefox',
                         data_set={
                             'col1': 'b',
                             'env': {
                                 'url': 'xxx',
                                 'name': 'stage'
                             }
                         },
                         secrets={},
                         name='test_one_005',
                         reportdir=None,
                         env='stage'),
         SimpleNamespace(browser='chrome',
                         data_set={
                             'col1': 'b',
                             'env': {
                                 'url': 'yyy',
                                 'name': 'preview'
                             }
                         },
                         secrets={},
                         name='test_one_005',
                         reportdir=None,
                         env='preview'),
         SimpleNamespace(browser='firefox',
                         data_set={
                             'col1': 'b',
                             'env': {
                                 'url': 'yyy',
                                 'name': 'preview'
                             }
                         },
                         secrets={},
                         name='test_one_005',
                         reportdir=None,
                         env='preview'),
         SimpleNamespace(browser='chrome',
                         data_set={'env': {
                             'url': 'xxx',
                             'name': 'stage'
                         }},
                         secrets={},
                         name='test_two_005',
                         reportdir=None,
                         env='stage'),
         SimpleNamespace(browser='firefox',
                         data_set={'env': {
                             'url': 'xxx',
                             'name': 'stage'
                         }},
                         secrets={},
                         name='test_two_005',
                         reportdir=None,
                         env='stage'),
         SimpleNamespace(
             browser='chrome',
             data_set={'env': {
                 'url': 'yyy',
                 'name': 'preview'
             }},
             secrets={},
             name='test_two_005',
             reportdir=None,
             env='preview'),
         SimpleNamespace(
             browser='firefox',
             data_set={'env': {
                 'url': 'yyy',
                 'name': 'preview'
             }},
             secrets={},
             name='test_two_005',
             reportdir=None,
             env='preview')
     ]
     assert execution_list == expected_list
Ejemplo n.º 19
0
 def test_create_test_invalid_name(self, project_session):
     _, project = project_session.activate()
     test_name = 'this-is-a-test'
     errors = test_module.create_test(project, test_name)
     assert errors == ['Only letters, numbers and underscores are allowed']
Ejemplo n.º 20
0
 def create_random_test(project):
     # TODO replace with create_test(name=None)
     test_name = TestUtils.random_string(10)
     test.create_test(project, test_name)
     return test_name
Ejemplo n.º 21
0
 def test_create_test_name_exists(self, project_session, test_utils):
     _, project = project_session.activate()
     test_name = test_utils.random_string()
     test_module.create_test(project, test_name)
     errors = test_module.create_test(project, test_name)
     assert errors == ['A test with that name already exists']