Skip to content

Commit 54685a8

Browse files
committed
added asssert_results to e2e tests
1 parent 1d4cf17 commit 54685a8

File tree

3 files changed

+150
-21
lines changed

3 files changed

+150
-21
lines changed

packages/google-cloud-firestore/google/cloud/firestore_v1/pipeline_stages.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,7 @@ def __init__(
152152
in this search stage.
153153
language_code (Optional[str]): The BCP-47 language code of text in the search query, such as "en-US" or "sr-Latn".
154154
"""
155-
if isinstance(query, str):
156-
self.query = DocumentMatches(query)
157-
else:
158-
self.query = query
155+
self.query = DocumentMatches(query) if isinstance(query, str) else query
159156
self.limit = limit
160157
self.retrieval_depth = retrieval_depth
161158
self.sort = [sort] if isinstance(sort, Ordering) else sort

packages/google-cloud-firestore/tests/system/pipeline_e2e/search.yaml

Lines changed: 149 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,33 @@ tests:
44
- Collection: books
55
- Search:
66
- SearchOptions:
7-
query: "technology"
7+
query: "science"
88
limit: 2
9+
assert_results:
10+
- title: "Dune"
11+
author: "Frank Herbert"
12+
genre: "Science Fiction"
13+
published: 1965
14+
rating: 4.6
15+
tags:
16+
- politics
17+
- desert
18+
- adventure
19+
awards:
20+
hugo: true
21+
nebula: true
22+
- title: "The Hitchhiker's Guide to the Galaxy"
23+
author: "Douglas Adams"
24+
genre: "Science Fiction"
25+
published: 1979
26+
rating: 4.2
27+
tags:
28+
- comedy
29+
- space
30+
- adventure
31+
awards:
32+
hugo: true
33+
nebula: false
934
assert_proto:
1035
pipeline:
1136
stages:
@@ -31,9 +56,22 @@ tests:
3156
- Constant: "science"
3257
limit: 5
3358
retrieval_depth: 10
34-
offset: 2
59+
offset: 1
3560
query_enhancement: disabled
3661
language_code: en
62+
assert_results:
63+
- title: "The Hitchhiker's Guide to the Galaxy"
64+
author: "Douglas Adams"
65+
genre: "Science Fiction"
66+
published: 1979
67+
rating: 4.2
68+
tags:
69+
- comedy
70+
- space
71+
- adventure
72+
awards:
73+
hugo: true
74+
nebula: false
3775
assert_proto:
3876
pipeline:
3977
stages:
@@ -47,7 +85,7 @@ tests:
4785
retrieval_depth:
4886
integerValue: '10'
4987
offset:
50-
integerValue: '2'
88+
integerValue: '1'
5189
query_enhancement:
5290
stringValue: "disabled"
5391
language_code:
@@ -57,7 +95,7 @@ tests:
5795
args:
5896
- stringValue: "science"
5997
name: document_matches
60-
- description: search_stage_with_sort_and_select
98+
- description: search_stage_with_sort_and_add_fields
6199
pipeline:
62100
- Collection: books
63101
- Search:
@@ -67,14 +105,44 @@ tests:
67105
Ordering:
68106
- Field: rating
69107
- DESCENDING
70-
select:
71-
- title
72108
add_fields:
73109
- AliasedExpression:
74110
- FunctionExpression.string_concat:
75111
- Field: title
76112
- Constant: " - Selected"
77113
- "title_selected"
114+
- AliasedExpression:
115+
- Score: []
116+
- "search_score"
117+
assert_results:
118+
- title: "Dune"
119+
author: "Frank Herbert"
120+
genre: "Science Fiction"
121+
published: 1965
122+
rating: 4.6
123+
tags:
124+
- politics
125+
- desert
126+
- adventure
127+
awards:
128+
hugo: true
129+
nebula: true
130+
title_selected: "Dune - Selected"
131+
search_score: 0.0
132+
- title: "The Hitchhiker's Guide to the Galaxy"
133+
author: "Douglas Adams"
134+
genre: "Science Fiction"
135+
published: 1979
136+
rating: 4.2
137+
tags:
138+
- comedy
139+
- space
140+
- adventure
141+
awards:
142+
hugo: true
143+
nebula: false
144+
title_selected: "The Hitchhiker's Guide to the Galaxy - Selected"
145+
search_score: 0.0
78146
assert_proto:
79147
pipeline:
80148
stages:
@@ -97,11 +165,6 @@ tests:
97165
stringValue: descending
98166
expression:
99167
fieldReferenceValue: rating
100-
select:
101-
mapValue:
102-
fields:
103-
title:
104-
fieldReferenceValue: title
105168
add_fields:
106169
mapValue:
107170
fields:
@@ -111,6 +174,9 @@ tests:
111174
- fieldReferenceValue: title
112175
- stringValue: " - Selected"
113176
name: string_concat
177+
search_score:
178+
functionValue:
179+
name: score
114180
- description: expression_between
115181
pipeline:
116182
- Collection: books
@@ -130,6 +196,41 @@ tests:
130196
- title: One Hundred Years of Solitude
131197
- title: The Lord of the Rings
132198
- title: To Kill a Mockingbird
199+
assert_proto:
200+
pipeline:
201+
stages:
202+
- args:
203+
- referenceValue: /books
204+
name: collection
205+
- args:
206+
- functionValue:
207+
args:
208+
- functionValue:
209+
args:
210+
- fieldReferenceValue: published
211+
- integerValue: '1950'
212+
name: greater_than_or_equal
213+
- functionValue:
214+
args:
215+
- fieldReferenceValue: published
216+
- integerValue: '1970'
217+
name: less_than_or_equal
218+
name: and
219+
name: where
220+
- args:
221+
- mapValue:
222+
fields:
223+
title:
224+
fieldReferenceValue: title
225+
name: select
226+
- args:
227+
- mapValue:
228+
fields:
229+
direction:
230+
stringValue: ascending
231+
expression:
232+
fieldReferenceValue: title
233+
name: sort
133234
- description: expression_geo_distance
134235
pipeline:
135236
- Collection: geopoints
@@ -138,8 +239,8 @@ tests:
138239
query:
139240
FunctionExpression.less_than:
140241
- FunctionExpression.geo_distance:
141-
- Field: location
142-
- Constant: GEOPOINT(37.0,-122.0)
242+
- Field: location
243+
- GeoPoint: [37.0, -122.0]
143244
- Constant: 150000.0
144245
- Select:
145246
- name
@@ -148,4 +249,38 @@ tests:
148249
- Field: name
149250
- ASCENDING
150251
assert_results:
151-
- name: SF
252+
- name: SF
253+
assert_proto:
254+
pipeline:
255+
stages:
256+
- args:
257+
- referenceValue: /geopoints
258+
name: collection
259+
- name: search
260+
options:
261+
query:
262+
functionValue:
263+
args:
264+
- functionValue:
265+
args:
266+
- fieldReferenceValue: location
267+
- geoPointValue:
268+
latitude: 37.0
269+
longitude: -122.0
270+
name: geo_distance
271+
- doubleValue: 150000.0
272+
name: less_than
273+
- args:
274+
- mapValue:
275+
fields:
276+
name:
277+
fieldReferenceValue: name
278+
name: select
279+
- args:
280+
- mapValue:
281+
fields:
282+
direction:
283+
stringValue: ascending
284+
expression:
285+
fieldReferenceValue: name
286+
name: sort

packages/google-cloud-firestore/tests/system/test_pipeline_acceptance.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,6 @@ def _parse_yaml_types(data):
352352
return parsed_datetime
353353
except ValueError:
354354
pass
355-
if isinstance(data, str) and data.startswith("GEOPOINT("):
356-
parts = data[9:-1].split(",")
357-
return GeoPoint(float(parts[0]), float(parts[1]))
358355
if data == "NaN":
359356
return float("NaN")
360357
return data

0 commit comments

Comments
 (0)