Skip to content

Commit e41f8d1

Browse files
Refactor/pgstac version tests (#305)
* update pypgstac version and tests multiple versions * use python 3.11 * revert
1 parent 7f3b9d7 commit e41f8d1

File tree

5 files changed

+49
-30
lines changed

5 files changed

+49
-30
lines changed

.github/workflows/cicd.yaml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,12 @@ on:
66
branches: [main]
77
workflow_dispatch:
88

9-
109
jobs:
1110
test:
1211
runs-on: ubuntu-latest
1312
strategy:
1413
matrix:
15-
include:
16-
- {python: '3.12', pypgstac: '0.9.*'}
17-
- {python: '3.12', pypgstac: '0.8.*'}
18-
- {python: '3.11', pypgstac: '0.8.*'}
19-
- {python: '3.10', pypgstac: '0.8.*'}
20-
- {python: '3.9', pypgstac: '0.8.*'}
14+
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
2115

2216
timeout-minutes: 20
2317

@@ -46,7 +40,6 @@ jobs:
4640
run: |
4741
python -m pip install --upgrade pip
4842
python -m pip install .[dev,server,validation]
49-
python -m pip install "pypgstac==${{ matrix.pypgstac }}"
5043
5144
- name: Run test suite
5245
run: python -m pytest --cov stac_fastapi.pgstac --cov-report xml --cov-report term-missing

setup.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616
"buildpg",
1717
"brotli_asgi",
1818
"cql2>=0.3.6",
19-
"pypgstac>=0.8,<0.10",
19+
"pypgstac>=0.9,<0.10",
20+
"hydraters>=0.1.3",
2021
"typing_extensions>=4.9.0",
2122
"jsonpatch>=1.33.0",
2223
"json-merge-patch>=0.3.0",
23-
"hydraters>=0.1.3",
2424
]
2525

