@@ -191,11 +191,21 @@ def test__parent_info_nested(self):
191
191
192
192
def test_add_auto_assigned (self ):
193
193
from google .cloud .firestore_v1beta1 .proto import document_pb2
194
- from google .cloud .firestore_v1beta1 import _helpers
195
194
from google .cloud .firestore_v1beta1 .document import DocumentReference
195
+ from google .cloud .firestore_v1beta1 import SERVER_TIMESTAMP
196
+ from google .cloud .firestore_v1beta1 ._helpers import pbs_for_set_no_merge
196
197
197
198
# Create a minimal fake GAPIC add attach it to a real client.
198
- firestore_api = mock .Mock (spec = ["create_document" ])
199
+ firestore_api = mock .Mock (spec = ["create_document" , "commit" ])
200
+ write_result = mock .Mock (
201
+ update_time = mock .sentinel .update_time , spec = ["update_time" ]
202
+ )
203
+ commit_response = mock .Mock (
204
+ write_results = [write_result ],
205
+ spec = ["write_results" , "commit_time" ],
206
+ commit_time = mock .sentinel .commit_time ,
207
+ )
208
+ firestore_api .commit .return_value = commit_response
199
209
create_doc_response = document_pb2 .Document ()
200
210
firestore_api .create_document .return_value = create_doc_response
201
211
client = _make_client ()
@@ -212,20 +222,19 @@ def test_add_auto_assigned(self):
212
222
create_doc_response .update_time .FromDatetime (datetime .datetime .utcnow ())
213
223
firestore_api .create_document .return_value = create_doc_response
214
224
215
- # Actually call add() on our collection.
216
- document_data = {"been" : "here" }
225
+ # Actually call add() on our collection; include a transform to make
226
+ # sure transforms during adds work.
227
+ document_data = {"been" : "here" , "now" : SERVER_TIMESTAMP }
217
228
update_time , document_ref = collection .add (document_data )
218
229
219
230
# Verify the response and the mocks.
220
- self .assertIs (update_time , create_doc_response .update_time )
231
+ self .assertIs (update_time , mock . sentinel .update_time )
221
232
self .assertIsInstance (document_ref , DocumentReference )
222
233
self .assertIs (document_ref ._client , client )
223
234
expected_path = collection ._path + (auto_assigned_id ,)
224
235
self .assertEqual (document_ref ._path , expected_path )
225
236
226
- expected_document_pb = document_pb2 .Document (
227
- fields = _helpers .encode_dict (document_data )
228
- )
237
+ expected_document_pb = document_pb2 .Document ()
229
238
firestore_api .create_document .assert_called_once_with (
230
239
parent_path ,
231
240
collection_id = collection .id ,
@@ -234,6 +243,13 @@ def test_add_auto_assigned(self):
234
243
mask = None ,
235
244
metadata = client ._rpc_metadata ,
236
245
)
246
+ write_pbs = pbs_for_set_no_merge (document_ref ._document_path , document_data )
247
+ firestore_api .commit .assert_called_once_with (
248
+ client ._database_string ,
249
+ write_pbs ,
250
+ transaction = None ,
251
+ metadata = client ._rpc_metadata ,
252
+ )
237
253
238
254
@staticmethod
239
255
def _write_pb_for_create (document_path , document_data ):
0 commit comments