Skip to content
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

Weird behaviour during comparision of values #294

Open
oursinyi opened this issue Dec 6, 2018 · 1 comment
Open

Weird behaviour during comparision of values #294

oursinyi opened this issue Dec 6, 2018 · 1 comment

Comments

@oursinyi
Copy link

oursinyi commented Dec 6, 2018

@svanoort

Hi There,

I faced with weird behaviour when I tried co compare two values. The testset:

- config:
   - testset: "User related default tests"
   - generators:
        - "id": {'type': "random_text", 'length': "20", 'character_set': "alphanumeric"}

- test:
   - name: "login"
   - group: "cust_login"
   - url: "/authenticate/login"
   - method: "POST"
   - headers: {template: {'Authorization': 'Basic ABCDEFG=='}}
   - expected_status: [201]
   - extract_binds:
       - "token": {"jsonpath_mini": "session_id"}

- test:
   - name: "user list"
   - group: "user_list"
   - url: "/users/list/"
   - method: "GET"
   - headers: {template: {'Authorization': "OAuth $token"}}
   - expected_status: [200]
   - extract_binds:
       - "totalnums": {"jsonpath_mini": "total_num"}
       - "name": {"jmespath": "users[0].username"}
   
{ more tests here (user creation) }

- test:
   - name: "user list"
   - group: "user_list"
   - url: "/users/list/"
   - method: "GET"
   - headers: {template: {'Authorization': "OAuth $token"}}
   - expected_status: [200]
   - validators:
       - compare: {jsonpath_mini: "total_num", comparator: "gt", expected: {template: "$totalnums"}}

{ more tests here (user deletion) }

- test:
   - name: "user list"
   - group: "user_list"
   - url: "/users/list/"
   - method: "GET"
   - headers: {template: {'Authorization': "OAuth $token"}}
   - expected_status: [200]
   - validators:
       - compare: {jsonpath_mini: "total_num", comparator: "eq", expected: {template: "$totalnums"}}

The first comparation's result:
ERROR:Test Failure, failure type: Validator Failed, Reason: Comparison failed, evaluating gt(8, 7) returned False

And the second comparision's result:
ERROR:Test Failure, failure type: Validator Failed, Reason: Comparison failed, evaluating eq(7, 7) returned False

I am not sure why get False if 8 grater than 7 and 7 equal with 7? (These data are from same field, which means these are same type)

Thanks in advance!

@kovacsbalu
Copy link

kovacsbalu commented Dec 11, 2018

Hi @oursinyi,
you can create a custom_comparators.py and use with --import_extensions "custom_comparators"

COMPARATORS = {
    'int_lt': lambda a, b: int(a) < int(b),
    'int_gt': lambda a, b: int(a) > int(b),
    'int_eq': lambda a, b: int(a) == int(b)
}

Now you can comapre json data and template variable as integer.
- compare: {jsonpath_mini: "total_num", comparator: "int_gt", expected: {template: "$totalnums"}}

Pacsi ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants