Skip to content

Commit

Permalink
test: Add CLI test for defining body in GET requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Jun 15, 2020
1 parent dfa1454 commit 9f144a0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/cli/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1356,3 +1356,13 @@ def test_openapi_links_multiple_threads(cli, cli_args, schema_url, recursion_lim
lines = result.stdout.splitlines()
assert result.exit_code == ExitCode.OK, result.stdout
assert lines[10] == expected


def test_get_request_with_body(testdir, cli, base_url, schema_with_get_payload):
schema_file = testdir.makefile(".yaml", schema=yaml.dump(schema_with_get_payload))
result = cli.run(
str(schema_file), f"--base-url={base_url}", "--hypothesis-max-examples=1", "--show-errors-tracebacks",
)
assert result.exit_code == ExitCode.TESTS_FAILED, result.stdout
lines = result.stdout.splitlines()
assert "schemathesis.exceptions.InvalidSchema: Body parameters are defined for GET request." in lines
29 changes: 29 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,35 @@ def fast_api_schema():
}


@pytest.fixture(scope="session")
def schema_with_get_payload():
return {
"openapi": "3.0.2",
"info": {"title": "Test", "description": "Test", "version": "0.1.0"},
"paths": {
"/users": {
"get": {
"requestBody": {
"required": True,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {"key": {"type": "string"}},
"required": ["key"],
}
}
},
},
"responses": {
"200": {"description": "OK", "content": {"application/json": {"schema": {"type": "object"}}}}
},
}
}
},
}


ROOT_SCHEMA = {
"openapi": "3.0.2",
"info": {"title": "Example API", "description": "An API to test Schemathesis", "version": "1.0.0"},
Expand Down
22 changes: 22 additions & 0 deletions test/test_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,25 @@ def test_(request, case):
r".*1 failed",
]
)


def test_get_request_with_body(testdir, schema_with_get_payload):
testdir.make_test(
"""
@pytest.fixture
def simple_schema():
return schema
lazy_schema = schemathesis.from_pytest_fixture("simple_schema")
@lazy_schema.parametrize()
def test_(request, case):
request.config.HYPOTHESIS_CASES += 1
""",
schema=schema_with_get_payload,
)
result = testdir.runpytest("-v")
result.assert_outcomes(passed=1, failed=1)
result.stdout.re_match_lines(
[r"E Failed: Body parameters are defined for GET request.",]
)

0 comments on commit 9f144a0

Please sign in to comment.