2
2
3
3
import pytest
4
4
5
+ from typing import Iterable
5
6
from martin_eden .core import HttpMessageHandler
7
+ from martin_eden .database import Base , MarshmallowToDataclass , SqlAlchemyToMarshmallow
6
8
from martin_eden .http_utils import HttpHeadersParser
7
9
from martin_eden .routing import register_route
8
10
from tests .conftest import base_http_request , base_http_result_headers
11
+ from datetime import date
12
+ from typing import TYPE_CHECKING
13
+
14
+ from sqlalchemy import ForeignKey
15
+ from sqlalchemy .orm import Mapped , mapped_column , relationship
16
+
17
+ from martin_eden .database import Base
9
18
10
19
pytest_plugins = ('pytest_asyncio' ,)
11
20
@@ -15,6 +24,31 @@ async def get_openapi_schema() -> str:
15
24
return 'test'
16
25
17
26
27
+ class TestModel (Base ):
28
+ __tablename__ = 'test'
29
+ pk : Mapped [int ] = mapped_column (primary_key = True )
30
+ name : Mapped [str ]
31
+
32
+
33
+ class TestSchema (TestModel , metaclass = SqlAlchemyToMarshmallow ):
34
+ pass
35
+
36
+
37
+ class TestDataclass (TestSchema , metaclass = MarshmallowToDataclass ):
38
+ pass
39
+
40
+
41
+ @register_route (
42
+ '/test_query/' , 'get' ,
43
+ response_schema = TestSchema (),
44
+ query_params = {TestModel : ['name' ]},
45
+ )
46
+ async def get_users (query_params : Iterable ) -> str :
47
+ print ()
48
+ print (query_params )
49
+ return query_params
50
+
51
+
18
52
@pytest .fixture
19
53
def http_get_request ():
20
54
return base_http_request .encode ('utf8' )
@@ -88,3 +122,15 @@ async def test_openapi_schema(http_get_request):
88
122
assert openapi_result ['paths' ] == {
89
123
'/test/' : {'get' : {'operationId' : 'test_get' }}
90
124
}
125
+
126
+
127
+ #@pytest.mark.asyncio
128
+ #async def test_query_params(http_get_request):
129
+ # http_get_request = http_get_request.replace(
130
+ # b'/users/', b'/test_query/?test_model__name__like=martin',
131
+ # )
132
+ #
133
+ # handler = HttpMessageHandler(http_get_request)
134
+ # response = await handler.handle_request()
135
+ #
136
+ # print(response)
0 commit comments