Skip to content

Commit 513a4da

Browse files
committed
fix system test
1 parent d5f0db0 commit 513a4da

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

google/cloud/firestore_v1/base_pipeline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,12 @@ def find_nearest(
275275

276276
def literals(
277277
self,
278-
documents: Selectable,
278+
*documents: Selectable,
279279
) -> "_BasePipeline":
280280
"""
281281
TODO: add docstring.
282282
"""
283-
return self._append(stages.Literals(documents))
283+
return self._append(stages.Literals(*documents))
284284

285285
def replace_with(
286286
self,

google/cloud/firestore_v1/pipeline_stages.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,18 @@ def _pb_args(self):
345345
class Literals(Stage):
346346
"""TODO: add docstring."""
347347

348-
def __init__(self, documents: Selectable):
348+
def __init__(self, *documents: Selectable):
349349
super().__init__("literals")
350-
self.documents = Field(documents) if isinstance(documents, str) else documents
350+
self.documents = documents
351351

352352
def _pb_args(self):
353-
return [self.documents._to_pb()]
353+
args = []
354+
for doc in self.documents:
355+
if hasattr(doc, "_to_pb"):
356+
args.append(doc._to_pb())
357+
else:
358+
args.append(encode_value(doc))
359+
return args
354360

355361

356362
class Offset(Stage):

tests/system/pipeline_e2e/general.yaml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -688,23 +688,20 @@ tests:
688688
- description: literals
689689
pipeline:
690690
- Literals:
691-
- Constant:
692-
- title: "The Hitchhiker's Guide to the Galaxy"
693-
author: "Douglas Adams"
691+
- title: "The Hitchhiker's Guide to the Galaxy"
692+
author: "Douglas Adams"
694693
assert_results:
695694
- title: "The Hitchhiker's Guide to the Galaxy"
696695
author: "Douglas Adams"
697696
assert_proto:
698697
pipeline:
699698
stages:
700699
- args:
701-
- arrayValue:
702-
values:
703-
- mapValue:
704-
fields:
705-
author:
706-
stringValue: "Douglas Adams"
707-
title:
708-
stringValue: "The Hitchhiker's Guide to the Galaxy"
700+
- mapValue:
701+
fields:
702+
author:
703+
stringValue: "Douglas Adams"
704+
title:
705+
stringValue: "The Hitchhiker's Guide to the Galaxy"
709706
name: literals
710707

tests/unit/v1/test_pipeline_stages.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -521,24 +521,27 @@ def _make_one(self, *args, **kwargs):
521521
return stages.Literals(*args, **kwargs)
522522

523523
def test_ctor(self):
524-
val = Constant.of({"a": 1})
525-
instance = self._make_one(val)
526-
assert instance.documents == val
524+
val1 = Constant.of({"a": 1})
525+
val2 = Constant.of({"b": 2})
526+
instance = self._make_one(val1, val2)
527+
assert instance.documents == (val1, val2)
527528
assert instance.name == "literals"
528529

529530
def test_repr(self):
530-
val = Constant.of({"a": 1})
531-
instance = self._make_one(val)
531+
val1 = Constant.of({"a": 1})
532+
instance = self._make_one(val1)
532533
repr_str = repr(instance)
533-
assert repr_str == "Literals(documents=Constant.of({'a': 1}))"
534+
assert repr_str == "Literals(documents=(Constant.of({'a': 1}),))"
534535

535536
def test_to_pb(self):
536-
val = Constant.of({"a": 1})
537-
instance = self._make_one(val)
537+
val1 = Constant.of({"a": 1})
538+
val2 = Constant.of({"b": 2})
539+
instance = self._make_one(val1, val2)
538540
result = instance._to_pb()
539541
assert result.name == "literals"
540-
assert len(result.args) == 1
542+
assert len(result.args) == 2
541543
assert result.args[0].map_value.fields["a"].integer_value == 1
544+
assert result.args[1].map_value.fields["b"].integer_value == 2
542545
assert len(result.options) == 0
543546

544547

0 commit comments

Comments
 (0)