pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
1015 B
26 lines
1015 B
import pytest
|
|
from fastapi import Security
|
|
from fastapi.exceptions import FastAPIError
|
|
|
|
|
|
def test_pass_single_str():
|
|
with pytest.raises(FastAPIError) as exc_info:
|
|
Security(dependency=lambda: None, scopes="admin")
|
|
|
|
assert str(exc_info.value) == (
|
|
"Invalid value for `scopes` parameter in Security(). "
|
|
"Expected a sequence of strings (e.g., ['admin', 'user']), but received a single string. "
|
|
"Wrap it in a list: scopes=['your_scope'] instead of scopes='your_scope'."
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("value", ["function", "request"])
|
|
def test_pass_scope_instead_of_scopes(value: str):
|
|
with pytest.raises(FastAPIError) as exc_info:
|
|
Security(dependency=lambda: None, scopes=value)
|
|
|
|
assert str(exc_info.value) == (
|
|
"Invalid value for `scopes` parameter in Security(). "
|
|
"You probably meant to use the `scope` parameter instead of `scopes`. "
|
|
"Expected a sequence of strings (e.g., ['admin', 'user']), but received a single string."
|
|
)
|
|
|