Skip to content

Commit

Permalink
Add step to assert a field is not present (#1901)
Browse files Browse the repository at this point in the history
* Add step to assert a field is not present

* Fix method naming

* Fix method naming

---------

Co-authored-by: skarimo <40482491+skarimo@users.noreply.github.com>
  • Loading branch information
antonio-ramadas-dd and skarimo committed Mar 11, 2024
1 parent 8228e49 commit fe7a9a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .generator/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ def expect_response_has_field(context, response_path, field):
"""Check that a response has field."""


@then(parsers.parse('the response "{response_path}" does not have field "{field}"'))
def expect_response_does_not_have_field(context, response_path, field):
"""Check that a response path does not have field."""


@then(parsers.parse('the response "{response_path}" has item with field "{key_path}" with value {value}'))
def expect_array_contains_object(context, response_path, key_path, value):
"""Check that a response attribute contains an object with the specified key and value."""
Expand Down
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,13 @@ def expect_response_has_field(context, response_path, field):
assert field in response_value


@then(parsers.parse('the response "{response_path}" does not have "{field}"'))
def expect_response_does_not_have_field(context, response_path, field):
"""Check that a response path does not have field."""
response_value = glom(context["api_request"]["response"][0], response_path)
assert field not in response_value


@then(parsers.parse('the response "{response_path}" has item with field "{key_path}" with value {value}'))
def expect_array_contains_object(context, response_path, key_path, value):
from glom.core import PathAccessError
Expand Down

0 comments on commit fe7a9a6

Please sign in to comment.