예제 #1
0
 def execute(self, variables):
     # 如果没有设置前置或后置则无需执行
     if self.expr_lines:
         for expr_line in self.expr_lines:
             if "=" not in expr_line:
                 print YamlHelper.var_expr(variables, expr_line.strip())
             else:
                 self.add_var(variables, expr_line)
예제 #2
0
    def __init__(self, yml_file_path):
        api = self.api_content(yml_file_path)

        # if api.has_key(YamlTag.Body) and api.has_key(YamlTag.Procedure):
        #     print "不允许同时配置Body和Procedure标签"
        #     return None

        # Yaml 文件名及输出结果的路径
        file_name = os.path.split(yml_file_path)[1]
        root_dir = YamlHelper.same_prefix(os.path.abspath(yml_file_path), os.getcwd())
        self.interface_name = file_name[0 : file_name.index(".")]
        self.response_file = "{0}/response/{1}.yml".format(root_dir, self.interface_name)

        # Yaml配置文件定义的全局变量,对应globa标签下的变量
        self.variables = YamlVariables(api[YamlTag.Global])

        # Yaml请求实例
        self.request = YamlHttpRequest(
            YamlHelper.var_expr(self.variables.variables, YamlHelper.yaml_tag_value(api, YamlTag.Url)),
            YamlHelper.dict_var_expr(self.variables.variables, YamlHelper.yaml_tag_value(api, YamlTag.Auth)),
            YamlHelper.dict_var_expr(self.variables.variables, YamlHelper.yaml_tag_value(api, YamlTag.Header)),
            YamlHelper.var_expr(self.variables.variables, YamlHelper.yaml_tag_value(api, YamlTag.Method)),
            YamlHelper.var_expr(self.variables.variables, YamlHelper.yaml_tag_value(api, YamlTag.Action)),
        )

        print "全局变量列表: "
        for key in self.variables.variables:
            print "key = {0} \t\t value = {1}".format(key, self.variables.variables[key])

        # 前置操作
        self.precondition = YamlStep(YamlHelper.yaml_tag_value(api, YamlTag.Precondition))

        # 请求的主体,用来进行请求参数的组合
        self.body = YamlHelper.yaml_tag_value(api, YamlTag.Body)

        # 执行过程 -- 为避免与body重复,可考虑不要该标签
        # self.procedure = YamlStep()

        # 后置操作
        self.postcondition = YamlStep(YamlHelper.yaml_tag_value(api, YamlTag.Postcondition))

        # 参数数据组合
        self.data_combination = self.data_combine()
예제 #3
0
 def add_var(self, variables, variable_line):
     variable_name = variable_line.split("=")[0].strip()
     variables[variable_name] = YamlHelper.var_expr(variables, variable_line.split("=")[1].strip())