Example #1
0
def app_client(load_test_data, postgres_transactions):
    app = create_app(settings)
    coll = Collection.parse_obj(load_test_data("test_collection.json"))
    postgres_transactions.create_collection(coll, request=MockStarletteRequest)

    with TestClient(app) as test_app:
        yield test_app
Example #2
0
def test_app_sort_extension(load_test_data, postgres_transactions):
    settings = ApiSettings(stac_api_extensions=["sort"], )
    app = create_app(settings)

    coll = Collection.parse_obj(load_test_data("test_collection.json"))
    postgres_transactions.create_collection(coll, request=MockStarletteRequest)

    first_item = load_test_data("test_item.json")
    item_date = datetime.strptime(first_item["properties"]["datetime"],
                                  "%Y-%m-%dT%H:%M:%SZ")
    postgres_transactions.create_item(Item.parse_obj(first_item),
                                      request=MockStarletteRequest)

    second_item = load_test_data("test_item.json")
    second_item["id"] = "another-item"
    another_item_date = item_date - timedelta(days=1)
    second_item["properties"]["datetime"] = another_item_date.strftime(
        "%Y-%m-%dT%H:%M:%SZ")
    postgres_transactions.create_item(Item.parse_obj(second_item),
                                      request=MockStarletteRequest)

    with TestClient(app) as client:
        params = {
            "collections": [first_item["collection"]],
            "sortby": [{
                "field": "datetime",
                "direction": "desc"
            }],
        }
        resp = client.post("/search", json=params)
        assert resp.status_code == 200
        resp_json = resp.json()
        assert resp_json["features"][0]["id"] == first_item["id"]
        assert resp_json["features"][1]["id"] == second_item["id"]
Example #3
0
def test_app_transaction_extension(load_test_data):
    settings = ApiSettings(stac_api_extensions=["transaction"])
    app = create_app(settings)

    with TestClient(app) as client:
        collection = load_test_data("test_collection.json")
        resp = client.post("/collections", json=collection)
        assert resp.status_code == 200

        item = load_test_data("test_item.json")
        resp = client.post(f"/collections/{item['collection']}/items",
                           json=item)
        assert resp.status_code == 200
Example #4
0
def test_app_fields_extension(load_test_data, postgres_transactions):
    settings = ApiSettings(stac_api_extensions=["fields"])
    app = create_app(settings)

    coll = Collection.parse_obj(load_test_data("test_collection.json"))
    item = Item.parse_obj(load_test_data("test_item.json"))
    postgres_transactions.create_collection(coll, request=MockStarletteRequest)
    postgres_transactions.create_item(item, request=MockStarletteRequest)

    with TestClient(app) as client:
        resp = client.get("/search",
                          params={"collections": ["test-collection"]})
        assert resp.status_code == 200
        resp_json = resp.json()
        assert list(resp_json["features"][0]["properties"]) == ["datetime"]
Example #5
0
def test_app_context_extension(load_test_data, postgres_transactions):
    settings = ApiSettings(stac_api_extensions=["context"])
    app = create_app(settings)

    coll = Collection.parse_obj(load_test_data("test_collection.json"))
    item = Item.parse_obj(load_test_data("test_item.json"))
    postgres_transactions.create_collection(coll, request=MockStarletteRequest)
    postgres_transactions.create_item(item, request=MockStarletteRequest)

    with TestClient(app) as client:
        resp = client.get("/search",
                          params={"collections": ["test-collection"]})
        assert resp.status_code == 200
        resp_json = resp.json()

        assert "context" in resp_json
        assert resp_json["context"]["returned"] == resp_json["context"][
            "matched"] == 1
Example #6
0
def test_app_query_extension(load_test_data, postgres_transactions):
    settings = ApiSettings(stac_api_extensions=["query"], )
    app = create_app(settings)

    coll = Collection.parse_obj(load_test_data("test_collection.json"))
    test_item = load_test_data("test_item.json")
    item = Item.parse_obj(test_item)
    postgres_transactions.create_collection(coll, request=MockStarletteRequest)
    postgres_transactions.create_item(item, request=MockStarletteRequest)

    with TestClient(app) as client:
        params = {
            "query": {
                "proj:epsg": {
                    "gt": test_item["properties"]["proj:epsg"] + 1
                }
            }
        }
        resp = client.post("/search", json=params)
        assert resp.status_code == 200
        resp_json = resp.json()
        assert len(resp_json["features"]) == 0
Example #7
0
from stac_api.api import create_app
from stac_api.config import ApiSettings

os.environ["AWS_REQUEST_PAYER"] = "requester"


settings = ApiSettings(
    stac_api_extensions=["context", "fields", "query", "sort", "transaction"],
    add_ons=["tiles"],
    default_includes={
        "id",
        "type",
        "geometry",
        "bbox",
        "links",
        "assets",
        "properties.datetime",
        "properties.updated",
        "properties.created",
        "properties.gsd",
        "properties.eo:bands",
        "properties.proj:epsg",
        "properties.naip:quadrant",
        "properties.naip:cell_id",
        "properties.naip:statename",
        "properties.naip:utm_zone",
        "properties.naip:quad_location",
    },
)
app = create_app(settings=settings)