Skip to content

Commit

Permalink
update changelog, tests, mark tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhealy1 committed Oct 21, 2023
1 parent 7f1b5e5 commit 2573cf1
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 54 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Corrected the closing of client connections in ES index management functions [#132](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/132)
- Corrected the automatic converstion of float values to int when building Filter Clauses [#135](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/135)
- Remove unsupported characters from Elasticsearch index names [#153](https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/153)
- Fixed GET /search sortby requests https://github.com/stac-utils/stac-fastapi-elasticsearch/issues/25

## [v0.3.0]

Expand Down
15 changes: 15 additions & 0 deletions stac_fastapi/elasticsearch/tests/clients/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ..conftest import MockRequest, create_item


@pytest.mark.asyncio
async def test_create_collection(app_client, ctx, core_client, txn_client):
in_coll = deepcopy(ctx.collection)
in_coll["id"] = str(uuid.uuid4())
Expand All @@ -20,6 +21,7 @@ async def test_create_collection(app_client, ctx, core_client, txn_client):
await txn_client.delete_collection(in_coll["id"])


@pytest.mark.asyncio
async def test_create_collection_already_exists(app_client, ctx, txn_client):
data = deepcopy(ctx.collection)

Expand All @@ -32,6 +34,7 @@ async def test_create_collection_already_exists(app_client, ctx, txn_client):
await txn_client.delete_collection(data["id"])


@pytest.mark.asyncio
async def test_update_collection(
core_client,
txn_client,
Expand All @@ -49,6 +52,7 @@ async def test_update_collection(
await txn_client.delete_collection(data["id"])


@pytest.mark.asyncio
async def test_delete_collection(
core_client,
txn_client,
Expand All @@ -63,6 +67,7 @@ async def test_delete_collection(
await core_client.get_collection(data["id"], request=MockRequest)


@pytest.mark.asyncio
async def test_get_collection(
core_client,
txn_client,
Expand All @@ -76,6 +81,7 @@ async def test_get_collection(
await txn_client.delete_collection(data["id"])


@pytest.mark.asyncio
async def test_get_item(app_client, ctx, core_client):
got_item = await core_client.get_item(
item_id=ctx.item["id"],
Expand All @@ -86,6 +92,7 @@ async def test_get_item(app_client, ctx, core_client):
assert got_item["collection"] == ctx.item["collection"]


@pytest.mark.asyncio
async def test_get_collection_items(app_client, ctx, core_client, txn_client):
coll = ctx.collection
num_of_items_to_create = 5
Expand All @@ -106,6 +113,7 @@ async def test_get_collection_items(app_client, ctx, core_client, txn_client):
assert item["collection"] == coll["id"]


@pytest.mark.asyncio
async def test_create_item(ctx, core_client, txn_client):
resp = await core_client.get_item(
ctx.item["id"], ctx.item["collection"], request=MockRequest
Expand All @@ -115,6 +123,7 @@ async def test_create_item(ctx, core_client, txn_client):
) == Item(**resp).dict(exclude={"links": ..., "properties": {"created", "updated"}})


@pytest.mark.asyncio
async def test_create_item_already_exists(ctx, txn_client):
with pytest.raises(ConflictError):
await txn_client.create_item(
Expand All @@ -125,6 +134,7 @@ async def test_create_item_already_exists(ctx, txn_client):
)


@pytest.mark.asyncio
async def test_update_item(ctx, core_client, txn_client):
ctx.item["properties"]["foo"] = "bar"
collection_id = ctx.item["collection"]
Expand All @@ -139,6 +149,7 @@ async def test_update_item(ctx, core_client, txn_client):
assert updated_item["properties"]["foo"] == "bar"


@pytest.mark.asyncio
async def test_update_geometry(ctx, core_client, txn_client):
new_coordinates = [
[
Expand All @@ -163,6 +174,7 @@ async def test_update_geometry(ctx, core_client, txn_client):
assert updated_item["geometry"]["coordinates"] == new_coordinates


@pytest.mark.asyncio
async def test_delete_item(ctx, core_client, txn_client):
await txn_client.delete_item(ctx.item["id"], ctx.item["collection"])

Expand All @@ -172,6 +184,7 @@ async def test_delete_item(ctx, core_client, txn_client):
)


@pytest.mark.asyncio
async def test_bulk_item_insert(ctx, core_client, txn_client, bulk_txn_client):
items = {}
for _ in range(10):
Expand All @@ -193,6 +206,7 @@ async def test_bulk_item_insert(ctx, core_client, txn_client, bulk_txn_client):
# )


@pytest.mark.asyncio
async def test_feature_collection_insert(
core_client,
txn_client,
Expand All @@ -212,6 +226,7 @@ async def test_feature_collection_insert(
assert len(fc["features"]) >= 10


@pytest.mark.asyncio
async def test_landing_page_no_collection_title(ctx, core_client, txn_client, app):
ctx.collection["id"] = "new_id"
del ctx.collection["title"]
Expand Down
7 changes: 7 additions & 0 deletions stac_fastapi/elasticsearch/tests/extensions/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
from os import listdir
from os.path import isfile, join

import pytest

THIS_DIR = os.path.dirname(os.path.abspath(__file__))


@pytest.mark.asyncio
async def test_search_filters(app_client, ctx):

filters = []
Expand All @@ -19,6 +22,7 @@ async def test_search_filters(app_client, ctx):
assert resp.status_code == 200


@pytest.mark.asyncio
async def test_search_filter_extension_eq(app_client, ctx):
params = {"filter": {"op": "=", "args": [{"property": "id"}, ctx.item["id"]]}}
resp = await app_client.post("/search", json=params)
Expand All @@ -27,6 +31,7 @@ async def test_search_filter_extension_eq(app_client, ctx):
assert len(resp_json["features"]) == 1


@pytest.mark.asyncio
async def test_search_filter_extension_gte(app_client, ctx):
# there's one item that can match, so one of these queries should match it and the other shouldn't
params = {
Expand Down Expand Up @@ -58,6 +63,7 @@ async def test_search_filter_extension_gte(app_client, ctx):
assert len(resp.json()["features"]) == 0


@pytest.mark.asyncio
async def test_search_filter_ext_and(app_client, ctx):
params = {
"filter": {
Expand All @@ -80,6 +86,7 @@ async def test_search_filter_ext_and(app_client, ctx):
assert len(resp.json()["features"]) == 1


@pytest.mark.asyncio
async def test_search_filter_extension_floats(app_client, ctx):
sun_elevation = ctx.item["properties"]["view:sun_elevation"]

Expand Down
8 changes: 8 additions & 0 deletions stac_fastapi/elasticsearch/tests/resources/test_collection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pystac
import pytest


@pytest.mark.asyncio
async def test_create_and_delete_collection(app_client, load_test_data):
"""Test creation and deletion of a collection"""
test_collection = load_test_data("test_collection.json")
Expand All @@ -13,19 +15,22 @@ async def test_create_and_delete_collection(app_client, load_test_data):
assert resp.status_code == 204


@pytest.mark.asyncio
async def test_create_collection_conflict(app_client, ctx):
"""Test creation of a collection which already exists"""
# This collection ID is created in the fixture, so this should be a conflict
resp = await app_client.post("/collections", json=ctx.collection)
assert resp.status_code == 409


@pytest.mark.asyncio
async def test_delete_missing_collection(app_client):
"""Test deletion of a collection which does not exist"""
resp = await app_client.delete("/collections/missing-collection")
assert resp.status_code == 404


@pytest.mark.asyncio
async def test_update_collection_already_exists(ctx, app_client):
"""Test updating a collection which already exists"""
ctx.collection["keywords"].append("test")
Expand All @@ -38,6 +43,7 @@ async def test_update_collection_already_exists(ctx, app_client):
assert "test" in resp_json["keywords"]


@pytest.mark.asyncio
async def test_update_new_collection(app_client, load_test_data):
"""Test updating a collection which does not exist (same as creation)"""
test_collection = load_test_data("test_collection.json")
Expand All @@ -47,12 +53,14 @@ async def test_update_new_collection(app_client, load_test_data):
assert resp.status_code == 404


@pytest.mark.asyncio
async def test_collection_not_found(app_client):
"""Test read a collection which does not exist"""
resp = await app_client.get("/collections/does-not-exist")
assert resp.status_code == 404


@pytest.mark.asyncio
async def test_returns_valid_collection(ctx, app_client):
"""Test validates fetched collection with jsonschema"""
resp = await app_client.put("/collections", json=ctx.collection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def get_link(landing_page, rel_type):
)


@pytest.mark.asyncio
async def test_landing_page_health(response):
"""Test landing page"""
assert response.status_code == 200
Expand All @@ -39,6 +40,7 @@ async def test_landing_page_health(response):
]


@pytest.mark.asyncio
@pytest.mark.parametrize("rel_type,expected_media_type,expected_path", link_tests)
async def test_landing_page_links(
response_json, app_client, rel_type, expected_media_type, expected_path
Expand All @@ -59,6 +61,7 @@ async def test_landing_page_links(
# code here seems meaningless since it would be the same as if the endpoint did not exist. Once
# https://github.com/stac-utils/stac-fastapi/pull/227 has been merged we can add this to the
# parameterized tests above.
@pytest.mark.asyncio
async def test_search_link(response_json):
search_link = get_link(response_json, "search")

Expand Down
Loading

0 comments on commit 2573cf1

Please sign in to comment.