def test_bugfix_type_match(self): testcase_file_path = os.path.join(os.getcwd(), 'tests/data/test_bugfix.yml') testcases = loader.load_file(testcase_file_path) test = testcases[2]["test"] self.test_runner.run_test(test)
def test_load_testcase(self): raw_testcase = loader.load_file("tests/testcases/smoketest.yml") testcase = loader._load_testcase(raw_testcase, self.project_mapping) self.assertEqual(testcase["config"]["name"], "smoketest") self.assertIn("device_sn", testcase["config"]["variables"][0]) self.assertEqual(len(testcase["teststeps"]), 8) self.assertEqual(testcase["teststeps"][0]["name"], "get token")
def test_run_single_testcase(self): testcase_file_path_list = [ os.path.join( os.getcwd(), 'tests/data/demo_testcase_hardcode.yml'), os.path.join( os.getcwd(), 'tests/data/demo_testcase_hardcode.json') ] for testcase_file_path in testcase_file_path_list: testcases = loader.load_file(testcase_file_path) config_dict = { "variables": self.debugtalk_module["variables"], "functions": self.debugtalk_module["functions"] } test_runner = runner.Runner(config_dict) test = testcases[0]["test"] test_runner.run_test(test) test = testcases[1]["test"] test_runner.run_test(test) test = testcases[2]["test"] test_runner.run_test(test)
def setUp(self): loader.load_project_tests(os.path.join(os.getcwd(), "tests")) self.debugtalk_module = loader.project_mapping["debugtalk"] self.context = context.Context(self.debugtalk_module["variables"], self.debugtalk_module["functions"]) testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_binds.yml') self.testcases = loader.load_file(testcase_file_path)
def test_bugfix_type_match(self): testcase_file_path = os.path.join(os.getcwd(), 'tests/data/test_bugfix.yml') testcases = loader.load_file(testcase_file_path) config_dict = {"path": testcase_file_path} self.test_runner.init_config(config_dict, "testset") test = testcases[2]["test"] self.test_runner.run_test(test)
def setup_method(self): loader.load_project_tests(os.path.join(os.getcwd(), 'tests')) self.confcustom_module = loader.project_mapping['confcustom'] self.context = context.Context(self.confcustom_module['variables'], self.confcustom_module['functions']) testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_binds.yml') self.testcases = loader.load_file(testcase_file_path)
def parameterize(self, csv_file_name, fetch_method="Sequential"): parameter_file_path = os.path.join(os.path.dirname(self.file_path), "{}".format(csv_file_name)) csv_content_list = loader.load_file(parameter_file_path) if fetch_method.lower() == "random": random.shuffle(csv_content_list) return csv_content_list
def test_load_json_testcases(self): testcases_file_path = os.path.join(os.getcwd(), 'tests', 'data', 'demo_testset_hardcode.json') testcases = loader.load_file(testcases_file_path) assert len(testcases) == 3 test = testcases[0]['test'] assert 'name' in test assert 'request' in test assert 'url' in test['request'] assert 'method' in test['request']
def test_load_csv_file_one_parameter(self): csv_file_path = os.path.join(os.getcwd(), 'tests/data/user_agent.csv') csv_content = loader.load_file(csv_file_path) self.assertEqual(csv_content, [{ 'user_agent': 'iOS/10.1' }, { 'user_agent': 'iOS/10.2' }, { 'user_agent': 'iOS/10.3' }])
def test_load_yaml_testcases(self): testcase_file_path = os.path.join( os.getcwd(), 'tests/data/demo_testcase_hardcode.yml') testcases = loader.load_file(testcase_file_path) self.assertEqual(len(testcases), 3) test = testcases[0]["test"] self.assertIn('name', test) self.assertIn('request', test) self.assertIn('url', test['request']) self.assertIn('method', test['request'])
def test_load_csv_file_one_parameter(self): csv_file_path = os.path.join(os.getcwd(), 'tests', 'data', 'user_agent.csv') csv_content = loader.load_file(csv_file_path) assert csv_content == [{ 'user_agent': 'ios/10.1' }, { 'user_agent': 'ios/10.2' }, { 'user_agent': 'ios/10.3' }]
def test_load_csv_file_multiple_parameters(self): csv_file_path = os.path.join( os.getcwd(), 'tests/data/account.csv') csv_content = loader.load_file(csv_file_path) self.assertEqual( csv_content, [ {'username': '******', 'password': '******'}, {'username': '******', 'password': '******'}, {'username': '******', 'password': '******'} ] )
def test_run_single_testcase(self): for testcase_file_path in self.testcase_file_path_list: testcases = loader.load_file(testcase_file_path) config_dict = {"path": testcase_file_path} self.test_runner.init_config(config_dict, "testset") test = testcases[0]["test"] self.test_runner.run_test(test) test = testcases[1]["test"] self.test_runner.run_test(test) test = testcases[2]["test"] self.test_runner.run_test(test)
def load_csv_list(self, csv_file_name, fetch_method="Sequential"): """ locate csv file and load csv content. Args: csv_file_name (str): csv file name fetch_method (str): fetch data method, defaults to Sequential. If set to "random", csv data list will be reordered in random. Returns: list: csv data list """ csv_file_path = loader.locate_file(self.file_path, csv_file_name) csv_content_list = loader.load_file(csv_file_path) if fetch_method.lower() == "random": random.shuffle(csv_content_list) return csv_content_list
def test_load_testcases_bad_filepath(self): testcases_bad_file_path = os.path.join(os.getcwd(), 'tests', 'data', 'demo') with pytest.raises(exceptions.FileNotFound): loader.load_file(testcases_bad_file_path)
def setUp(self): self.context = context.Context() testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_binds.yml') self.testcases = loader.load_file(testcase_file_path)
def test_load_testcases_bad_filepath(self): testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo') with self.assertRaises(exceptions.FileNotFound): loader.load_file(testcase_file_path)