Skip to content

Fix tests in test_item.py etc #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Mar 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def bbox2poly(b0, b1, b2, b3):
poly = [[[b0, b1], [b2, b1], [b2, b3], [b0, b3], [b0, b1]]]
return poly

# Core Logic
"""CORE LOGIC"""

def get_all_collections(self, base_url: str) -> Collections:
"""Database logic to retrieve a list of all collections."""
Expand All @@ -53,7 +53,7 @@ def get_all_collections(self, base_url: str) -> Collections:
index=COLLECTIONS_INDEX, query={"match_all": {}}
)
except elasticsearch.exceptions.NotFoundError:
raise NotFoundError("No collections exist")
return []

serialized_collections = [
self.collection_serializer.db_to_stac(
Expand Down Expand Up @@ -222,7 +222,7 @@ def execute_search(self, search, limit: int, base_url: str) -> List:

return response_features

# Transaction Logic
""" TRANSACTION LOGIC """

def check_collection_exists(self, collection_id: str):
"""Database logic to check if a collection exists."""
Expand Down

This file was deleted.

35 changes: 21 additions & 14 deletions stac_fastapi/elasticsearch/tests/api/test_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
from datetime import datetime, timedelta

import pytest
Expand Down Expand Up @@ -69,14 +70,13 @@ def test_app_transaction_extension(app_client, load_test_data, es_transactions):
item = load_test_data("test_item.json")
resp = app_client.post(f"/collections/{item['collection']}/items", json=item)
assert resp.status_code == 200

time.sleep(1)
es_transactions.delete_item(
item["id"], item["collection"], request=MockStarletteRequest
)


def test_app_search_response(load_test_data, app_client, es_transactions):

item = load_test_data("test_item.json")
es_transactions.create_item(item, request=MockStarletteRequest)

Expand All @@ -94,7 +94,6 @@ def test_app_search_response(load_test_data, app_client, es_transactions):
)


@pytest.mark.skip(reason="this all passes manually?? assert 0 == 1")
def test_app_context_extension(load_test_data, app_client, es_transactions, es_core):
item = load_test_data("test_item.json")
collection = load_test_data("test_collection.json")
Expand All @@ -104,6 +103,8 @@ def test_app_context_extension(load_test_data, app_client, es_transactions, es_c
es_transactions.create_collection(collection, request=MockStarletteRequest)
es_transactions.create_item(item, request=MockStarletteRequest)

time.sleep(1)

resp = app_client.get(f"/collections/{collection['id']}/items/{item['id']}")
assert resp.status_code == 200
resp_json = resp.json()
Expand All @@ -115,7 +116,7 @@ def test_app_context_extension(load_test_data, app_client, es_transactions, es_c
resp_json = resp.json()
assert resp_json["id"] == collection["id"]

resp = app_client.post("/search", json={"collections": ["test-collection"]})
resp = app_client.post("/search", json={"collections": ["test-collection-2"]})
assert resp.status_code == 200
resp_json = resp.json()
assert len(resp_json["features"]) == 1
Expand Down Expand Up @@ -159,11 +160,10 @@ def test_app_query_extension_gt(load_test_data, app_client, es_transactions):
)


@pytest.mark.skip(reason="assert 0 == 1")
def test_app_query_extension_gte(load_test_data, app_client, es_transactions):
test_item = load_test_data("test_item.json")
es_transactions.create_item(test_item, request=MockStarletteRequest)

time.sleep(1)
params = {"query": {"proj:epsg": {"gte": test_item["properties"]["proj:epsg"]}}}
resp = app_client.post("/search", json=params)
assert resp.status_code == 200
Expand Down Expand Up @@ -212,14 +212,18 @@ def test_app_query_extension_limit_10000(load_test_data, app_client, es_transact
)


@pytest.mark.skip(reason="sort not fully implemented")
@pytest.mark.skip(
reason="No mapping found for [properties__datetime.keyword] in order to sort on"
)
def test_app_sort_extension(load_test_data, app_client, es_transactions):
first_item = load_test_data("test_item.json")
item_date = datetime.strptime(
first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ"
)
es_transactions.create_item(first_item, request=MockStarletteRequest)

time.sleep(1)

second_item = load_test_data("test_item.json")
second_item["id"] = "another-item"
another_item_date = item_date - timedelta(days=1)
Expand All @@ -228,6 +232,8 @@ def test_app_sort_extension(load_test_data, app_client, es_transactions):
)
es_transactions.create_item(second_item, request=MockStarletteRequest)

time.sleep(1)

params = {
"collections": [first_item["collection"]],
"sortby": [{"field": "datetime", "direction": "desc"}],
Expand Down Expand Up @@ -263,11 +269,11 @@ def test_search_invalid_date(load_test_data, app_client, es_transactions):
)


@pytest.mark.skip(reason="assert 0 == 1")
def test_search_point_intersects(load_test_data, app_client, es_transactions):
item = load_test_data("test_item.json")
es_transactions.create_item(item, request=MockStarletteRequest)

time.sleep(2)
point = [150.04, -33.14]
intersects = {"type": "Point", "coordinates": point}

Expand All @@ -276,19 +282,20 @@ def test_search_point_intersects(load_test_data, app_client, es_transactions):
"collections": [item["collection"]],
}
resp = app_client.post("/search", json=params)
es_transactions.delete_item(
item["id"], item["collection"], request=MockStarletteRequest
)

