Skip to content

Commit

Permalink
fix: Missing app, location and hooks parameters in schema when …
Browse files Browse the repository at this point in the history
…used with `BaseSchema.parametrize`
  • Loading branch information
Stranger6667 committed Feb 10, 2020
1 parent 43404db commit 261c7b4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.rst
Expand Up @@ -10,6 +10,7 @@ Fixed
~~~~~

- Not copied ``validate_schema`` parameter in ``BaseSchema.parametrize``. Regression after implementing `#383`_
- Missing ``app``, ``location`` and ``hooks`` parameters in schema when used with ``BaseSchema.parametrize``. `#416`_

`0.24.2`_ - 2020-02-09
----------------------
Expand Down Expand Up @@ -707,6 +708,7 @@ Fixed
.. _0.3.0: https://github.com/kiwicom/schemathesis/compare/v0.2.0...v0.3.0
.. _0.2.0: https://github.com/kiwicom/schemathesis/compare/v0.1.0...v0.2.0

.. _#416: https://github.com/kiwicom/schemathesis/issues/416
.. _#412: https://github.com/kiwicom/schemathesis/issues/412
.. _#410: https://github.com/kiwicom/schemathesis/issues/410
.. _#407: https://github.com/kiwicom/schemathesis/issues/407
Expand Down
3 changes: 3 additions & 0 deletions src/schemathesis/schemas.py
Expand Up @@ -117,10 +117,13 @@ def parametrize(
def wrapper(func: Callable) -> Callable:
func._schemathesis_test = self.__class__( # type: ignore
self.raw_schema,
location=self.location,
base_url=self.base_url,
method=method,
endpoint=endpoint,
tag=tag,
app=self.app,
hooks=self.hooks,
validate_schema=validate_schema, # type: ignore
)
return func
Expand Down
38 changes: 38 additions & 0 deletions test/test_hooks.py
Expand Up @@ -62,3 +62,41 @@ def test(case):
assert int(case.query["id"]) % 2 == 0

test()


def test_hooks_via_parametrize(testdir):
testdir.make_test(
"""
def extra(st):
return st.filter(lambda x: x["id"].isdigit() and int(x["id"]) % 2 == 0)
schema.register_hook("query", extra)
@schema.parametrize()
@settings(max_examples=1)
def test(case):
assert case.endpoint.schema.get_hook("query") is extra
assert int(case.query["id"]) % 2 == 0
""",
schema={
"openapi": "3.0.2",
"info": {"title": "Test", "description": "Test", "version": "0.1.0"},
"paths": {
"/query": {
"get": {
"parameters": [
{
"name": "id",
"in": "query",
"required": True,
"schema": {"type": "string", "minLength": 1},
}
],
"responses": {"200": {"description": "OK"}},
}
}
},
},
)
result = testdir.runpytest()
result.assert_outcomes(passed=1)
27 changes: 27 additions & 0 deletions test/test_wsgi.py
Expand Up @@ -117,3 +117,30 @@ def test(case):
assert response.json == {"size": mocker.ANY}

test()


def test_app_with_parametrize(testdir):
# Regression - missed argument inside "wrapper" in `BaseSchema.parametrize`
testdir.makepyfile(
"""
import schemathesis
from test.apps._flask.app import app
from hypothesis import settings
schema = schemathesis.from_wsgi("/swagger.yaml", app)
called = False
@schema.parametrize()
@settings(max_examples=1)
def test(case):
global called
called = True
assert case.endpoint.schema.app is app
def test_two():
assert called
"""
)
result = testdir.runpytest()
result.assert_outcomes(passed=3)

0 comments on commit 261c7b4

Please sign in to comment.