|
1 | 1 | from datetime import datetime, timedelta
|
2 |
| -from urllib.parse import quote_plus |
| 2 | +from urllib.parse import quote_plus, urljoin |
3 | 3 |
|
| 4 | +import attrs |
4 | 5 | import orjson
|
5 | 6 | import pytest
|
| 7 | +from httpx import AsyncClient |
| 8 | + |
| 9 | +from stac_fastapi.pgstac.db import close_db_connection, connect_to_db, dbfunc |
| 10 | +from stac_fastapi.types.stac import Collection |
6 | 11 |
|
7 | 12 | STAC_CORE_ROUTES = [
|
8 | 13 | "GET /",
|
@@ -92,6 +97,39 @@ async def test_core_router(api_client, app):
|
92 | 97 | assert not core_routes - api_routes
|
93 | 98 |
|
94 | 99 |
|
| 100 | +async def test_response_models(api_client): |
| 101 | + settings = api_client.settings |
| 102 | + settings.enable_response_models = True |
| 103 | + api = attrs.evolve(api_client, settings=settings) |
| 104 | + await connect_to_db(api.app) |
| 105 | + |
| 106 | + base_url = "http://test" |
| 107 | + if api.app.state.router_prefix != "": |
| 108 | + base_url = urljoin(base_url, api.app.state.router_prefix) |
| 109 | + |
| 110 | + collection = Collection( |
| 111 | + type="MyCollection", |
| 112 | + stac_version="1.0.0", |
| 113 | + id="my-collection", |
| 114 | + description="A test collection with an invalid type field", |
| 115 | + links=[], |
| 116 | + keywords=[], |
| 117 | + license="proprietary", |
| 118 | + providers=[], |
| 119 | + extent={}, |
| 120 | + summaries={}, |
| 121 | + assets={}, |
| 122 | + ) |
| 123 | + pool = api.app.state.writepool |
| 124 | + await dbfunc(pool, "create_collection", collection) |
| 125 | + |
| 126 | + async with AsyncClient(app=api.app, base_url=base_url) as client: |
| 127 | + response = await client.get("/collections/my-collection") |
| 128 | + assert response.status_code == 500, response.json()["type"] |
| 129 | + |
| 130 | + await close_db_connection(api.app) |
| 131 | + |
| 132 | + |
95 | 133 | async def test_landing_page_stac_extensions(app_client):
|
96 | 134 | resp = await app_client.get("/")
|
97 | 135 | assert resp.status_code == 200
|
|
0 commit comments