Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_as_strategy(swagger_20):
endpoint = swagger_20["/v1/users"]["GET"]
strategy = endpoint.as_strategy()
assert isinstance(strategy, st.SearchStrategy)
assert strategy.example() == Case(endpoint)
def test_display_errors(swagger_20, capsys, results_set):
# Given two test results - success and error
endpoint = models.Endpoint("/api/error", "GET", {}, swagger_20)
error = models.TestResult(endpoint, seed=123)
error.add_error(ConnectionError("Connection refused!"), models.Case(endpoint, query={"a": 1}))
results_set.append(error)
# When the errors are displayed
default.display_errors(results_set)
out = capsys.readouterr().out.strip()
# Then section title is displayed
assert " ERRORS " in out
# And endpoint with an error is displayed as a subsection
assert " GET: /api/error " in out
# And the error itself is displayed
assert "ConnectionError: Connection refused!" in out
# And the example is displayed
assert "Query : {'a': 1}" in out
assert "Or add this option to your command line parameters: --hypothesis-seed=123" in out
"attribute, expected", ((models.Case.__attrs_attrs__[3], "Cookies"), (models.Case.__attrs_attrs__[4], "Query"))
)
def test_make_verbose_name(attribute, expected):
assert default.make_verbose_name(attribute) == expected
(Case(ENDPOINT, body={"test": 1}), "requests.get('http://example.com/api/success', json={'test': 1})"),
(Case(ENDPOINT), "requests.get('http://example.com/api/success')"),
(Case(ENDPOINT, query={"a": 1}), "requests.get('http://example.com/api/success', params={'a': 1})"),
),
)
def test_get_code_to_reproduce(case, expected):
assert case.get_code_to_reproduce() == expected
(Case(ENDPOINT, query={"a": 1}), "requests.get('http://example.com/api/success', params={'a': 1})"),
),
)
def test_get_code_to_reproduce(case, expected):
assert case.get_code_to_reproduce() == expected
def test_call(override, base_url, swagger_20):
endpoint = Endpoint("/api/success", "GET", {}, swagger_20)
kwargs = {"endpoint": endpoint}
if override:
case = Case(**kwargs)
response = case.call(base_url)
else:
case = Case(**kwargs)
endpoint.base_url = base_url
response = case.call()
assert response.status_code == 200
assert response.json() == {"success": True}
with pytest.warns(None) as records:
del response
assert not records