Skip to content

Commit bfbfde3

Browse files
author
Raphael Krupinski
committed
✅ Improve test coverage.
1 parent f4b87d7 commit bfbfde3

File tree

3 files changed

+46
-13
lines changed

3 files changed

+46
-13
lines changed

src/lapidary/runtime/model/params.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ def apply(self, builder: 'RequestBuilder', value: typing.Any) -> None:
6363
def http_name(self) -> str:
6464
return self.alias or self.name
6565

66+
def __eq__(self, other):
67+
if not isinstance(other, type(self)):
68+
raise NotImplementedError
69+
return self.__dict__ == other.__dict__
70+
6671

6772
@dc.dataclass
6873
class RequestBody(RequestPartHandler, ParameterAnnotation):

tests/test_client.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55

66
import fastapi
77
import httpx
8-
import httpx_auth
98
import pydantic
109
import typing_extensions as typing
1110
from starlette.responses import JSONResponse
1211

13-
from lapidary.runtime import APIKeyAuth, ClientBase, NamedAuth, ParamStyle, Path, RequestBody, Responses, get, post, put
12+
from lapidary.runtime import ClientBase, ParamStyle, Path, RequestBody, Responses, get, post, put
1413
from lapidary.runtime.http_consts import MIME_JSON
1514

1615
# model (common to both client and server)
@@ -130,14 +129,11 @@ async def login(
130129
*,
131130
body: typing.Annotated[AuthRequest, RequestBody({MIME_JSON: AuthRequest})],
132131
) -> typing.Annotated[
133-
NamedAuth,
132+
AuthResponse,
134133
Responses(
135134
{
136135
'200': {
137-
MIME_JSON: typing.Annotated[
138-
AuthResponse,
139-
APIKeyAuth('api_key', 'header', 'Authorization', 'Token {body.api_key}'),
140-
]
136+
MIME_JSON: AuthResponse,
141137
}
142138
}
143139
),
@@ -163,12 +159,7 @@ async def test_request(self):
163159
async def test_response_auth(self):
164160
response = await client.login(body=AuthRequest(login='login', password='passwd'))
165161

166-
expected = 'api_key', httpx_auth.HeaderApiKey("Token you're in", 'Authorization')
167-
self.assertEqual(expected[0], response[0])
168-
self.assertDictEqual(
169-
expected[1].__dict__,
170-
response[1].__dict__,
171-
)
162+
self.assertEqual("you're in", response.api_key)
172163

173164
async def test_error(self):
174165
try:

tests/test_process.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import sys
2+
from typing import Annotated, Optional
3+
4+
import pytest
5+
from typing_extensions import Self
6+
7+
from lapidary.runtime import ClientBase, Query, Responses
8+
from lapidary.runtime.model.op import OperationModel, get_operation_model
9+
10+
11+
def test_optional_param():
12+
class Client(ClientBase):
13+
async def operation(
14+
self: Self,
15+
param: Annotated[Optional[str], Query()],
16+
) -> Annotated[None, Responses({})]:
17+
pass
18+
19+
op = get_operation_model('GET', '/op', Client.operation)
20+
expected_anno = Query()
21+
expected_anno.supply_formal('param', Optional[str])
22+
assert op == OperationModel('GET', '/op', {'param': expected_anno}, {})
23+
24+
25+
@pytest.mark.skipif(sys.version_info < (3, 10), reason='type-or requires python3.10 or higher')
26+
def test_or_none_param():
27+
class Client(ClientBase):
28+
async def operation(
29+
self: Self,
30+
param: Annotated[str | None, Query()],
31+
) -> Annotated[None, Responses({})]:
32+
pass
33+
34+
op = get_operation_model('GET', '/op', Client.operation)
35+
expected_anno = Query()
36+
expected_anno.supply_formal('param', Optional[str])
37+
assert op == OperationModel('GET', '/op', {'param': expected_anno}, {})

0 commit comments

Comments
 (0)