Ejemplo n.º 1
0
def make_testcase(testcase_path: str) -> Union[str, None]:
    logger.info(f"start to make testcase: {testcase_path}")
    try:
        testcase, _ = load_testcase_file(testcase_path)
    except TestCaseFormatError:
        return None

    template = jinja2.Template(__TMPL__)

    testcase_python_path, name_in_title_case = convert_testcase_path(testcase_path)

    config = testcase["config"]
    config["path"] = testcase_python_path
    data = {
        "testcase_path": testcase_path,
        "class_name": f"TestCase{name_in_title_case}",
        "config": config,
        "teststeps": testcase["teststeps"],
    }
    content = template.render(data)

    with open(testcase_python_path, "w") as f:
        f.write(content)

    logger.info(f"generated testcase: {testcase_python_path}")
    return testcase_python_path
Ejemplo n.º 2
0
def make_testcase(testcase_path: str) -> Union[str, None]:
    logger.info(f"start to make testcase: {testcase_path}")
    try:
        testcase, _ = load_testcase_file(testcase_path)
    except TestCaseFormatError:
        return None

    template = jinja2.Template(__TMPL__)

    raw_file_name, _ = os.path.splitext(os.path.basename(testcase_path))
    # convert title case, e.g. request_with_variables => RequestWithVariables
    name_in_title_case = raw_file_name.title().replace("_", "")

    testcase_dir = os.path.dirname(testcase_path)
    testcase_python_path = os.path.join(testcase_dir,
                                        f"{raw_file_name}_test.py")

    config = testcase["config"]
    config["path"] = testcase_python_path
    data = {
        "class_name": f"TestCase{name_in_title_case}",
        "config": config,
        "teststeps": testcase["teststeps"],
    }
    content = template.render(data)

    with open(testcase_python_path, "w") as f:
        f.write(content)

    logger.info(f"generated testcase: {testcase_python_path}")
    return testcase_python_path
Ejemplo n.º 3
0
 def test_load_testcase_file(self):
     path = "examples/postman_echo/request_methods/request_with_variables.yml"
     testcase_json, testcase_obj = loader.load_testcase_file(path)
     self.assertEqual(testcase_json["config"]["name"],
                      "request methods testcase with variables")
     self.assertEqual(testcase_obj.config.name,
                      "request methods testcase with variables")
     self.assertEqual(len(testcase_json["teststeps"]), 3)
     self.assertEqual(len(testcase_obj.teststeps), 3)
Ejemplo n.º 4
0
    def run_path(self, path: Text) -> "HttpRunner":
        if not os.path.isfile(path):
            raise exceptions.ParamsError(f"Invalid testcase path: {path}")

        _, testcase_obj = load_testcase_file(path)
        return self.run(testcase_obj)
Ejemplo n.º 5
0
 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_testcase_file(testcase_file_path)