Skip to content

Commit 0c1642c

Browse files
anayeayeividito
authored andcommitted
remove commented code and rename stac api extensions test file
1 parent 3e0643c commit 0c1642c

File tree

7 files changed

+163
-29
lines changed

7 files changed

+163
-29
lines changed

.github/actions/cdk-deploy/action.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,6 @@ runs:
6666
working-directory: ${{ inputs.dir }}
6767
run: docker compose up --build -d
6868

69-
# - name: Ingest Stac Items/Collection
70-
# if: ${{ inputs.skip_tests == false }}
71-
# shell: bash
72-
# working-directory: ${{ inputs.dir }}
73-
# run: |
74-
# ./scripts/load-data-container.sh
75-
7669
- name: Sleep for 10 seconds
7770
if: ${{ inputs.skip_tests == false }}
7871
shell: bash

.github/workflows/pr.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ jobs:
6363
- name: Launch services
6464
run: AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY=${{secrets.AWS_SECRET_ACCESS_KEY}} docker compose up --build -d
6565

66-
# - name: Ingest Stac Items/Collection
67-
# run: |
68-
# ./scripts/load-data-container.sh
69-
7066
- name: Sleep for 10 seconds
7167
run: sleep 10s
7268
shell: bash
@@ -83,7 +79,7 @@ jobs:
8379
- name: Ingest unit tests
8480
run: NO_PYDANTIC_SSM_SETTINGS=1 python -m pytest ingest_api/runtime/tests/ -vv -s
8581

86-
- name: Stac-api transactions unit tests
82+
- name: Stac-api extensions unit tests
8783
run: python -m pytest stac_api/runtime/tests/ --asyncio-mode=auto -vv -s
8884

8985
- name: Stop services

scripts/load-data-container.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

scripts/run-local-tests.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ set -e
55
pre-commit run --all-files
66

77
# Bring up stack for testing; ingestor not required
8-
docker compose up -d stac raster database dynamodb pypgstac
9-
# docker compose up -d --wait stac raster database dynamodb pypgstac
8+
docker compose up -d --wait stac raster database dynamodb pypgstac
109

