1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
import pytest
from ninja import NinjaAPI, Query
from ninja.utils import contribute_operation_args, replace_path_param_notation
@pytest.mark.parametrize(
"input,expected_output",
[
("abc/{def}", "abc/<def>"),
("abc/<def>", "abc/<def>"),
("abc", "abc"),
("<abc>", "<abc>"),
("{abc}", "<abc>"),
("{abc}/{def}", "<abc>/<def>"),
],
)
def test_replace_path_param_notation(input, expected_output):
assert replace_path_param_notation(input) == expected_output
def test_contribute_operation_args():
def some_func():
pass
contribute_operation_args(some_func, "arg1", str, Query(...))
contribute_operation_args(some_func, "arg2", int, Query(...))
api = NinjaAPI()
api.get("/test")(some_func)
schema = api.get_openapi_schema()
assert schema["paths"]["/api/test"]["get"]["parameters"] == [
{
"in": "query",
"name": "arg1",
"schema": {"title": "Arg1", "type": "string"},
"required": True,
},
{
"in": "query",
"name": "arg2",
"schema": {"title": "Arg2", "type": "integer"},
"required": True,
},
]
|