Пример #1
0
 def test_edit_test_explicit_action_import(self, project_function,
                                           test_utils):
     _, project = project_function.activate()
     test_name = test_utils.create_random_test(project)
     settings_manager.save_project_settings(
         project, '{"implicit_actions_import": false}')
     test_module.edit_test(project,
                           test_name,
                           description='',
                           pages=[],
                           steps=EMPTY_STEPS,
                           test_data=[],
                           tags=[])
     expected = ('from golem import actions\n\n\n'
                 'description = \'\'\n\n'
                 'tags = []\n\n'
                 'pages = []\n\n\n'
                 'def setup(data):\n'
                 '    pass\n\n\n'
                 'def test(data):\n'
                 '    pass\n\n\n'
                 'def teardown(data):\n'
                 '    pass\n')
     with open(Test(project, test_name).path) as f:
         assert f.read() == expected
Пример #2
0
 def test_test_components_skip(self, project_session, test_utils):
     _, project = project_session.activate()
     test_name = test_utils.create_random_test(project)
     # default / empty skip is False
     assert Test(project, test_name).components['skip'] is False
     # skip is True
     test_module.edit_test(project,
                           test_name,
                           description='',
                           pages=[],
                           steps=EMPTY_STEPS,
                           test_data=[],
                           tags=[],
                           skip=True)
     assert Test(project, test_name).components['skip'] is True
     # skip is string
     test_module.edit_test(project,
                           test_name,
                           description='',
                           pages=[],
                           steps=EMPTY_STEPS,
                           test_data=[],
                           tags=[],
                           skip='please skip')
     assert Test(project, test_name).components['skip'] == 'please skip'
Пример #3
0
 def test_edit_test_skip(self, project_session, test_utils):
     _, project = project_session.activate()
     test_name = test_utils.create_random_test(project)
     test_module.edit_test(project,
                           test_name,
                           description='',
                           pages=[],
                           steps=EMPTY_STEPS,
                           test_data=EMPTY_TEST_DATA,
                           tags=[],
                           skip=True)
     path = Test(project, test_name).path
     expected = ('\n'
                 'skip = True\n\n\n'
                 'def test_name(data):\n'
                 '    pass\n')
     with open(path) as f:
         assert f.read() == expected
     # skip is string
     test_module.edit_test(project,
                           test_name,
                           description='',
                           pages=[],
                           steps=EMPTY_STEPS,
                           test_data=EMPTY_TEST_DATA,
                           tags=[],
                           skip='please skip this')
     path = Test(project, test_name).path
     expected = ('\n'
                 'skip = \'please skip this\'\n\n\n'
                 'def test_name(data):\n'
                 '    pass\n')
     with open(path) as f:
         assert f.read() == expected
Пример #4
0
 def test_edit_test_explicit_page_import(self, project_function,
                                         test_utils):
     _, project = project_function.activate()
     test_name = test_utils.create_random_test(project)
     pages = ['page1', 'module.page2']
     settings_manager.save_project_settings(
         project, '{"implicit_page_import": false}')
     test_module.edit_test(project,
                           test_name,
                           description='',
                           pages=pages,
                           steps=EMPTY_STEPS,
                           test_data=[],
                           tags=[])
     expected = ('from projects.{}.pages import page1\n'
                 'from projects.{}.pages.module import page2\n'
                 '\n\n'
                 'description = \'\'\n'
                 '\n'
                 'tags = []\n'
                 '\n\n'
                 'def setup(data):\n'
                 '    pass\n'
                 '\n\n'
                 'def test(data):\n'
                 '    pass\n'
                 '\n\n'
                 'def teardown(data):\n'
                 '    pass\n'.format(project, project))
     with open(Test(project, test_name).path) as f:
         assert f.read() == expected
Пример #5
0
 def test_edit_test_data_csv(self, project_function, test_utils):
     _, project = project_function.activate()
     test_name = test_utils.create_random_test(project)
     description = 'description'
     pages = []
     test_steps = {
         'hooks': {},
         'tests': {
             'test': [{
                 'type': 'function-call',
                 'action': 'send_keys',
                 'parameters': ['elem2', 'keys']
             }]
         }
     }
     data = {'csv': [{'key': 'value'}], 'json': None, 'internal': None}
     test_module.edit_test(project, test_name, description, pages,
                           test_steps, data, [])
     expected = ('\n'
                 'description = \'description\'\n'
                 '\n'
                 '\n'
                 'def test(data):\n'
                 '    send_keys(elem2, keys)\n')
     with open(Test(project, test_name).path) as f:
         assert f.read() == expected
     expected = ('key\n' 'value\n')
     with open(test_data_module.csv_file_path(project, test_name)) as f:
         assert f.read() == expected
Пример #6
0
def test_save():
    project = request.json['project']
    test_name = request.json['testName']
    description = request.json['description']
    pages = request.json['pages']
    test_data_content = request.json['testData']
    test_steps = request.json['steps']
    tags = request.json['tags']
    skip = request.json['skip']
    _verify_permissions(Permissions.STANDARD, project)
    test_module.edit_test(project, test_name, description, pages, test_steps,
                          test_data_content, tags, skip)
    return jsonify('test-saved')
