Skip to content

Commit

Permalink
fix: Pass data_generation_method to GraphQLCase
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Oct 17, 2021
1 parent d31b017 commit b765e8f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Changelog
- Improve reporting of ``jsonschema`` errors which are caused by non-string object keys.
- Store ``data_generation_method`` in ```BeforeExecution``.

**Fixed**

- Pass ``data_generation_method`` to ``Case`` for GraphQL schemas.

`3.10.1`_ - 2021-10-04
----------------------

Expand Down
2 changes: 1 addition & 1 deletion src/schemathesis/specs/graphql/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def get_case_strategy(
hooks: Optional[HookDispatcher] = None,
data_generation_method: DataGenerationMethod = DataGenerationMethod.default(),
) -> SearchStrategy:
constructor = partial(GraphQLCase, operation=operation)
constructor = partial(GraphQLCase, operation=operation, data_generation_method=data_generation_method)
return st.builds(constructor, body=gql_st.query(self.client_schema, fields=[operation.verbose_name]))

def get_strategies_from_examples(self, operation: APIOperation) -> List[SearchStrategy[Case]]:
Expand Down
15 changes: 14 additions & 1 deletion test/cli/test_targeted.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def new_target(testdir, cli):
@schemathesis.register_target
def new_target(context) -> float:
click.echo("NEW TARGET IS CALLED")
assert context.case.data_generation_method is not None, "Empty data_generation_method"
return float(len(context.response.content))
"""
)
Expand All @@ -28,7 +29,7 @@ def new_target(context) -> float:

@pytest.mark.usefixtures("new_target")
@pytest.mark.operations("success")
def test_custom_target(testdir, cli, new_target, openapi3_schema_url):
def test_custom_target(cli, new_target, openapi3_schema_url):
# When `--pre-run` hook is passed to the CLI call
# And it contains registering a new target
result = cli.main("--pre-run", new_target.purebasename, "run", "-t", "new_target", openapi3_schema_url)
Expand All @@ -38,6 +39,18 @@ def test_custom_target(testdir, cli, new_target, openapi3_schema_url):
assert "NEW TARGET IS CALLED" in result.stdout


@pytest.mark.usefixtures("new_target")
@pytest.mark.operations("success")
def test_custom_target_graphql(cli, new_target, graphql_url):
# When `--pre-run` hook is passed to the CLI call
# And it contains registering a new target
result = cli.main("--pre-run", new_target.purebasename, "run", "-t", "new_target", graphql_url)
# Then the test run should be successful
assert result.exit_code == ExitCode.OK, result.stdout
# And the specified target is called
assert "NEW TARGET IS CALLED" in result.stdout


@pytest.fixture
def target_function():
@schemathesis.register_target
Expand Down

0 comments on commit b765e8f

Please sign in to comment.