Skip to content

Commit 4d29c1f

Browse files
authored
Refactor conformance tests. (#6291)
Closes #6290. Breaking change from `firestore-0.30.0`: revert to merge not being an option; instead make it a bool or a list param to `set`. Use 'pytest.mark.parametrize' to create a testcase per textproto file. Blacklist conformance tests for transforms we don't yet have (ArrayDelete, ArrayUnion, and Delete) Re-import google-cloud-common testdata textprotos: discard older, renamed versions.
1 parent 5c4b1d3 commit 4d29c1f

File tree

107 files changed

+1663
-2988
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+1663
-2988
lines changed

‎google/cloud/firestore_v1beta1/_helpers.py

Lines changed: 394 additions & 76 deletions
Large diffs are not rendered by default.

‎google/cloud/firestore_v1beta1/batch.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def create(self, reference, document_data):
5757
document_data (dict): Property names and values to use for
5858
creating a document.
5959
"""
60-
write_pbs = _helpers.pbs_for_set(
61-
reference._document_path, document_data, merge=False, exists=False)
60+
write_pbs = _helpers.pbs_for_create(
61+
reference._document_path, document_data)
6262
self._add_write_pbs(write_pbs)
6363

6464
def set(self, reference, document_data, merge=False):
@@ -74,12 +74,17 @@ def set(self, reference, document_data, merge=False):
7474
A document reference that will have values set in this batch.
7575
document_data (dict):
7676
Property names and values to use for replacing a document.
77-
merge (Optional[bool]):
77+
merge (Optional[bool] or Optional[List<apispec>]):
7878
If True, apply merging instead of overwriting the state
7979
of the document.
8080
"""
81-
write_pbs = _helpers.pbs_for_set(
82-
reference._document_path, document_data, merge=merge)
81+
if merge is not False:
82+
write_pbs = _helpers.pbs_for_set_with_merge(
83+
reference._document_path, document_data, merge)
84+
else:
85+
write_pbs = _helpers.pbs_for_set_no_merge(
86+
reference._document_path, document_data)
87+
8388
self._add_write_pbs(write_pbs)
8489

8590
def update(self, reference, field_updates, option=None):
@@ -98,6 +103,9 @@ def update(self, reference, field_updates, option=None):
98103
write option to make assertions / preconditions on the server
99104
state of the document before applying changes.
100105
"""
106+
if option.__class__.__name__ == 'ExistsOption':
107+
raise ValueError('you must not pass an explicit write option to '
108+
'update.')
101109
write_pbs = _helpers.pbs_for_update(
102110
self._client, reference._document_path, field_updates, option)
103111
self._add_write_pbs(write_pbs)

‎google/cloud/firestore_v1beta1/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
* a :class:`~.firestore_v1beta1.client.Client` owns a
2424
:class:`~.firestore_v1beta1.document.DocumentReference`
2525
"""
26-
2726
from google.cloud.client import ClientWithProject
2827

2928
from google.cloud.firestore_v1beta1 import _helpers
@@ -39,7 +38,9 @@
3938
DEFAULT_DATABASE = '(default)'
4039
"""str: The default database used in a :class:`~.firestore.client.Client`."""
4140
_BAD_OPTION_ERR = (
42-
'Exactly one of ``last_update_time`` or ``exists`` must be provided.')
41+
'Exactly one of ``last_update_time`` or ``exists`` '
42+
'must be provided.'
43+
)
4344
_BAD_DOC_TEMPLATE = (
4445
'Document {!r} appeared in response but was not present among references')
4546
_ACTIVE_TXN = 'There is already an active transaction.'

‎google/cloud/firestore_v1beta1/document.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ def set(self, document_data, merge=False):
211211
Args:
212212
document_data (dict): Property names and values to use for
213213
replacing a document.
214-
option (Optional[~.firestore_v1beta1.client.WriteOption]): A
215-
write option to make assertions / preconditions on the server
216-
state of the document before applying changes.
214+
merge (Optional[bool] or Optional[List<apispec>]):
215+
If True, apply merging instead of overwriting the state
216+
of the document.
217217
218218
Returns:
219219
google.cloud.firestore_v1beta1.types.WriteResult: The

‎tests/system.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ def test_document_integer_field(client, cleanup):
202202
document.create(data1)
203203

204204
data2 = {'1a.ab': '4d', '6f.7g': '9h'}
205-
option2 = client.write_option(exists=True)
206-
document.update(data2, option=option2)
205+
document.update(data2)
207206
snapshot = document.get()
208207
expected = {
209208
'1a': {
@@ -311,9 +310,8 @@ def test_update_document(client, cleanup):
311310
assert document_id in exc_info.value.message
312311

313312
# 1. Try to update before the document exists (now with an option).
314-
option1 = client.write_option(exists=True)
315313
with pytest.raises(NotFound) as exc_info:
316-
document.update({'still': 'not-there'}, option=option1)
314+
document.update({'still': 'not-there'})
317315
assert exc_info.value.message.startswith(MISSING_DOCUMENT)
318316
assert document_id in exc_info.value.message
319317

@@ -327,8 +325,7 @@ def test_update_document(client, cleanup):
327325
},
328326
'other': True,
329327
}
330-
option2 = client.write_option(exists=False)
331-
write_result2 = document.update(data, option=option2)
328+
write_result2 = document.create(data)
332329

333330
# 3. Send an update without a field path (no option).
334331
field_updates3 = {'foo': {'quux': 800}}

0 commit comments

Comments
 (0)