Skip to content

Commit ea72219

Browse files
Feat: add tests for loading queryables with hyphenated collection names
1 parent 38e757f commit ea72219

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

src/pypgstac/tests/test_queryables.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,117 @@ def test_load_queryables_create_missing_collections(db: PgstacDB) -> None:
584584
for queryable in queryables:
585585
assert set(queryable["collection_ids"]) == set(non_existent_collections)
586586

587+
def test_load_queryables_with_multiple_hyphenated_collections(db: PgstacDB) -> None:
588+
"""Test loading queryables for multiple collections with hyphenated names."""
589+
# Create a CLI instance
590+
cli = PgstacCLI(dsn=db.dsn)
591+
592+
# Create collections with hyphenated names
593+
hyphenated_collections = [
594+
"test-collection-1",
595+
"my-hyphenated-collection-2",
596+
"another-test-collection-3",
597+
]
598+
cli.load_queryables(
599+
str(TEST_QUERYABLES_JSON),
600+
collection_ids=hyphenated_collections,
601+
create_missing_collections=True,
602+
index_fields=["test:string_prop", "test:number_prop"],
603+
)
604+
605+
# Verify that all collections were created
606+
result = db.query(
607+
"""
608+
SELECT id FROM collections WHERE id = ANY(%s);
609+
""",
610+
[hyphenated_collections],
611+
)
612+
collections = [row[0] for row in result]
613+
assert len(collections) == len(hyphenated_collections)
614+
assert set(collections) == set(hyphenated_collections)
615+
616+
# Verify that queryables were loaded for all collections
617+
result = db.query(
618+
"""
619+
SELECT name, collection_ids, property_index_type
620+
FROM queryables
621+
WHERE name LIKE 'test:%%'
622+
AND collection_ids @> %s
623+
ORDER BY name;
624+
""",
625+
[hyphenated_collections],
626+
)
627+
628+
# Convert result to a list of dictionaries
629+
queryables = [
630+
{"name": row[0], "collection_ids": row[1], "property_index_type": row[2]}
631+
for row in result
632+
]
633+
634+
# Check that all queryables were created and associated with all collections
635+
assert len(queryables) == 5 # All test properties should be present
636+
for queryable in queryables:
637+
# Verify all collections are associated with each queryable
638+
assert set(hyphenated_collections).issubset(set(queryable["collection_ids"]))
639+
# Check that only specified properties have indexes
640+
if queryable["name"] in ["test:string_prop", "test:number_prop"]:
641+
assert queryable["property_index_type"] == "BTREE"
642+
else:
643+
assert queryable["property_index_type"] is None
644+
645+
def test_load_queryables_with_hyphenated_collection(db: PgstacDB) -> None:
646+
"""Test loading queryables for a collection with a hyphenated name."""
647+
# Create a CLI instance
648+
cli = PgstacCLI(dsn=db.dsn)
649+
650+
# Create a collection with a hyphenated name
651+
hyphenated_collection = "test-collection-with-hyphens"
652+
cli.load_queryables(
653+
str(TEST_QUERYABLES_JSON),
654+
collection_ids=[hyphenated_collection],
655+
create_missing_collections=True,
656+
index_fields=["test:string_prop"],
657+
)
658+
659+
# Verify that the collection was created
660+
result = db.query(
661+
"""
662+
SELECT id FROM collections WHERE id = %s;
663+
""",
664+
[hyphenated_collection],
665+
)
666+
collections = [row[0] for row in result]
667+
assert len(collections) == 1
668+
assert collections[0] == hyphenated_collection
669+
670+
# Verify that queryables were loaded for this collection
671+
result = db.query(
672+
"""
673+
SELECT name, collection_ids, property_index_type
674+
FROM queryables
675+
WHERE name LIKE 'test:%%'
676+
AND %s = ANY(collection_ids)
677+
ORDER BY name;
678+
""",
679+
[hyphenated_collection],
680+
)
681+
682+
# Convert result to a list of dictionaries
683+
queryables = [
684+
{"name": row[0], "collection_ids": row[1], "property_index_type": row[2]}
685+
for row in result
686+
]
687+
688+
# Check that all queryables were created and associated with the collection
689+
assert len(queryables) == 5 # All test properties should be present
690+
for queryable in queryables:
691+
assert hyphenated_collection in queryable["collection_ids"]
692+
# Check that only test:string_prop has an index
693+
if queryable["name"] == "test:string_prop":
694+
assert queryable["property_index_type"] == "BTREE"
695+
else:
696+
assert queryable["property_index_type"] is None
697+
587698
def test_load_queryables_no_properties(db: PgstacDB) -> None:
588699
"""Test loading queryables with no properties."""
589700
# Create a CLI instance

0 commit comments

Comments
 (0)