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_default_strategies_bytes(swagger_20):
endpoint = make_endpoint(
swagger_20,
body={
"required": ["byte"],
"type": "object",
"additionalProperties": False,
"properties": {"byte": {"type": "string", "format": "byte"}},
},
)
result = get_case_strategy(endpoint).example()
assert isinstance(result.body["byte"], str)
b64decode(result.body["byte"])
def test_custom_strategies(swagger_20):
register_string_format("even_4_digits", strategies.from_regex(r"\A[0-9]{4}\Z").filter(lambda x: int(x) % 2 == 0))
endpoint = make_endpoint(
swagger_20,
query={
"required": ["id"],
"type": "object",
"additionalProperties": False,
"properties": {"id": {"type": "string", "format": "even_4_digits"}},
},
)
result = get_case_strategy(endpoint).example()
assert len(result.query["id"]) == 4
assert int(result.query["id"]) % 2 == 0
@given(case=get_case_strategy(endpoint))
def inner(case):
case.call()
def test_invalid_body_in_get(swagger_20):
endpoint = Endpoint(
path="/foo",
method="GET",
definition={},
schema=swagger_20,
body={"required": ["foo"], "type": "object", "properties": {"foo": {"type": "string"}}},
)
with pytest.raises(InvalidSchema, match=r"^Body parameters are defined for GET request.$"):
get_case_strategy(endpoint)
def test_default_strategies_binary(swagger_20):
endpoint = make_endpoint(
swagger_20,
form_data={
"required": ["file"],
"type": "object",
"additionalProperties": False,
"properties": {"file": {"type": "string", "format": "binary"}},
},
)
result = get_case_strategy(endpoint).example()
assert isinstance(result.form_data["file"], bytes)