Skip to content

Commit

Permalink
untangle item_collection and api.item_collectoin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-maschler committed Nov 21, 2023
1 parent f0942c3 commit 48b5d63
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
2 changes: 2 additions & 0 deletions tests/api/examples/v1.0.0/itemcollection-sample-full.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"type": "FeatureCollection",
"numberMatched": 10,
"numberReturned": 1,
"features": [
{
"stac_version": "1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion tests/api/extensions/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_fields_filter_item():
bbox=[0, 0, 0, 0],
type="Feature",
)
print(fields.filter)

d = item.model_dump(**fields.filter)
assert d.pop("id") == item.id
assert d.pop("geometry") == item.geometry.model_dump(exclude_unset=True)
Expand Down
21 changes: 18 additions & 3 deletions tests/api/test_item_collection.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
import json

from stac_pydantic import ItemCollection
import pytest

from stac_pydantic.api import ItemCollection
from stac_pydantic.api.version import STAC_API_VERSION
from stac_pydantic.version import STAC_VERSION

from ..conftest import dict_match, request
from ..conftest import compare_example, dict_match, request

ITEM_COLLECTION = "itemcollection-sample-full.json"
PATH = ["tests", "api", "examples", f"v{STAC_API_VERSION}"]


@pytest.mark.parametrize(
"example_url",
[
f"https://raw.githubusercontent.com/radiantearth/stac-api-spec/v{STAC_API_VERSION}/fragments/itemcollection/examples/itemcollection-sample-full.json",
f"https://raw.githubusercontent.com/radiantearth/stac-api-spec/v{STAC_API_VERSION}/fragments/itemcollection/examples/itemcollection-sample-minimal.json",
],
)
def test_item_collection_examples(example_url):
"""
Testing the less strict version here, not enforcing required Links
"""
compare_example(example_url, ItemCollection)


def test_item_collection():
test_item_coll = request(ITEM_COLLECTION, PATH)
for feat in test_item_coll["features"]:
Expand All @@ -20,7 +36,6 @@ def test_item_collection():
dict_match(feat, valid_item_coll["features"][idx])


# TODO: REFACTOR
def test_to_json():
test_item = request(ITEM_COLLECTION, PATH)
for feat in test_item["features"]:
Expand Down
4 changes: 0 additions & 4 deletions tests/api/test_landing_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def test_landing_page_invalid_features(example_url):
LandingPage(**example)


# TODO: Not sure if this actually does anything??
@pytest.mark.parametrize("example_url,schema_url", unique_combinations)
def test_schema(example_url, schema_url):
rsp_yaml = requests.get(schema_url).text
Expand All @@ -70,9 +69,6 @@ def test_schema(example_url, schema_url):
jsonschema.validate(instance=landing_page, schema=schema)


##############


def test_api_landing_page():
LandingPage(
id="test-landing-page",
Expand Down
15 changes: 2 additions & 13 deletions tests/test_item_collection.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
import json

from stac_pydantic import ItemCollection
from stac_pydantic.api.version import STAC_API_VERSION
from stac_pydantic.version import STAC_VERSION

from .conftest import dict_match, request

ITEM_COLLECTION = "itemcollection-sample-full.json"
PATH = ["tests", "api", "examples", f"v{STAC_API_VERSION}"]

# TODO sort this out. has extra attributes but missing links
# @pytest.mark.parametrize("example_url", [f"https://raw.githubusercontent.com/radiantearth/stac-api-spec/v{STAC_API_VERSION}/fragments/itemcollection/examples/itemcollection-sample-full.json",
# f"https://raw.githubusercontent.com/radiantearth/stac-api-spec/v{STAC_API_VERSION}/fragments/itemcollection/examples/itemcollection-sample-minimal.json"])
# def test_item_collection_examples(example_url):
# """
# Testing the less strict version here, not enforcing required Links
# """
# compare_example(example_url, ItemCollection)
PATH = ["tests", "example_stac"]


def test_item_collection():
test_item_coll = request(ITEM_COLLECTION, PATH)
# test_item_coll["stac_version"] = STAC_VERSION

for feat in test_item_coll["features"]:
feat["stac_version"] = STAC_VERSION

Expand All @@ -30,7 +20,6 @@ def test_item_collection():
dict_match(feat, valid_item_coll["features"][idx])


# TODO: REFACTOR
def test_to_json():
test_item = request(ITEM_COLLECTION, PATH)
for feat in test_item["features"]:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py38,py39,py310,py311
envlist = py38,py39,py310,py311,py312

[testenv]
extras = dev
Expand Down

0 comments on commit 48b5d63

Please sign in to comment.