Skip to content

Commit 2d10292

Browse files
committed
Use shared app config
1 parent a569587 commit 2d10292

File tree

5 files changed

+120
-248
lines changed

5 files changed

+120
-248
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1515
### Changed
1616

1717
- Optimize data_loader.py script [#395](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/395)
18+
- Refactored test configuration to use shared app config pattern [#396](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/396)
1819

1920
### Removed
2021

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,26 @@
104104

105105
post_request_model = create_post_request_model(search_extensions)
106106

107-
api = StacApi(
108-
title=os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi-elasticsearch"),
109-
description=os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi-elasticsearch"),
110-
api_version=os.getenv("STAC_FASTAPI_VERSION", "5.0.0a1"),
111-
settings=settings,
112-
extensions=extensions,
113-
client=CoreClient(
107+
# Export the configuration that would be used to create the app
108+
app_config = {
109+
"title": os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi-elasticsearch"),
110+
"description": os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi-elasticsearch"),
111+
"api_version": os.getenv("STAC_FASTAPI_VERSION", "5.0.0a1"),
112+
"settings": settings,
113+
"extensions": extensions,
114+
"client": CoreClient(
114115
database=database_logic,
115116
session=session,
116117
post_request_model=post_request_model,
117118
landing_page_id=os.getenv("STAC_FASTAPI_LANDING_PAGE_ID", "stac-fastapi"),
118119
),
119-
search_get_request_model=create_get_request_model(search_extensions),
120-
search_post_request_model=post_request_model,
121-
route_dependencies=get_route_dependencies(),
122-
)
120+
"search_get_request_model": create_get_request_model(search_extensions),
121+
"search_post_request_model": post_request_model,
122+
"route_dependencies": get_route_dependencies(),
123+
}
124+
125+
# Create the app instance for production use
126+
api = StacApi(**app_config)
123127

124128

125129
@asynccontextmanager

stac_fastapi/opensearch/stac_fastapi/opensearch/app.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,26 @@
105105

106106
post_request_model = create_post_request_model(search_extensions)
107107

108-
api = StacApi(
109-
title=os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi-opensearch"),
110-
description=os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi-opensearch"),
111-
api_version=os.getenv("STAC_FASTAPI_VERSION", "5.0.0a1"),
112-
settings=settings,
113-
extensions=extensions,
114-
client=CoreClient(
108+
# Export the configuration that would be used to create the app
109+
app_config = {
110+
"title": os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi-opensearch"),
111+
"description": os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi-opensearch"),
112+
"api_version": os.getenv("STAC_FASTAPI_VERSION", "5.0.0a1"),
113+
"settings": settings,
114+
"extensions": extensions,
115+
"client": CoreClient(
115116
database=database_logic,
116117
session=session,
117118
post_request_model=post_request_model,
118119
landing_page_id=os.getenv("STAC_FASTAPI_LANDING_PAGE_ID", "stac-fastapi"),
119120
),
120-
search_get_request_model=create_get_request_model(search_extensions),
121-
search_post_request_model=post_request_model,
122-
route_dependencies=get_route_dependencies(),
123-
)
121+
"search_get_request_model": create_get_request_model(search_extensions),
122+
"search_post_request_model": post_request_model,
123+
"route_dependencies": get_route_dependencies(),
124+
}
125+
126+
# Create the app instance for production use
127+
api = StacApi(**app_config)
124128

125129

126130
@asynccontextmanager

stac_fastapi/tests/api/test_api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"POST /collections/{collection_id}/items",
3535
"PUT /collections/{collection_id}",
3636
"PUT /collections/{collection_id}/items/{item_id}",
37+
"POST /collections/{collection_id}/bulk_items",
3738
"GET /aggregations",
3839
"GET /aggregate",
3940
"POST /aggregations",
@@ -70,6 +71,14 @@ async def test_api_headers(app_client):
7071
@pytest.mark.asyncio
7172
async def test_router(app):
7273
api_routes = set([f"{list(route.methods)[0]} {route.path}" for route in app.routes])
74+
print("\nActual routes:")
75+
for route in sorted(api_routes):
76+
print(f" {route}")
77+
print("\nExpected routes:")
78+
for route in sorted(ROUTES):
79+
print(f" {route}")
80+
print("\nMissing routes:", ROUTES - api_routes)
81+
print("Extra routes:", api_routes - ROUTES)
7382
assert len(api_routes - ROUTES) == 0
7483

7584

0 commit comments

Comments
 (0)