New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate中,expected字段支持变量引用 #52

Closed
testwangchao opened this Issue Nov 10, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@testwangchao

testwangchao commented Nov 10, 2017

接口response内,会返回数据库内的自增ID。ID校验的时候,希望expected为参数化的值。

validate:
    - {"check": "content.data.table_list.0.id", "expected": $id}
@debugtalk

This comment has been minimized.

Show comment
Hide comment
@debugtalk

debugtalk Nov 10, 2017

Collaborator

@testwangchao 当前是不支持的。初步想了下,这个功能是可以实现的,我后期实现下。

Collaborator

debugtalk commented Nov 10, 2017

@testwangchao 当前是不支持的。初步想了下,这个功能是可以实现的,我后期实现下。

@debugtalk debugtalk changed the title from validate内,check和expected字段的值不支持变量和函数绑定吗? to validate中,expected字段支持变量引用 Nov 10, 2017

@debugtalk debugtalk added the TODO label Nov 10, 2017

@testwangchao

This comment has been minimized.

Show comment
Hide comment
@testwangchao

testwangchao Nov 16, 2017

根据源码提供的方法,实现了expect字段支持自定义函数和变量的绑定。
runner内expect字段进行替换重新生成一个列表:

validators = testcase_dict.get("validate") \
                     or testcase_dict.get("validators", [])
parse_validators = []
for validator in validators:
    parse_validators.append(self.context.parse_validators(validator))
try:
    resp_obj.validate(parse_validators, self.context.get_testcase_variables_mapping())

context内加一个方法,进行对expect字段的值进行解析:

def parse_validators(self, validators):
        return self.testcase_parser.parse_content_with_bindings(validators)

testwangchao commented Nov 16, 2017

根据源码提供的方法,实现了expect字段支持自定义函数和变量的绑定。
runner内expect字段进行替换重新生成一个列表:

validators = testcase_dict.get("validate") \
                     or testcase_dict.get("validators", [])
parse_validators = []
for validator in validators:
    parse_validators.append(self.context.parse_validators(validator))
try:
    resp_obj.validate(parse_validators, self.context.get_testcase_variables_mapping())

context内加一个方法,进行对expect字段的值进行解析:

def parse_validators(self, validators):
        return self.testcase_parser.parse_content_with_bindings(validators)
@debugtalk

This comment has been minimized.

Show comment
Hide comment
@debugtalk

debugtalk Dec 12, 2017

Collaborator

@testwangchao 已经支持在validator的expect字段引用变量。

Collaborator

debugtalk commented Dec 12, 2017

@testwangchao 已经支持在validator的expect字段引用变量。

@debugtalk debugtalk added enhancement and removed TODO labels Dec 12, 2017

@debugtalk debugtalk closed this Jan 23, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment