Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d0e7745
WIP: Refactor conformance tests for firestore.
tseaver Oct 23, 2018
0ee56fe
unused imports
mcdonc Oct 23, 2018
d05e97a
fix conformance tests which assert that keys can contain nonalpha cha…
mcdonc Oct 23, 2018
50b58b6
WIP: set conformance not achieved
mcdonc Oct 25, 2018
5587407
Lint.
tseaver Oct 25, 2018
2a3bbd2
checkpoint checkin
mcdonc Oct 26, 2018
1882795
work towards making set tests pass
mcdonc Oct 28, 2018
f32fb45
revert to merge not being an option; instead make it a bool or a list…
mcdonc Oct 28, 2018
29c8dc5
WIP: set conformance tests
mcdonc Oct 30, 2018
3f27b8f
WIP: checkpoint... ArrayDelete, ArrayUnion, and Delete related set te…
mcdonc Oct 30, 2018
4fcdaf6
blacklist conformance tests for transforms we don't yet have
mcdonc Oct 31, 2018
c50fc9c
WIP: traunch of set tests; 3 still fail which, when fixed, break 3 ot…
mcdonc Oct 31, 2018
3fe44ce
blacklist all tests that use features we dont have
mcdonc Oct 31, 2018
d8e8840
reenable all tests
mcdonc Oct 31, 2018
75b74f0
more blacklisted tests for features
mcdonc Oct 31, 2018
61c99f4
fix one test, break another
mcdonc Oct 31, 2018
c64de2a
Remove duplicate testdata files. The removes are as follows,
mcdonc Nov 1, 2018
a926e5c
delete removed testdata files from _MISSING_FEATURES
mcdonc Nov 1, 2018
b0c3442
just import google-cloud-common testdata in from its master instead o…
mcdonc Nov 1, 2018
4c3cd38
no such thing anymore
mcdonc Nov 1, 2018
511580c
write_pb -> update_pb
mcdonc Nov 1, 2018
679fada
re-disable get tests
mcdonc Nov 2, 2018
50e79d5
clean up clowny logic
mcdonc Nov 2, 2018
ad6f4b0
appease flake8
mcdonc Nov 2, 2018
31b3e7a
fix update-exists-precond
mcdonc Nov 2, 2018
8ded2f9
fix test to assert conformance
mcdonc Nov 2, 2018
178cde8
conformance for update when transform is not top-level
mcdonc Nov 3, 2018
1ad7ec9
Add explicit skips for unimplemented transform testprotos.
tseaver Nov 5, 2018
4551ee4
Lint.
tseaver Nov 12, 2018
3ecf0ba
Unit test fix for 'update' change when transform is not top level.
tseaver Nov 12, 2018
6913a59
Factor out write pb logic for create.
tseaver Nov 12, 2018
dec105f
Add parents of transformed fields to mask of initial update PB in set.
tseaver Nov 12, 2018
59b964b
Avoid adding an 'update' pb if there are no actual values.
tseaver Nov 12, 2018
400358e
Blacklist testcases for updates w/ field deletion.
tseaver Nov 12, 2018
f4f0529
Lint
tseaver Nov 12, 2018
fc6fcba
Ajust sys tests: don't passing explicit 'exists' to update.
tseaver Nov 13, 2018
cccdfe4
Explicit coverage for '_helpers.FieldPath'.
tseaver Nov 13, 2018
9d3df11
Explicit coverage for '_helpers.extract_field_paths'.
tseaver Nov 13, 2018
8f8a0b0
Add explicit coverage for '_helpers.parse_field_path'.
tseaver Nov 13, 2018
2f569d4
Move '_helpers.ReadAfterWriteError' exception
tseaver Nov 13, 2018
93cbb23
Expand tests for '_helpers.filter_document_data_by_field_paths'.
tseaver Nov 13, 2018
417bbc2
Explicit coverage for '_helpers.get_field_path'.
tseaver Nov 13, 2018
08bba84
Split out 'pbs_for_set_with_merge' from 'pbs_for_set'.
tseaver Nov 14, 2018
9677e79
Explicit coverage for '_helpers.pbs_for_set_no_merge'.
tseaver Nov 14, 2018
d661a1d
Make 'split_on_dots' arg to 'process_server_timestamp' explicit.
tseaver Nov 14, 2018
70185fa
Factor out the simpler 'merge=True' case into '_helpers.all_merge_pat…
tseaver Nov 14, 2018
845c02a
100% coverage in testcase module.
tseaver Nov 14, 2018
69d5366
Incremental coverage for '_helpers.pbs_for_set_with_merge'.
tseaver Nov 14, 2018
09d3f89
Typo.
tseaver Nov 14, 2018
05bb4df
Coverage for '_helpers.normalize_merge_paths'.
tseaver Nov 14, 2018
581e006
Explicit coverage for '_helpers.pb_for_set_with_merge'.
tseaver Nov 15, 2018
1d0418f
Fix overlong lines introduced in PR #6481.
tseaver Nov 15, 2018
a477308
Coverage for 'DocumentReference.update'.
tseaver Nov 15, 2018
52031e7
Lint
tseaver Nov 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
470 changes: 394 additions & 76 deletions firestore/google/cloud/firestore_v1beta1/_helpers.py

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions firestore/google/cloud/firestore_v1beta1/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def create(self, reference, document_data):
document_data (dict): Property names and values to use for
creating a document.
"""
write_pbs = _helpers.pbs_for_set(
reference._document_path, document_data, merge=False, exists=False)
write_pbs = _helpers.pbs_for_create(
reference._document_path, document_data)
self._add_write_pbs(write_pbs)

def set(self, reference, document_data, merge=False):
Expand All @@ -74,12 +74,17 @@ def set(self, reference, document_data, merge=False):
A document reference that will have values set in this batch.
document_data (dict):
Property names and values to use for replacing a document.
merge (Optional[bool]):
merge (Optional[bool] or Optional[List<apispec>]):
If True, apply merging instead of overwriting the state
of the document.
"""
write_pbs = _helpers.pbs_for_set(
reference._document_path, document_data, merge=merge)
if merge is not False:
write_pbs = _helpers.pbs_for_set_with_merge(
reference._document_path, document_data, merge)
else:
write_pbs = _helpers.pbs_for_set_no_merge(
reference._document_path, document_data)

