Skip to content

Commit 10d612b

Browse files
committed
Review Changes
1 parent 138111b commit 10d612b

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

firestore/google/cloud/firestore_v1beta1/_helpers.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -823,29 +823,29 @@ def process_server_timestamp(document_data, split_on_dots=True):
823823
transform_paths = []
824824
actual_data = {}
825825
for field_name, value in six.iteritems(document_data):
826+
if split_on_dots:
827+
top_level_path = FieldPath(*field_name.split("."))
828+
else:
829+
top_level_path = FieldPath.from_string(field_name)
826830
if isinstance(value, dict):
827831
sub_transform_paths, sub_data, sub_field_paths = (
828832
process_server_timestamp(value, False))
829-
for sub_path in sub_transform_paths:
830-
field_path = FieldPath.from_string(field_name)
831-
field_path.parts = field_path.parts + sub_path.parts
832-
transform_paths.extend([field_path])
833+
for sub_transform_path in sub_transform_paths:
834+
transform_path = FieldPath.from_string(field_name)
835+
transform_path.parts = transform_path.parts + sub_transform_path.parts
836+
transform_paths.extend([transform_path])
833837
if sub_data:
834838
# Only add a key to ``actual_data`` if there is data.
835-
836839
actual_data[field_name] = sub_data
837840
for sub_field_path in sub_field_paths:
838841
field_path = FieldPath.from_string(field_name)
839842
field_path.parts = field_path.parts + sub_field_path.parts
840843
field_paths.append(field_path)
841844
elif value is constants.SERVER_TIMESTAMP:
842-
if split_on_dots:
843-
transform_paths.append(FieldPath(*field_name.split(".")))
844-
else:
845-
transform_paths.append(FieldPath.from_string(field_name))
845+
transform_paths.append(top_level_path)
846846
else:
847847
actual_data[field_name] = value
848-
field_paths.append(FieldPath(field_name))
848+
field_paths.append(top_level_path)
849849
if not transform_paths:
850850
actual_data = document_data
851851
return transform_paths, actual_data, field_paths
@@ -887,9 +887,9 @@ def pbs_for_set(document_path, document_data, merge=False, exists=None):
887887
document_path (str): A fully-qualified document path.
888888
document_data (dict): Property names and values to use for
889889
replacing a document.
890-
option (optional[~.firestore_v1beta1.client.WriteOption]): A
891-
write option to make assertions / preconditions on the server
892-
state of the document before applying changes.
890+
merge (bool): Whether to merge the fields or replace them
891+
exists (bool): If set, a precondition to indicate whether the
892+
document should exist or not. Used for create.
893893
894894
Returns:
895895
List[google.cloud.firestore_v1beta1.types.Write]: One

firestore/google/cloud/firestore_v1beta1/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
DEFAULT_DATABASE = '(default)'
4040
"""str: The default database used in a :class:`~.firestore.client.Client`."""
4141
_BAD_OPTION_ERR = (
42-
'Exactly one of ``last_update_time``, ``exists`` '
43-
'must be provided.')
42+
'Exactly one of ``last_update_time`` or ``exists`` must be provided.')
4443
_BAD_DOC_TEMPLATE = (
4544
'Document {!r} appeared in response but was not present among references')
4645
_ACTIVE_TXN = 'There is already an active transaction.'

firestore/tests/system.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def test_document_set(client, cleanup):
143143
snapshot = document.get()
144144
assert snapshot.to_dict() is None
145145

146-
# 1. Use ``create()`` to create the document (using an option).
146+
# 1. Use ``create()`` to create the document.
147147
data1 = {'foo': 88}
148148
write_result1 = document.create(data1)
149149
snapshot1 = document.get()
@@ -152,7 +152,7 @@ def test_document_set(client, cleanup):
152152
assert snapshot1.create_time == snapshot1.update_time
153153
assert snapshot1.update_time == write_result1.update_time
154154

155-
# 2. Call ``set()`` again to overwrite (no option).
155+
# 2. Call ``set()`` again to overwrite.
156156
data2 = {'bar': None}
157157
write_result2 = document.set(data2)
158158
snapshot2 = document.get()
@@ -203,7 +203,7 @@ def test_document_set_merge(client, cleanup):
203203
snapshot = document.get()
204204
assert not snapshot.exists
205205

206-
# 1. Use ``set()`` to create the document (using an option).
206+
# 1. Use ``create()`` to create the document.
207207
data1 = {'name': 'Sam',
208208
'address': {'city': 'SF',
209209
'state': 'CA'}}

firestore/tests/unit/test_cross_language.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TestCrossLanguage(unittest.TestCase):
2727

2828
def test_cross_language(self):
2929
filenames = sorted(glob.glob('tests/unit/testdata/*.textproto'))
30-
count = 0
30+
failed = 0
3131
descs = []
3232
for test_filename in filenames:
3333
bytes = open(test_filename, 'r').read()
@@ -38,14 +38,14 @@ def test_cross_language(self):
3838
os.path.splitext(os.path.basename(test_filename))[0])
3939
try:
4040
self.run_write_test(test_proto, desc)
41-
except (AssertionError, Exception) as error:
42-
count += 1
41+
except Exception as error:
42+
failed += 1
4343
# print(desc, test_proto) # for debugging
4444
# print(error.args[0]) # for debugging
4545
descs.append(desc)
4646
# for desc in descs: # for debugging
4747
# print(desc) # for debugging
48-
# print(str(count) + "/" + str(len(filenames))) # for debugging
48+
# print(str(failed) + "/" + str(len(filenames))) # for debugging
4949

5050
def run_write_test(self, test_proto, desc):
5151
from google.cloud.firestore_v1beta1.proto import firestore_pb2
@@ -78,10 +78,10 @@ def run_write_test(self, test_proto, desc):
7878
client, doc = self.setup(firestore_api, tp)
7979
data = convert_data(json.loads(tp.json_data))
8080
if tp.HasField("option"):
81-
option = True
81+
merge = True
8282
else:
83-
option = False
84-
call = functools.partial(doc.set, data, option)
83+
merge = False
84+
call = functools.partial(doc.set, data, merge)
8585
elif kind == "update":
8686
tp = test_proto.update
8787
client, doc = self.setup(firestore_api, tp)

0 commit comments

Comments
 (0)