2626
extra_reqs = {
2727
"dev": [
2828
"pystac[validation]",
29-
"pypgstac[psycopg]==0.9.*",
3029
"pytest-postgresql",
3130
"pytest",
3231
"pytest-cov",
@@ -37,6 +36,8 @@
3736
"httpx",
3837
"twine",
3938
"wheel",
39+
"psycopg[binary]==3.1.*",
40+
"psycopg-pool==3.1.*",
4041
],
4142
"docs": [
4243
"black>=23.10.1",
@@ -68,6 +69,8 @@
6869
"Programming Language :: Python :: 3.10",
6970
"Programming Language :: Python :: 3.11",
7071
"Programming Language :: Python :: 3.12",
72+
"Programming Language :: Python :: 3.13",
73+
"Programming Language :: Python :: 3.14",
7174
"License :: OSI Approved :: MIT License",
7275
],
7376
keywords="STAC FastAPI COG",

tests/conftest.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import pytest
1010
from fastapi import APIRouter
1111
from httpx import ASGITransport, AsyncClient
12-
from pypgstac import __version__ as pgstac_version
1312
from pypgstac.db import PgstacDB
1413
from pypgstac.migrate import Migrate
1514
from pytest_postgresql.janitor import DatabaseJanitor
@@ -54,12 +53,6 @@
5453
logger = logging.getLogger(__name__)
5554

5655

57-
requires_pgstac_0_9_2 = pytest.mark.skipif(
58-
tuple(map(int, pgstac_version.split("."))) < (0, 9, 2),
59-
reason="PgSTAC>=0.9.2 required",
60-
)
61-
62-
6356
@pytest.fixture(scope="session")
6457
def database(postgresql_proc):
6558
with DatabaseJanitor(
@@ -79,7 +72,13 @@ def database(postgresql_proc):
7972
yield jan
8073

8174

82-
@pytest.fixture(autouse=True)
75+
@pytest.fixture(
76+
params=[
77+
"0.8.6",
78+
"0.9.8",
79+
],
80+
autouse=True,
81+
)
8382
async def pgstac(database):
8483
connection = f"postgresql://{database.user}:{quote(database.password)}@{database.host}:{database.port}/{database.dbname}"
8584
yield

tests/resources/test_collection.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import pytest
55
from stac_pydantic import Collection
66

7-
from ..conftest import requires_pgstac_0_9_2
8-
97

108
async def test_create_collection(app_client, load_test_data: Callable):
119
in_json = load_test_data("test_collection.json")
@@ -349,11 +347,15 @@ async def test_get_collections_search(
349347
assert len(resp.json()["collections"]) == 2
350348

351349

352-
@requires_pgstac_0_9_2
353350
@pytest.mark.asyncio
354351
async def test_collection_search_freetext(
355352
app_client, load_test_collection, load_test2_collection
356353
):
354+
res = await app_client.get("/_mgmt/health")
355+
pgstac_version = res.json()["pgstac"]["pgstac_version"]
356+
if tuple(map(int, pgstac_version.split("."))) < (0, 9, 2):
357+
pass
358+
357359
# free-text
358360
resp = await app_client.get(
359361
"/collections",
@@ -388,11 +390,15 @@ async def test_collection_search_freetext(
388390
assert len(resp.json()["collections"]) == 0
389391

390392

391-
@requires_pgstac_0_9_2
392393
@pytest.mark.asyncio
393394
async def test_collection_search_freetext_advanced(
394395
app_client_advanced_freetext, load_test_collection, load_test2_collection
395396
):
397+
res = await app_client_advanced_freetext.get("/_mgmt/health")
398+
pgstac_version = res.json()["pgstac"]["pgstac_version"]
399+
if tuple(map(int, pgstac_version.split("."))) < (0, 9, 2):
400+
pass
401+
396402
# free-text
397403
resp = await app_client_advanced_freetext.get(
398404
"/collections",
@@ -436,9 +442,13 @@ async def test_collection_search_freetext_advanced(
436442
assert len(resp.json()["collections"]) == 0
437443

438444

439-
@requires_pgstac_0_9_2
440445
@pytest.mark.asyncio
441446
async def test_all_collections_with_pagination(app_client, load_test_data):
447+
res = await app_client.get("/_mgmt/health")
448+
pgstac_version = res.json()["pgstac"]["pgstac_version"]
449+
if tuple(map(int, pgstac_version.split("."))) < (0, 9, 2):
450+
pass
451+
442452
data = load_test_data("test_collection.json")
443453
collection_id = data["id"]
444454
for ii in range(0, 12):
@@ -468,9 +478,13 @@ async def test_all_collections_with_pagination(app_client, load_test_data):
468478
assert {"root", "self"} == {link["rel"] for link in links}
469479

470480

471-
@requires_pgstac_0_9_2
472481
@pytest.mark.asyncio
473482
async def test_all_collections_without_pagination(app_client_no_ext, load_test_data):
483+
res = await app_client_no_ext.get("/_mgmt/health")
484+
pgstac_version = res.json()["pgstac"]["pgstac_version"]
485+
if tuple(map(int, pgstac_version.split("."))) < (0, 9, 2):
486+
pass
487+
474488
data = load_test_data("test_collection.json")
475489
collection_id = data["id"]
476490
for ii in range(0, 12):
@@ -491,11 +505,15 @@ async def test_all_collections_without_pagination(app_client_no_ext, load_test_d
491505
assert {"root", "self"} == {link["rel"] for link in links}
492506

493507

494-
@requires_pgstac_0_9_2
495508
@pytest.mark.asyncio
496509
async def test_get_collections_search_pagination(
497510
app_client, load_test_collection, load_test2_collection
498511
):
512+
res = await app_client.get("/_mgmt/health")
513+
pgstac_version = res.json()["pgstac"]["pgstac_version"]
514+
if tuple(map(int, pgstac_version.split("."))) < (0, 9, 2):
515+
pass
516+
499517
resp = await app_client.get("/collections")
500518
assert resp.json()["numberReturned"] == 2
501519
assert resp.json()["numberMatched"] == 2
@@ -621,12 +639,16 @@ async def test_get_collections_search_pagination(
621639
assert {"root", "self"} == {link["rel"] for link in links}
622640

623641

624-
@requires_pgstac_0_9_2
625642
@pytest.mark.xfail(strict=False)
626643
@pytest.mark.asyncio
627644
async def test_get_collections_search_offset_1(
628645
app_client, load_test_collection, load_test2_collection
629646
):
647+
res = await app_client.get("/_mgmt/health")
648+
pgstac_version = res.json()["pgstac"]["pgstac_version"]
649+
if tuple(map(int, pgstac_version.split("."))) < (0, 9, 2):
650+
pass
651+
630652
# BUG: pgstac doesn't return a `prev` link when limit is not set
631653
# offset=1, should have a `previous` link
632654
resp = await app_client.get(

tests/resources/test_item.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
from stac_fastapi.pgstac.models.links import CollectionLinks
2020

21-
from ..conftest import requires_pgstac_0_9_2
22-
2321

2422
async def test_create_collection(app_client, load_test_data: Callable):
2523
in_json = load_test_data("test_collection.json")
@@ -1693,9 +1691,13 @@ async def test_get_search_link_media(app_client):
16931691
assert get_self_link["type"] == "application/geo+json"
16941692

16951693

1696-
@requires_pgstac_0_9_2
16971694
@pytest.mark.asyncio
16981695
async def test_item_search_freetext(app_client, load_test_data, load_test_collection):
1696+
res = await app_client.get("/_mgmt/health")
1697+
pgstac_version = res.json()["pgstac"]["pgstac_version"]
1698+
if tuple(map(int, pgstac_version.split("."))) < (0, 9, 2):
1699+
pass
1700+
16991701
test_item = load_test_data("test_item.json")
17001702
resp = await app_client.post(
17011703
f"/collections/{test_item['collection']}/items", json=test_item

0 commit comments

Comments
 (0)