add api exception handler (#74)

* try to add exception handler

* improve server error test

* fix lint

* add build_uri util

* fix header file path

---------

Co-authored-by: Dmitry Afanasyev <afanasiev@litres.ru>
This commit is contained in:
Dmitry Afanasyev
2023-12-30 23:50:59 +03:00
committed by GitHub
parent d1ae7f2281
commit bf7a5520dc
10 changed files with 171 additions and 45 deletions

View File

@@ -1,7 +1,9 @@
import time
from typing import Callable
from core.utils import timed_lru_cache
import pytest
from core.utils import build_uri, timed_lru_cache
class TestTimedLruCache:
@@ -58,3 +60,21 @@ class TestTimedLruCache:
) -> None:
for _ in range(call_times):
assert func(first, second) == result
@pytest.mark.parametrize(
"uri_parts, expected_result",
[
(["", "admin"], "/admin"),
(["/gpt", "admin"], "/gpt/admin"),
(["/gpt", "/chat"], "/gpt/chat"),
(["gpt", ""], "/gpt"),
(["gpt"], "/gpt"),
(["gpt", "chat"], "/gpt/chat"),
(["", ""], "/"),
(["gpt", "/chat", "/admin"], "/gpt/chat/admin"),
(["gpt/", "/chat/", "/admin"], "/gpt/chat/admin"),
],
)
def test_build_uri_with_slash_prefix(uri_parts: list[str], expected_result: str) -> None:
assert build_uri(uri_parts) == expected_result