Пример #7
0
 def test_edit_test_data_infile(self, project_function, test_utils):
     _, project = project_function.activate()
     test_name = test_utils.create_random_test(project)
     description = 'description'
     pages = ['page1', 'page2']
     test_steps = {
         'setup': [{
             'type': 'function-call',
             'action': 'click',
             'parameters': ['elem1']
         }],
         'test': [{
             'type': 'function-call',
             'action': 'send_keys',
             'parameters': ['elem2', 'keys']
         }],
         'teardown': []
     }
     data = [{'key': '\'value\''}]
     settings_manager.save_project_settings(project,
                                            '{"test_data": "infile"}')
     test_module.edit_test(project, test_name, description, pages,
                           test_steps, data, [])
     expected = ('\n'
                 'description = \'description\'\n'
                 '\n'
                 'tags = []\n'
                 '\n'
                 'pages = [\'page1\',\n'
                 '         \'page2\']\n'
                 '\n'
                 'data = [\n'
                 '    {\n'
                 '        \'key\': \'value\',\n'
                 '    },\n'
                 ']\n'
                 '\n\n'
                 'def setup(data):\n'
                 '    click(elem1)\n'
                 '\n\n'
                 'def test(data):\n'
                 '    send_keys(elem2, keys)\n'
                 '\n\n'
                 'def teardown(data):\n'
                 '    pass\n')
     with open(Test(project, test_name).path) as f:
         assert f.read() == expected
Пример #8
0
 def test_edit_test_data_internal(self, project_function, test_utils):
     _, project = project_function.activate()
     test_name = test_utils.create_random_test(project)
     description = 'description'
     pages = ['page1', 'page2']
     test_steps = {
         'hooks': {
             'before_test': [{
                 'type': 'function-call',
                 'action': 'click',
                 'parameters': ['elem1']
             }]
         },
         'tests': {
             'test_one': [{
                 'type': 'function-call',
                 'action': 'send_keys',
                 'parameters': ['elem2', 'keys']
             }]
         },
         'teardown': []
     }
     data = {
         'csv': None,
         'json': None,
         'internal': "data = [{'key': 'value'}]"
     }
     test_module.edit_test(project, test_name, description, pages,
                           test_steps, data, [])
     expected = ('\n'
                 'description = \'description\'\n'
                 '\n'
                 'pages = [\'page1\',\n'
                 '         \'page2\']\n'
                 '\n'
                 'data = [{\'key\': \'value\'}]\n'
                 '\n\n'
                 'def before_test(data):\n'
                 '    click(elem1)\n'
                 '\n\n'
                 'def test_one(data):\n'
                 '    send_keys(elem2, keys)\n')
     with open(Test(project, test_name).path) as f:
         assert f.read() == expected
Пример #9
0
def test_save():
    project = request.json['project']
    test_name = request.json['testName']
    description = request.json['description']
    pages = request.json['pages']
    test_data = request.json['testData']
    test_steps = request.json['steps']
    tags = request.json['tags']
    skip = request.json['skip']
    errors = []
    _verify_permissions(Permissions.STANDARD, project)
    if test_data['internal'] is not None:
        errors.extend(test_data_module.validate_internal_data(test_data['internal']))
    if test_data['json'] is not None and test_data['json'].strip():
        errors.extend(utils.json_parse_error(test_data['json']))
    if not errors:
        test_module.edit_test(project, test_name, description, pages, test_steps,
                              test_data, tags, skip)
    return jsonify({'errors': errors})
Пример #10
0
 def test_edit_test_data_csv(self, project_function, test_utils):
     _, project = project_function.activate()
     test_name = test_utils.create_random_test(project)
     description = 'description'
     pages = []
     test_steps = {
         'setup': [],
         'test': [
             {'type': 'function-call', 'action': 'send_keys', 'parameters': ['elem2', 'keys']}
         ],
         'teardown': []
     }
     data = [{
         'key': '\'value\''
     }]
     settings_manager.save_project_settings(project, '{"test_data": "csv"}')
     test_module.edit_test(project, test_name, description, pages, test_steps, data, [])
     expected = (
         '\n'
         'description = \'description\'\n'
         '\n'
         'tags = []\n'
         '\n'
         'pages = []\n'
         '\n\n'
         'def setup(data):\n'
         '    pass\n'
         '\n\n'
         'def test(data):\n'
         '    send_keys(elem2, keys)\n'
         '\n\n'
         'def teardown(data):\n'
         '    pass\n')
     with open(Test(project, test_name).path) as f:
         assert f.read() == expected
     data_path = os.path.join(Project(project).test_directory_path,
                              '{}.csv'.format(test_name))
     expected = ('key\n'
                 '\'value\'\n')
     with open(data_path) as f:
         assert f.read() == expected