Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

Commit f9687a0

Browse files
committed
add unit tests
1 parent 59fa92a commit f9687a0

1 file changed

Lines changed: 49 additions & 10 deletions

File tree

tests/unit/v1/test_base_query.py

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,19 +2116,58 @@ def test__query_pipeline_order_sorts():
21162116
assert sort_stage.orders[1].order_dir == expr.Ordering.Direction.DESCENDING
21172117

21182118

2119-
def test__query_pipeline_unsupported():
2119+
def test__query_pipeline_cursors():
21202120
client = make_client()
2121-
query_start = client.collection("my_col").start_at({"field_a": "value"})
2122-
with pytest.raises(NotImplementedError, match="cursors"):
2123-
query_start._build_pipeline(client.pipeline())
2121+
query_start = (
2122+
client.collection("my_col").order_by("field_a").start_at({"field_a": "value"})
2123+
)
2124+
pipeline = query_start._build_pipeline(client.pipeline())
2125+
assert len(pipeline.stages) >= 2
2126+
2127+
query_end = (
2128+
client.collection("my_col").order_by("field_a").end_at({"field_a": "value"})
2129+
)
2130+
pipeline = query_end._build_pipeline(client.pipeline())
2131+
assert len(pipeline.stages) >= 2
21242132

2125-
query_end = client.collection("my_col").end_at({"field_a": "value"})
2126-
with pytest.raises(NotImplementedError, match="cursors"):
2127-
query_end._build_pipeline(client.pipeline())
21282133

2129-
query_limit_last = client.collection("my_col").limit_to_last(10)
2130-
with pytest.raises(NotImplementedError, match="limit_to_last"):
2131-
query_limit_last._build_pipeline(client.pipeline())
2134+
def test__query_pipeline_limit_to_last():
2135+
from google.cloud.firestore_v1 import pipeline_expressions as expr
2136+
2137+
client = make_client()
2138+
query_limit_last = (
2139+
client.collection("my_col").order_by("field_a").limit_to_last(10)
2140+
)
2141+
pipeline = query_limit_last._build_pipeline(client.pipeline())
2142+
# stages: collection, exists, sort(desc), limit, sort(asc)
2143+
2144+
assert len(pipeline.stages) == 5
2145+
2146+
# 0. Collection
2147+
assert pipeline.stages[0].path == "/my_col"
2148+
2149+
# 1. Exists
2150+
exists_stage = pipeline.stages[1]
2151+
assert isinstance(exists_stage, stages.Where)
2152+
2153+
# 2. Sort DESCENDING (reversed)
2154+
sort_desc = pipeline.stages[2]
2155+
assert isinstance(sort_desc, stages.Sort)
2156+
assert len(sort_desc.orders) == 1
2157+
assert sort_desc.orders[0].expr.path == "field_a"
2158+
assert sort_desc.orders[0].order_dir == expr.Ordering.Direction.DESCENDING
2159+
2160+
# 3. Limit
2161+
limit_stage = pipeline.stages[3]
2162+
assert isinstance(limit_stage, stages.Limit)
2163+
assert limit_stage.limit == 10
2164+
2165+
# 4. Sort ASCENDING (original)
2166+
sort_asc = pipeline.stages[4]
2167+
assert isinstance(sort_asc, stages.Sort)
2168+
assert len(sort_asc.orders) == 1
2169+
assert sort_asc.orders[0].expr.path == "field_a"
2170+
assert sort_asc.orders[0].order_dir == expr.Ordering.Direction.ASCENDING
21322171

21332172

21342173
def test__query_pipeline_limit():

0 commit comments

Comments
 (0)