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
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
def test_save_project_settings(self, project_class): _, project = project_class.activate() input_settings = ('// test\n' '{\n' '"test": "test"\n' '}') settings_manager.save_project_settings(project, input_settings) actual = settings_manager.get_project_settings_as_string(project) assert actual == input_settings
def test_save_project_settings(self, project_class): testdir = project_class.testdir project = project_class.name input_settings = ('// test\n' '{\n' '"test": "test"\n' '}') settings_manager.save_project_settings(testdir, project, input_settings) actual = settings_manager.get_project_settings_as_string( testdir, project) assert actual == input_settings
def save_settings(): if request.method == 'POST': projectname = request.json['project'] project_settings = request.json['projectSettings'] global_settings = request.json['globalSettings'] result = {'result': 'ok', 'errors': []} settings_manager.save_global_settings(root_path, global_settings) settings_manager.save_project_settings(root_path, projectname, project_settings) # re-read settings test_execution.settings = settings_manager.get_project_settings( root_path, projectname) return json.dumps(result)
def test_edit_test_code_csv_data(self, project_session, test_utils): _, project = project_session.activate() test_data = [{'key': "'value'"}] settings_manager.save_project_settings(project, '{"test_data": "csv"}') test_name = test_utils.create_random_test(project) test_module.edit_test_code(project, test_name, SAMPLE_TEST_CONTENT, test_data) path = test_module.Test(project, test_name).path with open(path) as f: assert f.read() == SAMPLE_TEST_CONTENT path = os.path.join(Project(project).test_directory_path, test_name + '.csv') expected = ('key\n' '\'value\'\n') with open(path) as f: assert f.read() == expected
def save_settings(): if request.method == 'POST': project = request.json['project'] project_settings = request.json['projectSettings'] global_settings = request.json['globalSettings'] result = { 'result': 'ok', 'errors': [] } settings_manager.save_global_settings(global_settings) session.settings = settings_manager.get_global_settings() if project_settings: settings_manager.save_project_settings(project, project_settings) # re-read project settings session.settings = settings_manager.get_project_settings(project) return json.dumps(result)
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
def test_save_test_case_data_infile(self, project_function): _, project = project_function.activate() test_case.new_test_case(project, ['a', 'b'], 'test_one') description = 'description' page_objects = ['page1', 'page2'] test_steps = { 'setup': [{ 'action': 'click', 'parameters': ['elem1'] }], 'test': [{ 'action': 'send_keys', 'parameters': ['elem2', 'keys'] }], 'teardown': [] } data = [{'key': '\'value\''}] settings_manager.save_project_settings(project, '{"test_data": "infile"}') test_case.save_test_case(project, 'a.b.test_one', description, page_objects, test_steps, data, []) path = os.path.join(project_function.path, 'tests', 'a', 'b', 'test_one.py') expected = ('\n' 'description = \'description\'\n' '\n' 'tags = []\n' '\n' 'pages = [\'page1\',\n' ' \'page2\']\n' '\n' 'data = [\n' ' {\n' ' \'key\': \'value\',\n' ' },\n' ']\n' '\n' 'def setup(data):\n' ' click(elem1)\n' '\n' 'def test(data):\n' ' send_keys(elem2, keys)\n' '\n' 'def teardown(data):\n' ' pass\n') with open(path) as f: assert f.read() == expected
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
def settings_project_save(): project = request.json['project'] settings = request.json['settings'] _verify_permissions(Permissions.ADMIN, project) settings_manager.save_project_settings(project, settings) return jsonify('settings-saved')