Skip to content

Commit

Permalink
chore: Added contains method to ParameterSet for easier parameter…
Browse files Browse the repository at this point in the history
… checks in hooks

Ref: #1789
  • Loading branch information
Stranger6667 committed Oct 13, 2023
1 parent 0db1b74 commit d761ece
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Changelog
- Support for ``body`` hooks in GraphQL schemas, enabling custom filtering or modification of queries and mutations. `#1464`_
- New ``filter_operations`` hook to conditionally include or exclude specific API operations from being tested.
- Introduced a new CLI option ``--experimental=openapi-3.1`` for experimental support of OpenAPI 3.1. This enables compatible JSON Schema validation for responses, while data generation remains OpenAPI 3.0-compatible. `#1820`_
- Added ``contains`` method to ``ParameterSet`` for easier parameter checks in hooks. `#1789`_

**Note**: Experimental features can change or be removed in any minor version release.

Expand Down Expand Up @@ -3463,6 +3464,7 @@ Deprecated
.. _#1802: https://github.com/schemathesis/schemathesis/issues/1802
.. _#1801: https://github.com/schemathesis/schemathesis/issues/1801
.. _#1797: https://github.com/schemathesis/schemathesis/issues/1797
.. _#1789: https://github.com/schemathesis/schemathesis/issues/1789
.. _#1788: https://github.com/schemathesis/schemathesis/issues/1788
.. _#1781: https://github.com/schemathesis/schemathesis/issues/1781
.. _#1780: https://github.com/schemathesis/schemathesis/issues/1780
Expand Down
3 changes: 3 additions & 0 deletions src/schemathesis/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def get(self, name: str) -> Optional[P]:
return parameter
return None

def contains(self, name: str) -> bool:
return self.get(name) is not None

@property
def example(self) -> Dict[str, Any]:
"""Composite example gathered from individual parameters."""
Expand Down
10 changes: 10 additions & 0 deletions test/specs/openapi/parameters/test_simple_payloads.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for behavior not specific to forms."""
import pytest

import schemathesis
from schemathesis.parameters import PayloadAlternatives
from schemathesis.specs.openapi.parameters import OpenAPI20Body, OpenAPI30Body

Expand Down Expand Up @@ -62,3 +63,12 @@ def test_payload_open_api_3(media_types, assert_parameters, make_openapi_3_schem
# In this case they are the same
[user_jsonschema] * len(media_types),
)


def test_parameter_set_get(make_openapi_3_schema):
header = {"in": "header", "name": "id", "required": True, "schema": {}}
raw_schema = make_openapi_3_schema(parameters=[header])
schema = schemathesis.from_dict(raw_schema)
headers = schema["/users"]["POST"].headers
assert headers.contains("id")
assert not headers.contains("foo")

0 comments on commit d761ece

Please sign in to comment.