1110
# cleanup, logging in case of failure
1211
cleanup() {
@@ -36,4 +35,4 @@ python -m pytest .github/workflows/tests/ -vv -s
3635
NO_PYDANTIC_SSM_SETTINGS=1 python -m pytest --cov=ingest_api/runtime/src ingest_api/runtime/tests/ -vv -s
3736

3837
# Transactions tests
39-
python -m pytest stac_api/runtime/tests/ --asyncio-mode=auto -vv -s
38+
python -m pytest stac_api/runtime/tests/ --asyncio-mode=auto -vv -s

stac_api/runtime/tests/conftest.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,6 @@ def test_environ():
240240
os.environ["POSTGRES_HOST_WRITER"] = "0.0.0.0"
241241
os.environ["POSTGRES_PORT"] = "5439"
242242

243-
# os.environ["PGUSER"] = "username"
244-
# os.environ["PGPASSWORD"] = "password"
245-
# os.environ["PGDATABASE"] = "postgis"
246-
# os.environ["PGHOST"] = "database"
247-
# os.environ["PGPORT"] = "5439"
248-
249243

250244
def override_validated_token():
251245
"""
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
"""
2+
Test suite for STAC (SpatioTemporal Asset Catalog) Transactions API endpoints.
3+
4+
This module contains tests for the collection and item endpoints of the STAC API.
5+
It verifies the behavior of the API when posting valid and invalid STAC collections and items,
6+
as well as bulk items.
7+
8+
Endpoints tested:
9+
- /collections
10+
- /collections/{}/items
11+
- /collections/{}/bulk_items
12+
"""
13+
14+
15+
collections_endpoint = "/collections"
16+
items_endpoint = "/collections/{}/items"
17+
bulk_endpoint = "/collections/{}/bulk_items"
18+
19+
20+
class TestList:
21+
"""
22+
Test cases for STAC API's collection and item endpoints.
23+
24+
This class contains tests to ensure that the STAC API correctly handles
25+
posting valid and invalid STAC collections and items, both individually
26+
and in bulk. It uses pytest fixtures to set up the test environment with
27+
necessary data.
28+
"""
29+
30+
async def test_post_invalid_collection(self, api_client, invalid_stac_collection):
31+
"""
32+
Test the API's response to posting an invalid STAC collection.
33+
34+
Asserts that the response status code is 422 and the detail
35+
is "Validation Error".
36+
"""
37+
response = await api_client.post(
38+
collections_endpoint, json=invalid_stac_collection
39+
)
40+
assert response.json()["detail"] == "Validation Error"
41+
assert response.status_code == 422
42+
43+
async def test_post_valid_collection(self, api_client, valid_stac_collection):
44+
"""
45+
Test the API's response to posting a valid STAC collection.
46+
47+
Asserts that the response status code is 200.
48+
"""
49+
response = await api_client.post(
50+
collections_endpoint, json=valid_stac_collection
51+
)
52+
assert response.status_code == 201
53+
54+
async def test_post_invalid_item(self, api_client, invalid_stac_item):
55+
"""
56+
Test the API's response to posting an invalid STAC item.
57+
58+
Asserts that the response status code is 422 and the detail
59+
is "Validation Error".
60+
"""
61+
collection_id = invalid_stac_item["collection"]
62+
response = await api_client.post(
63+
items_endpoint.format(collection_id), json=invalid_stac_item
64+
)
65+
assert response.json()["detail"] == "Validation Error"
66+
assert response.status_code == 422
67+
68+
async def test_post_valid_item(self, api_client, valid_stac_item, collection_in_db):
69+
"""
70+
Test the API's response to posting a valid STAC item.
71+
72+
Asserts that the response status code is 200.
73+
"""
74+
collection_id = valid_stac_item["collection"]
75+
response = await api_client.post(
76+
items_endpoint.format(collection_id), json=valid_stac_item
77+
)
78+
assert response.status_code == 201
79+
80+
async def test_post_invalid_bulk_items(self, api_client, invalid_stac_item):
81+
"""
82+
Test the API's response to posting invalid bulk STAC items.
83+
84+
Asserts that the response status code is 422.
85+
"""
86+
item_id = invalid_stac_item["id"]
87+
collection_id = invalid_stac_item["collection"]
88+
invalid_request = {"items": {item_id: invalid_stac_item}, "method": "upsert"}
89+
90+
response = await api_client.post(
91+
bulk_endpoint.format(collection_id), json=invalid_request
92+
)
93+
assert response.status_code == 422
94+
95+
async def test_post_valid_bulk_items(
96+
self, api_client, valid_stac_item, collection_in_db
97+
):
98+
"""
99+
Test the API's response to posting valid bulk STAC items.
100+
101+
Asserts that the response status code is 200.
102+
"""
103+
item_id = valid_stac_item["id"]
104+
collection_id = valid_stac_item["collection"]
105+
valid_request = {"items": {item_id: valid_stac_item}, "method": "upsert"}
106+
107+
response = await api_client.post(
108+
bulk_endpoint.format(collection_id), json=valid_request
109+
)
110+
assert response.status_code == 200
111+
112+
async def test_get_collection_by_id(self, api_client, collection_in_db):
113+
"""
114+
Test searching for a specific collection by its ID.
115+
"""
116+
# The `collection_in_db` fixture ensures the collection exists and provides its ID.
117+
collection_id = collection_in_db
118+
119+
# Perform a GET request to the /collections endpoint with an "ids" query
120+
response = await api_client.get(
121+
collections_endpoint, params={"ids": collection_id}
122+
)
123+
124+
assert response.status_code == 200
125+
126+
response_data = response.json()
127+
128+
assert response_data["collections"][0]["id"] == collection_id
129+
130+
async def test_collection_freetext_search_by_title(
131+
self, api_client, valid_stac_collection, collection_in_db
132+
):
133+
"""
134+
Test free-text search for a collection using a word from its title.
135+
"""
136+
137+
# The `collection_in_db` fixture ensures the collection exists.
138+
collection_id = collection_in_db
139+
140+
# Use a unique word from the collection's title for the query.
141+
search_term = "precipitation"
142+
143+
# Perform a GET request with the `q` free-text search parameter.
144+
response = await api_client.get(collections_endpoint, params={"q": search_term})
145+
146+
assert response.status_code == 200
147+
response_data = response.json()
148+
149+
assert len(response_data["collections"]) > 0
150+
151+
returned_ids = [col["id"] for col in response_data["collections"]]
152+
assert collection_id in returned_ids

stac_api/runtime/tests/test_transactions.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
"""
2-
Test suite for STAC (SpatioTemporal Asset Catalog) Transactions API endpoints.
2+
Test suite for STAC (SpatioTemporal Asset Catalog) Extensions including Transactions and Collections Search API endpoints.
33
44
This module contains tests for the collection and item endpoints of the STAC API.
55
It verifies the behavior of the API when posting valid and invalid STAC collections and items,
66
as well as bulk items.
77
88
Endpoints tested:
9+
Transactions
910
- /collections
1011
- /collections/{}/items
1112
- /collections/{}/bulk_items
13+
14+
Collection Search
15+
This module adds search options to collections GET method
16+
- /Collections search by id and free text search
17+
1218
"""
1319

1420

@@ -128,7 +134,7 @@ async def test_get_collection_by_id(self, api_client, collection_in_db):
128134
assert response_data["collections"][0]["id"] == collection_id
129135

130136
async def test_collection_freetext_search_by_title(
131-
self, api_client, valid_stac_collection, collection_in_db
137+
self, api_client, collection_in_db
132138
):
133139
"""
134140
Test free-text search for a collection using a word from its title.

0 commit comments

Comments
 (0)