self._add_write_pbs(write_pbs)

def update(self, reference, field_updates, option=None):
Expand All @@ -98,6 +103,9 @@ def update(self, reference, field_updates, option=None):
write option to make assertions / preconditions on the server
state of the document before applying changes.
"""
if option.__class__.__name__ == 'ExistsOption':
raise ValueError('you must not pass an explicit write option to '
'update.')
write_pbs = _helpers.pbs_for_update(
self._client, reference._document_path, field_updates, option)
self._add_write_pbs(write_pbs)
Expand Down
5 changes: 3 additions & 2 deletions firestore/google/cloud/firestore_v1beta1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* a :class:`~.firestore_v1beta1.client.Client` owns a
:class:`~.firestore_v1beta1.document.DocumentReference`
"""

from google.cloud.client import ClientWithProject

from google.cloud.firestore_v1beta1 import _helpers
Expand All @@ -39,7 +38,9 @@
DEFAULT_DATABASE = '(default)'
"""str: The default database used in a :class:`~.firestore.client.Client`."""
_BAD_OPTION_ERR = (
'Exactly one of ``last_update_time`` or ``exists`` must be provided.')
'Exactly one of ``last_update_time`` or ``exists`` '
'must be provided.'
)
_BAD_DOC_TEMPLATE = (
'Document {!r} appeared in response but was not present among references')
_ACTIVE_TXN = 'There is already an active transaction.'
Expand Down
6 changes: 3 additions & 3 deletions firestore/google/cloud/firestore_v1beta1/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ def set(self, document_data, merge=False):
Args:
document_data (dict): Property names and values to use for
replacing a document.
option (Optional[~.firestore_v1beta1.client.WriteOption]): A
write option to make assertions / preconditions on the server
state of the document before applying changes.
merge (Optional[bool] or Optional[List<apispec>]):
If True, apply merging instead of overwriting the state
of the document.

Returns:
google.cloud.firestore_v1beta1.types.WriteResult: The
Expand Down
13 changes: 7 additions & 6 deletions firestore/google/cloud/firestore_v1beta1/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
from google.cloud.firestore_v1beta1.watch import Watch

_EQ_OP = '=='
_operator_enum = enums.StructuredQuery.FieldFilter.Operator
_COMPARISON_OPERATORS = {
'<': enums.StructuredQuery.FieldFilter.Operator.LESS_THAN,
'<=': enums.StructuredQuery.FieldFilter.Operator.LESS_THAN_OR_EQUAL,
_EQ_OP: enums.StructuredQuery.FieldFilter.Operator.EQUAL,
'>=': enums.StructuredQuery.FieldFilter.Operator.GREATER_THAN_OR_EQUAL,
'>': enums.StructuredQuery.FieldFilter.Operator.GREATER_THAN,
'array_contains': enums.StructuredQuery.FieldFilter.Operator.ARRAY_CONTAINS,
'<': _operator_enum.LESS_THAN,
'<=': _operator_enum.LESS_THAN_OR_EQUAL,
_EQ_OP: _operator_enum.EQUAL,
'>=': _operator_enum.GREATER_THAN_OR_EQUAL,
'>': _operator_enum.GREATER_THAN,
'array_contains': _operator_enum.ARRAY_CONTAINS,
}
_BAD_OP_STRING = 'Operator string {!r} is invalid. Valid choices are: {}.'
_BAD_OP_NAN_NULL = (
Expand Down
9 changes: 3 additions & 6 deletions firestore/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,7 @@ def test_document_integer_field(client, cleanup):
document.create(data1)

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

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

Expand All @@ -327,8 +325,7 @@ def test_update_document(client, cleanup):
},
'other': True,
}
option2 = client.write_option(exists=False)
write_result2 = document.update(data, option=option2)
write_result2 = document.create(data)

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