Skip to content

Commit fe7a9a6

Browse files
Add step to assert a field is not present (#1901)
* Add step to assert a field is not present * Fix method naming * Fix method naming --------- Co-authored-by: skarimo <[email protected]>
1 parent 8228e49 commit fe7a9a6

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

.generator/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,11 @@ def expect_response_has_field(context, response_path, field):
538538
"""Check that a response has field."""
539539

540540

541+
@then(parsers.parse('the response "{response_path}" does not have field "{field}"'))
542+
def expect_response_does_not_have_field(context, response_path, field):
543+
"""Check that a response path does not have field."""
544+
545+
541546
@then(parsers.parse('the response "{response_path}" has item with field "{key_path}" with value {value}'))
542547
def expect_array_contains_object(context, response_path, key_path, value):
543548
"""Check that a response attribute contains an object with the specified key and value."""

tests/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,13 @@ def expect_response_has_field(context, response_path, field):
699699
assert field in response_value
700700

701701

702+
@then(parsers.parse('the response "{response_path}" does not have "{field}"'))
703+
def expect_response_does_not_have_field(context, response_path, field):
704+
"""Check that a response path does not have field."""
705+
response_value = glom(context["api_request"]["response"][0], response_path)
706+
assert field not in response_value
707+
708+
702709
@then(parsers.parse('the response "{response_path}" has item with field "{key_path}" with value {value}'))
703710
def expect_array_contains_object(context, response_path, key_path, value):
704711
from glom.core import PathAccessError

0 commit comments

Comments
 (0)