assert resp.status_code == 200
resp_json = resp.json()
assert len(resp_json["features"]) == 1

es_transactions.delete_item(
item["id"], item["collection"], request=MockStarletteRequest
)


@pytest.mark.skip(reason="unknown")
def test_datetime_non_interval(load_test_data, app_client, es_transactions):
item = load_test_data("test_item.json")
es_transactions.create_item(item, request=MockStarletteRequest)
time.sleep(2)
alternate_formats = [
"2020-02-12T12:30:22+00:00",
"2020-02-12T12:30:22.00Z",
Expand All @@ -312,10 +319,10 @@ def test_datetime_non_interval(load_test_data, app_client, es_transactions):
)


@pytest.mark.skip(reason="unknown")
def test_bbox_3d(load_test_data, app_client, es_transactions):
item = load_test_data("test_item.json")
es_transactions.create_item(item, request=MockStarletteRequest)
time.sleep(1)

australia_bbox = [106.343365, -47.199523, 0.1, 168.218365, -19.437288, 0.1]
params = {
Expand All @@ -331,10 +338,10 @@ def test_bbox_3d(load_test_data, app_client, es_transactions):
)


@pytest.mark.skip(reason="unknown")
def test_search_line_string_intersects(load_test_data, app_client, es_transactions):
item = load_test_data("test_item.json")
es_transactions.create_item(item, request=MockStarletteRequest)
time.sleep(2)

line = [[150.04, -33.14], [150.22, -33.89]]
intersects = {"type": "LineString", "coordinates": line}
Expand Down
10 changes: 6 additions & 4 deletions stac_fastapi/elasticsearch/tests/clients/test_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@ def test_create_collection(
es_transactions.delete_collection(data["id"], request=MockStarletteRequest)


@pytest.mark.skip(reason="passing but messing up the next test")
def test_create_collection_already_exists(
es_transactions: TransactionsClient,
load_test_data: Callable,
):
data = load_test_data("test_collection.json")
es_transactions.create_collection(data, request=MockStarletteRequest)

time.sleep(1)

# change id to avoid elasticsearch duplicate key error
data["_id"] = str(uuid.uuid4())

with pytest.raises(ConflictError):
es_transactions.create_collection(data, request=MockStarletteRequest)

es_transactions.delete_collection(data["id"], request=MockStarletteRequest)


def test_update_collection(
es_core: CoreCrudClient,
Expand Down Expand Up @@ -116,7 +119,6 @@ def test_get_item(
)


@pytest.mark.skip(reason="unknown")
def test_get_collection_items(
es_core: CoreCrudClient,
es_transactions: TransactionsClient,
Expand All @@ -131,6 +133,8 @@ def test_get_collection_items(
item["id"] = str(uuid.uuid4())
es_transactions.create_item(item, request=MockStarletteRequest)

time.sleep(2)

fc = es_core.item_collection(coll["id"], request=MockStarletteRequest)
assert len(fc["features"]) == 5

Expand Down Expand Up @@ -258,7 +262,6 @@ def test_delete_item(
es_core.get_item(item["id"], item["collection"], request=MockStarletteRequest)


# @pytest.mark.skip(reason="might need a larger timeout")
def test_bulk_item_insert(
es_core: CoreCrudClient,
es_transactions: TransactionsClient,
Expand Down Expand Up @@ -315,7 +318,6 @@ def test_feature_collection_insert(
assert len(fc["features"]) >= 10


@pytest.mark.skip(reason="Not working")
def test_landing_page_no_collection_title(
es_core: CoreCrudClient,
es_transactions: TransactionsClient,
Expand Down
Loading