@@ -143,10 +143,9 @@ def test_document_set(client, cleanup):
143143 snapshot = document .get ()
144144 assert snapshot .to_dict () is None
145145
146- # 1. Use ``set ()`` to create the document (using an option).
146+ # 1. Use ``create ()`` to create the document (using an option).
147147 data1 = {'foo' : 88 }
148- option1 = client .write_option (exists = False )
149- write_result1 = document .set (data1 , option = option1 )
148+ write_result1 = document .create (data1 )
150149 snapshot1 = document .get ()
151150 assert snapshot1 .to_dict () == data1
152151 # Make sure the update is what created the document.
@@ -162,30 +161,6 @@ def test_document_set(client, cleanup):
162161 assert snapshot2 .create_time == snapshot1 .create_time
163162 assert snapshot2 .update_time == write_result2 .update_time
164163
165- # 3. Call ``set()`` with a valid "last timestamp" option.
166- data3 = {'skates' : 88 }
167- option3 = client .write_option (last_update_time = snapshot2 .update_time )
168- write_result3 = document .set (data3 , option = option3 )
169- snapshot3 = document .get ()
170- assert snapshot3 .to_dict () == data3
171- # Make sure the create time hasn't changed.
172- assert snapshot3 .create_time == snapshot1 .create_time
173- assert snapshot3 .update_time == write_result3 .update_time
174-
175- # 4. Call ``set()`` with invalid (in the past) "last timestamp" option.
176- assert_timestamp_less (option3 ._last_update_time , snapshot3 .update_time )
177- with pytest .raises (FailedPrecondition ):
178- document .set ({'bad' : 'time-past' }, option = option3 )
179-
180- # 5. Call ``set()`` with invalid (in the future) "last timestamp" option.
181- timestamp_pb = timestamp_pb2 .Timestamp (
182- seconds = snapshot3 .update_time .nanos + 120 ,
183- nanos = snapshot3 .update_time .nanos ,
184- )
185- option5 = client .write_option (last_update_time = timestamp_pb )
186- with pytest .raises (FailedPrecondition ):
187- document .set ({'bad' : 'time-future' }, option = option5 )
188-
189164
190165def test_document_integer_field (client , cleanup ):
191166 document_id = 'for-set' + unique_resource_id ('-' )
@@ -201,8 +176,7 @@ def test_document_integer_field(client, cleanup):
201176 '7g' : '8h' ,
202177 'cd' : '0j' }
203178 }
204- option1 = client .write_option (exists = False )
205- document .set (data1 , option = option1 )
179+ document .create (data1 )
206180
207181 data2 = {'1a.ab' : '4d' , '6f.7g' : '9h' }
208182 option2 = client .write_option (exists = True )
@@ -225,30 +199,24 @@ def test_document_set_merge(client, cleanup):
225199 # Add to clean-up before API request (in case ``set()`` fails).
226200 cleanup (document )
227201
228- # 0. Make sure the document doesn't exist yet using an option.
229- option0 = client .write_option (exists = True )
230- with pytest .raises (NotFound ) as exc_info :
231- document .set ({'no' : 'way' }, option = option0 )
232-
233- assert exc_info .value .message .startswith (MISSING_DOCUMENT )
234- assert document_id in exc_info .value .message
202+ # 0. Make sure the document doesn't exist yet
203+ snapshot = document .get ()
204+ assert not snapshot .exists
235205
236206 # 1. Use ``set()`` to create the document (using an option).
237207 data1 = {'name' : 'Sam' ,
238208 'address' : {'city' : 'SF' ,
239209 'state' : 'CA' }}
240- option1 = client .write_option (exists = False )
241- write_result1 = document .set (data1 , option = option1 )
210+ write_result1 = document .create (data1 )
242211 snapshot1 = document .get ()
243212 assert snapshot1 .to_dict () == data1
244213 # Make sure the update is what created the document.
245214 assert snapshot1 .create_time == snapshot1 .update_time
246215 assert snapshot1 .update_time == write_result1 .update_time
247216
248- # 2. Call ``set()`` again to overwrite (no option).
217+ # 2. Call ``set()`` to merge
249218 data2 = {'address' : {'city' : 'LA' }}
250- option2 = client .write_option (merge = True )
251- write_result2 = document .set (data2 , option = option2 )
219+ write_result2 = document .set (data2 , merge = True )
252220 snapshot2 = document .get ()
253221 assert snapshot2 .to_dict () == {'name' : 'Sam' ,
254222 'address' : {'city' : 'LA' ,
@@ -333,7 +301,7 @@ def test_update_document(client, cleanup):
333301 )
334302 option6 = client .write_option (last_update_time = timestamp_pb )
335303 with pytest .raises (FailedPrecondition ) as exc_info :
336- document .set ({'bad' : 'time-future' }, option = option6 )
304+ document .update ({'bad' : 'time-future' }, option = option6 )
337305
338306
339307def check_snapshot (snapshot , document , data , write_result ):
0 commit comments