stac-fastapi.api 3.0.0a4__tar.gz → 3.0.0b1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/PKG-INFO +1 -1
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi/api/app.py +23 -31
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi/api/models.py +36 -63
- stac_fastapi_api-3.0.0b1/stac_fastapi/api/version.py +2 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi.api.egg-info/PKG-INFO +1 -1
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/tests/test_api.py +9 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/tests/test_app.py +97 -5
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/tests/test_models.py +26 -4
- stac_fastapi_api-3.0.0a4/stac_fastapi/api/version.py +0 -2
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/README.md +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/setup.cfg +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/setup.py +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi/api/__init__.py +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi/api/config.py +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi/api/errors.py +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi/api/middleware.py +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi/api/openapi.py +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi/api/routes.py +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi.api.egg-info/SOURCES.txt +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi.api.egg-info/dependency_links.txt +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi.api.egg-info/not-zip-safe +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi.api.egg-info/requires.txt +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi.api.egg-info/top_level.txt +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/tests/test_app_prefix.py +0 -0
- {stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/tests/test_middleware.py +0 -0
|
@@ -18,18 +18,15 @@ from starlette.responses import JSONResponse, Response
|
|
|
18
18
|
from stac_fastapi.api.errors import DEFAULT_STATUS_CODES, add_exception_handlers
|
|
19
19
|
from stac_fastapi.api.middleware import CORSMiddleware, ProxyHeaderMiddleware
|
|
20
20
|
from stac_fastapi.api.models import (
|
|
21
|
+
APIRequest,
|
|
21
22
|
CollectionUri,
|
|
22
23
|
EmptyRequest,
|
|
23
24
|
GeoJSONResponse,
|
|
24
25
|
ItemCollectionUri,
|
|
25
26
|
ItemUri,
|
|
26
|
-
create_request_model,
|
|
27
27
|
)
|
|
28
28
|
from stac_fastapi.api.openapi import update_openapi
|
|
29
29
|
from stac_fastapi.api.routes import Scope, add_route_dependencies, create_async_endpoint
|
|
30
|
-
|
|
31
|
-
# TODO: make this module not depend on `stac_fastapi.extensions`
|
|
32
|
-
from stac_fastapi.extensions.core import FieldsExtension, TokenPaginationExtension
|
|
33
30
|
from stac_fastapi.types.config import ApiSettings, Settings
|
|
34
31
|
from stac_fastapi.types.core import AsyncBaseCoreClient, BaseCoreClient
|
|
35
32
|
from stac_fastapi.types.extension import ApiExtension
|
|
@@ -108,7 +105,10 @@ class StacApi:
|
|
|
108
105
|
search_post_request_model: Type[BaseSearchPostRequest] = attr.ib(
|
|
109
106
|
default=BaseSearchPostRequest
|
|
110
107
|
)
|
|
111
|
-
|
|
108
|
+
collections_get_request_model: Type[APIRequest] = attr.ib(default=EmptyRequest)
|
|
109
|
+
collection_get_request_model: Type[APIRequest] = attr.ib(default=CollectionUri)
|
|
110
|
+
items_get_request_model: Type[APIRequest] = attr.ib(default=ItemCollectionUri)
|
|
111
|
+
item_get_request_model: Type[APIRequest] = attr.ib(default=ItemUri)
|
|
112
112
|
response_class: Type[Response] = attr.ib(default=JSONResponse)
|
|
113
113
|
middlewares: List[Middleware] = attr.ib(
|
|
114
114
|
default=attr.Factory(
|
|
@@ -211,7 +211,9 @@ class StacApi:
|
|
|
211
211
|
response_model_exclude_unset=True,
|
|
212
212
|
response_model_exclude_none=True,
|
|
213
213
|
methods=["GET"],
|
|
214
|
-
endpoint=create_async_endpoint(
|
|
214
|
+
endpoint=create_async_endpoint(
|
|
215
|
+
self.client.get_item, self.item_get_request_model
|
|
216
|
+
),
|
|
215
217
|
)
|
|
216
218
|
|
|
217
219
|
def register_post_search(self):
|
|
@@ -220,15 +222,12 @@ class StacApi:
|
|
|
220
222
|
Returns:
|
|
221
223
|
None
|
|
222
224
|
"""
|
|
223
|
-
fields_ext = self.get_extension(FieldsExtension)
|
|
224
225
|
self.router.add_api_route(
|
|
225
226
|
name="Search",
|
|
226
227
|
path="/search",
|
|
227
|
-
response_model=
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
else None
|
|
231
|
-
),
|
|
228
|
+
response_model=api.ItemCollection
|
|
229
|
+
if self.settings.enable_response_models
|
|
230
|
+
else None,
|
|
232
231
|
responses={
|
|
233
232
|
200: {
|
|
234
233
|
"content": {
|
|
@@ -252,15 +251,12 @@ class StacApi:
|
|
|
252
251
|
Returns:
|
|
253
252
|
None
|
|
254
253
|
"""
|
|
255
|
-
fields_ext = self.get_extension(FieldsExtension)
|
|
256
254
|
self.router.add_api_route(
|
|
257
255
|
name="Search",
|
|
258
256
|
path="/search",
|
|
259
|
-
response_model=
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
else None
|
|
263
|
-
),
|
|
257
|
+
response_model=api.ItemCollection
|
|
258
|
+
if self.settings.enable_response_models
|
|
259
|
+
else None,
|
|
264
260
|
responses={
|
|
265
261
|
200: {
|
|
266
262
|
"content": {
|
|
@@ -302,7 +298,9 @@ class StacApi:
|
|
|
302
298
|
response_model_exclude_unset=True,
|
|
303
299
|
response_model_exclude_none=True,
|
|
304
300
|
methods=["GET"],
|
|
305
|
-
endpoint=create_async_endpoint(
|
|
301
|
+
endpoint=create_async_endpoint(
|
|
302
|
+
self.client.all_collections, self.collections_get_request_model
|
|
303
|
+
),
|
|
306
304
|
)
|
|
307
305
|
|
|
308
306
|
def register_get_collection(self):
|
|
@@ -329,7 +327,9 @@ class StacApi:
|
|
|
329
327
|
response_model_exclude_unset=True,
|
|
330
328
|
response_model_exclude_none=True,
|
|
331
329
|
methods=["GET"],
|
|
332
|
-
endpoint=create_async_endpoint(
|
|
330
|
+
endpoint=create_async_endpoint(
|
|
331
|
+
self.client.get_collection, self.collection_get_request_model
|
|
332
|
+
),
|
|
333
333
|
)
|
|
334
334
|
|
|
335
335
|
def register_get_item_collection(self):
|
|
@@ -338,16 +338,6 @@ class StacApi:
|
|
|
338
338
|
Returns:
|
|
339
339
|
None
|
|
340
340
|
"""
|
|
341
|
-
pagination_extension = self.get_extension(self.pagination_extension)
|
|
342
|
-
if pagination_extension is not None:
|
|
343
|
-
mixins = [pagination_extension.GET]
|
|
344
|
-
else:
|
|
345
|
-
mixins = None
|
|
346
|
-
request_model = create_request_model(
|
|
347
|
-
"ItemCollectionURI",
|
|
348
|
-
base_model=ItemCollectionUri,
|
|
349
|
-
mixins=mixins,
|
|
350
|
-
)
|
|
351
341
|
self.router.add_api_route(
|
|
352
342
|
name="Get ItemCollection",
|
|
353
343
|
path="/collections/{collection_id}/items",
|
|
@@ -366,7 +356,9 @@ class StacApi:
|
|
|
366
356
|
response_model_exclude_unset=True,
|
|
367
357
|
response_model_exclude_none=True,
|
|
368
358
|
methods=["GET"],
|
|
369
|
-
endpoint=create_async_endpoint(
|
|
359
|
+
endpoint=create_async_endpoint(
|
|
360
|
+
self.client.item_collection, self.items_get_request_model
|
|
361
|
+
),
|
|
370
362
|
)
|
|
371
363
|
|
|
372
364
|
def register_core(self):
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"""Api request/response models."""
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
from dataclasses import dataclass, make_dataclass
|
|
4
4
|
from typing import List, Optional, Type, Union
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
from fastapi import Path
|
|
6
|
+
from fastapi import Path, Query
|
|
8
7
|
from pydantic import BaseModel, create_model
|
|
9
8
|
from stac_pydantic.shared import BBox
|
|
9
|
+
from typing_extensions import Annotated
|
|
10
10
|
|
|
11
11
|
from stac_fastapi.types.extension import ApiExtension
|
|
12
12
|
from stac_fastapi.types.rfc3339 import DateTimeType
|
|
@@ -18,6 +18,12 @@ from stac_fastapi.types.search import (
|
|
|
18
18
|
str_to_interval,
|
|
19
19
|
)
|
|
20
20
|
|
|
21
|
+
try:
|
|
22
|
+
import orjson # noqa
|
|
23
|
+
from fastapi.responses import ORJSONResponse as JSONResponse
|
|
24
|
+
except ImportError: # pragma: nocover
|
|
25
|
+
from starlette.responses import JSONResponse
|
|
26
|
+
|
|
21
27
|
|
|
22
28
|
def create_request_model(
|
|
23
29
|
model_name="SearchGetRequest",
|
|
@@ -37,11 +43,11 @@ def create_request_model(
|
|
|
37
43
|
|
|
38
44
|
mixins = mixins or []
|
|
39
45
|
|
|
40
|
-
models =
|
|
46
|
+
models = extension_models + mixins + [base_model]
|
|
41
47
|
|
|
42
48
|
# Handle GET requests
|
|
43
49
|
if all([issubclass(m, APIRequest) for m in models]):
|
|
44
|
-
return
|
|
50
|
+
return make_dataclass(model_name, [], bases=tuple(models))
|
|
45
51
|
|
|
46
52
|
# Handle POST requests
|
|
47
53
|
elif all([issubclass(m, BaseModel) for m in models]):
|
|
@@ -80,85 +86,52 @@ def create_post_request_model(
|
|
|
80
86
|
)
|
|
81
87
|
|
|
82
88
|
|
|
83
|
-
@
|
|
89
|
+
@dataclass
|
|
84
90
|
class CollectionUri(APIRequest):
|
|
85
91
|
"""Get or delete collection."""
|
|
86
92
|
|
|
87
|
-
collection_id: str
|
|
93
|
+
collection_id: Annotated[str, Path(description="Collection ID")]
|
|
88
94
|
|
|
89
95
|
|
|
90
|
-
@
|
|
91
|
-
class ItemUri(
|
|
96
|
+
@dataclass
|
|
97
|
+
class ItemUri(APIRequest):
|
|
92
98
|
"""Get or delete item."""
|
|
93
99
|
|
|
94
|
-
|
|
100
|
+
collection_id: Annotated[str, Path(description="Collection ID")]
|
|
101
|
+
item_id: Annotated[str, Path(description="Item ID")]
|
|
95
102
|
|
|
96
103
|
|
|
97
|
-
@
|
|
104
|
+
@dataclass
|
|
98
105
|
class EmptyRequest(APIRequest):
|
|
99
106
|
"""Empty request."""
|
|
100
107
|
|
|
101
108
|
...
|
|
102
109
|
|
|
103
110
|
|
|
104
|
-
@
|
|
105
|
-
class ItemCollectionUri(
|
|
111
|
+
@dataclass
|
|
112
|
+
class ItemCollectionUri(APIRequest):
|
|
106
113
|
"""Get item collection."""
|
|
107
114
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
class POSTTokenPagination(BaseModel):
|
|
114
|
-
"""Token pagination model for POST requests."""
|
|
115
|
-
|
|
116
|
-
token: Optional[str] = None
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
@attr.s
|
|
120
|
-
class GETTokenPagination(APIRequest):
|
|
121
|
-
"""Token pagination for GET requests."""
|
|
122
|
-
|
|
123
|
-
token: Optional[str] = attr.ib(default=None)
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
class POSTPagination(BaseModel):
|
|
127
|
-
"""Page based pagination for POST requests."""
|
|
115
|
+
collection_id: Annotated[str, Path(description="Collection ID")]
|
|
116
|
+
limit: Annotated[int, Query()] = 10
|
|
117
|
+
bbox: Annotated[Optional[BBox], Query()] = None
|
|
118
|
+
datetime: Annotated[Optional[DateTimeType], Query()] = None
|
|
128
119
|
|
|
129
|
-
|
|
120
|
+
def __post_init__(self):
|
|
121
|
+
"""convert attributes."""
|
|
122
|
+
if self.bbox:
|
|
123
|
+
self.bbox = str2bbox(self.bbox) # type: ignore
|
|
124
|
+
if self.datetime:
|
|
125
|
+
self.datetime = str_to_interval(self.datetime) # type: ignore
|
|
130
126
|
|
|
131
127
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
"""Page based pagination for GET requests."""
|
|
135
|
-
|
|
136
|
-
page: Optional[str] = attr.ib(default=None)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
# Test for ORJSON and use it rather than stdlib JSON where supported
|
|
140
|
-
if importlib.util.find_spec("orjson") is not None:
|
|
141
|
-
from fastapi.responses import ORJSONResponse
|
|
142
|
-
|
|
143
|
-
class GeoJSONResponse(ORJSONResponse):
|
|
144
|
-
"""JSON with custom, vendor content-type."""
|
|
145
|
-
|
|
146
|
-
media_type = "application/geo+json"
|
|
147
|
-
|
|
148
|
-
class JSONSchemaResponse(ORJSONResponse):
|
|
149
|
-
"""JSON with custom, vendor content-type."""
|
|
150
|
-
|
|
151
|
-
media_type = "application/schema+json"
|
|
152
|
-
|
|
153
|
-
else:
|
|
154
|
-
from starlette.responses import JSONResponse
|
|
128
|
+
class GeoJSONResponse(JSONResponse):
|
|
129
|
+
"""JSON with custom, vendor content-type."""
|
|
155
130
|
|
|
156
|
-
|
|
157
|
-
"""JSON with custom, vendor content-type."""
|
|
131
|
+
media_type = "application/geo+json"
|
|
158
132
|
|
|
159
|
-
media_type = "application/geo+json"
|
|
160
133
|
|
|
161
|
-
|
|
162
|
-
|
|
134
|
+
class JSONSchemaResponse(JSONResponse):
|
|
135
|
+
"""JSON with custom, vendor content-type."""
|
|
163
136
|
|
|
164
|
-
|
|
137
|
+
media_type = "application/schema+json"
|
|
@@ -2,6 +2,7 @@ from fastapi import Depends, HTTPException, security, status
|
|
|
2
2
|
from starlette.testclient import TestClient
|
|
3
3
|
|
|
4
4
|
from stac_fastapi.api.app import StacApi
|
|
5
|
+
from stac_fastapi.api.models import ItemCollectionUri, create_request_model
|
|
5
6
|
from stac_fastapi.extensions.core import (
|
|
6
7
|
TokenPaginationExtension,
|
|
7
8
|
TransactionExtension,
|
|
@@ -13,6 +14,13 @@ class TestRouteDependencies:
|
|
|
13
14
|
@staticmethod
|
|
14
15
|
def _build_api(**overrides):
|
|
15
16
|
settings = config.ApiSettings()
|
|
17
|
+
|
|
18
|
+
items_get_request_model = create_request_model(
|
|
19
|
+
"ItemCollectionURI",
|
|
20
|
+
base_model=ItemCollectionUri,
|
|
21
|
+
mixins=[TokenPaginationExtension().GET],
|
|
22
|
+
)
|
|
23
|
+
|
|
16
24
|
return StacApi(
|
|
17
25
|
**{
|
|
18
26
|
"settings": settings,
|
|
@@ -23,6 +31,7 @@ class TestRouteDependencies:
|
|
|
23
31
|
),
|
|
24
32
|
TokenPaginationExtension(),
|
|
25
33
|
],
|
|
34
|
+
"items_get_request_model": items_get_request_model,
|
|
26
35
|
**overrides,
|
|
27
36
|
}
|
|
28
37
|
)
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
1
2
|
from datetime import datetime
|
|
2
3
|
from typing import List, Optional, Union
|
|
3
4
|
|
|
4
5
|
import pytest
|
|
6
|
+
from fastapi import Path, Query
|
|
5
7
|
from fastapi.testclient import TestClient
|
|
6
8
|
from pydantic import ValidationError
|
|
7
9
|
from stac_pydantic import api
|
|
8
10
|
|
|
9
11
|
from stac_fastapi.api import app
|
|
10
|
-
from stac_fastapi.api.models import
|
|
12
|
+
from stac_fastapi.api.models import (
|
|
13
|
+
APIRequest,
|
|
14
|
+
JSONResponse,
|
|
15
|
+
create_get_request_model,
|
|
16
|
+
create_post_request_model,
|
|
17
|
+
)
|
|
11
18
|
from stac_fastapi.extensions.core import FieldsExtension, FilterExtension
|
|
12
19
|
from stac_fastapi.types import stac
|
|
13
20
|
from stac_fastapi.types.config import ApiSettings
|
|
@@ -200,7 +207,14 @@ def test_fields_extension(validate, TestCoreClient, item_dict):
|
|
|
200
207
|
def post_search(
|
|
201
208
|
self, search_request: BaseSearchPostRequest, **kwargs
|
|
202
209
|
) -> stac.ItemCollection:
|
|
203
|
-
|
|
210
|
+
resp = {"not": "a proper stac item"}
|
|
211
|
+
|
|
212
|
+
# if `fields` extension is enabled, then we return a JSONResponse
|
|
213
|
+
# to avoid Item validation
|
|
214
|
+
if getattr(search_request, "fields", None):
|
|
215
|
+
return JSONResponse(content=resp)
|
|
216
|
+
|
|
217
|
+
return resp
|
|
204
218
|
|
|
205
219
|
def get_search(
|
|
206
220
|
self,
|
|
@@ -212,7 +226,14 @@ def test_fields_extension(validate, TestCoreClient, item_dict):
|
|
|
212
226
|
limit: Optional[int] = 10,
|
|
213
227
|
**kwargs,
|
|
214
228
|
) -> stac.ItemCollection:
|
|
215
|
-
|
|
229
|
+
resp = {"not": "a proper stac item"}
|
|
230
|
+
|
|
231
|
+
# if `fields` extension is enabled, then we return a JSONResponse
|
|
232
|
+
# to avoid Item validation
|
|
233
|
+
if "fields" in kwargs:
|
|
234
|
+
return JSONResponse(content=resp)
|
|
235
|
+
|
|
236
|
+
return resp
|
|
216
237
|
|
|
217
238
|
def get_item(self, item_id: str, collection_id: str, **kwargs) -> stac.Item:
|
|
218
239
|
raise NotImplementedError
|
|
@@ -234,6 +255,7 @@ def test_fields_extension(validate, TestCoreClient, item_dict):
|
|
|
234
255
|
) -> stac.ItemCollection:
|
|
235
256
|
raise NotImplementedError
|
|
236
257
|
|
|
258
|
+
# With FieldsExtension
|
|
237
259
|
test_app = app.StacApi(
|
|
238
260
|
settings=ApiSettings(enable_response_models=validate),
|
|
239
261
|
client=BadCoreClient(),
|
|
@@ -258,14 +280,18 @@ def test_fields_extension(validate, TestCoreClient, item_dict):
|
|
|
258
280
|
},
|
|
259
281
|
)
|
|
260
282
|
|
|
283
|
+
# With or without validation, /search endpoints will always return 200
|
|
284
|
+
# because we have the `FieldsExtension` enabled, so the endpoint
|
|
285
|
+
# will avoid the model validation (by returning JSONResponse)
|
|
261
286
|
assert get_search.status_code == 200, get_search.text
|
|
262
287
|
assert post_search.status_code == 200, post_search.text
|
|
263
288
|
|
|
289
|
+
# Without FieldsExtension
|
|
264
290
|
test_app = app.StacApi(
|
|
265
291
|
settings=ApiSettings(enable_response_models=validate),
|
|
266
292
|
client=BadCoreClient(),
|
|
267
|
-
search_get_request_model=create_get_request_model([
|
|
268
|
-
search_post_request_model=create_post_request_model([
|
|
293
|
+
search_get_request_model=create_get_request_model([]),
|
|
294
|
+
search_post_request_model=create_post_request_model([]),
|
|
269
295
|
extensions=[],
|
|
270
296
|
)
|
|
271
297
|
|
|
@@ -284,7 +310,10 @@ def test_fields_extension(validate, TestCoreClient, item_dict):
|
|
|
284
310
|
},
|
|
285
311
|
},
|
|
286
312
|
)
|
|
313
|
+
|
|
287
314
|
if validate:
|
|
315
|
+
# NOTE: the `fields` options will be ignored by fastAPI because it's
|
|
316
|
+
# not part of the request model, so the client should not by-pass the validation
|
|
288
317
|
assert get_search.status_code == 500, (
|
|
289
318
|
get_search.json()["code"] == "ResponseValidationError"
|
|
290
319
|
)
|
|
@@ -294,3 +323,66 @@ def test_fields_extension(validate, TestCoreClient, item_dict):
|
|
|
294
323
|
else:
|
|
295
324
|
assert get_search.status_code == 200, get_search.text
|
|
296
325
|
assert post_search.status_code == 200, post_search.text
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def test_request_model(AsyncTestCoreClient):
|
|
329
|
+
"""Test if request models are passed correctly."""
|
|
330
|
+
|
|
331
|
+
@dataclass
|
|
332
|
+
class CollectionsRequest(APIRequest):
|
|
333
|
+
user: str = Query(...)
|
|
334
|
+
|
|
335
|
+
@dataclass
|
|
336
|
+
class CollectionRequest(APIRequest):
|
|
337
|
+
collection_id: str = Path(description="Collection ID")
|
|
338
|
+
user: str = Query(...)
|
|
339
|
+
|
|
340
|
+
@dataclass
|
|
341
|
+
class ItemsRequest(APIRequest):
|
|
342
|
+
collection_id: str = Path(description="Collection ID")
|
|
343
|
+
user: str = Query(...)
|
|
344
|
+
|
|
345
|
+
@dataclass
|
|
346
|
+
class ItemRequest(APIRequest):
|
|
347
|
+
collection_id: str = Path(description="Collection ID")
|
|
348
|
+
item_id: str = Path(description="Item ID")
|
|
349
|
+
user: str = Query(...)
|
|
350
|
+
|
|
351
|
+
test_app = app.StacApi(
|
|
352
|
+
settings=ApiSettings(),
|
|
353
|
+
client=AsyncTestCoreClient(),
|
|
354
|
+
collections_get_request_model=CollectionsRequest,
|
|
355
|
+
collection_get_request_model=CollectionRequest,
|
|
356
|
+
items_get_request_model=ItemsRequest,
|
|
357
|
+
item_get_request_model=ItemRequest,
|
|
358
|
+
extensions=[],
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
with TestClient(test_app.app) as client:
|
|
362
|
+
resp = client.get("/collections")
|
|
363
|
+
assert resp.status_code == 400
|
|
364
|
+
|
|
365
|
+
resp = client.get("/collections", params={"user": "Luke"})
|
|
366
|
+
assert resp.status_code == 200
|
|
367
|
+
|
|
368
|
+
resp = client.get("/collections/test_collection")
|
|
369
|
+
assert resp.status_code == 400
|
|
370
|
+
|
|
371
|
+
resp = client.get("/collections/test_collection", params={"user": "Leia"})
|
|
372
|
+
assert resp.status_code == 200
|
|
373
|
+
|
|
374
|
+
resp = client.get("/collections/test_collection/items")
|
|
375
|
+
assert resp.status_code == 400
|
|
376
|
+
|
|
377
|
+
resp = client.get(
|
|
378
|
+
"/collections/test_collection/items", params={"user": "Obi-Wan"}
|
|
379
|
+
)
|
|
380
|
+
assert resp.status_code == 200
|
|
381
|
+
|
|
382
|
+
resp = client.get("/collections/test_collection/items/test_item")
|
|
383
|
+
assert resp.status_code == 400
|
|
384
|
+
|
|
385
|
+
resp = client.get(
|
|
386
|
+
"/collections/test_collection/items/test_item", params={"user": "Chewbacca"}
|
|
387
|
+
)
|
|
388
|
+
assert resp.status_code == 200
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import json
|
|
2
2
|
|
|
3
3
|
import pytest
|
|
4
|
+
from fastapi import Depends, FastAPI
|
|
5
|
+
from fastapi.testclient import TestClient
|
|
4
6
|
from pydantic import ValidationError
|
|
5
7
|
|
|
6
8
|
from stac_fastapi.api.models import create_get_request_model, create_post_request_model
|
|
@@ -26,13 +28,33 @@ def test_create_get_request_model():
|
|
|
26
28
|
datetime="2020-01-01T00:00:00Z",
|
|
27
29
|
limit=10,
|
|
28
30
|
filter="test==test",
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
# **{"filter-crs": "epsg:4326", "filter-lang": "cql2-text"},
|
|
31
|
+
filter_crs="epsg:4326",
|
|
32
|
+
filter_lang="cql2-text",
|
|
32
33
|
)
|
|
33
34
|
|
|
34
35
|
assert model.collections == ["test1", "test2"]
|
|
35
|
-
|
|
36
|
+
assert model.filter_crs == "epsg:4326"
|
|
37
|
+
|
|
38
|
+
app = FastAPI()
|
|
39
|
+
|
|
40
|
+
@app.get("/test")
|
|
41
|
+
def route(model=Depends(request_model)):
|
|
42
|
+
return model
|
|
43
|
+
|
|
44
|
+
with TestClient(app) as client:
|
|
45
|
+
resp = client.get(
|
|
46
|
+
"/test",
|
|
47
|
+
params={
|
|
48
|
+
"collections": "test1,test2",
|
|
49
|
+
"filter-crs": "epsg:4326",
|
|
50
|
+
"filter-lang": "cql2-text",
|
|
51
|
+
},
|
|
52
|
+
)
|
|
53
|
+
assert resp.status_code == 200
|
|
54
|
+
response_dict = resp.json()
|
|
55
|
+
assert response_dict["collections"] == ["test1", "test2"]
|
|
56
|
+
assert response_dict["filter_crs"] == "epsg:4326"
|
|
57
|
+
assert response_dict["filter_lang"] == "cql2-text"
|
|
36
58
|
|
|
37
59
|
|
|
38
60
|
@pytest.mark.parametrize(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi.api.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi.api.egg-info/not-zip-safe
RENAMED
|
File without changes
|
{stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi.api.egg-info/requires.txt
RENAMED
|
File without changes
|
{stac_fastapi_api-3.0.0a4 → stac_fastapi_api-3.0.0b1}/stac_fastapi.api.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|