@@ -196,7 +196,8 @@ def test_notify_rfc_published(self, mock_task_delay):
196196 self .assertEqual (mock_kwargs ["rfc_number_list" ], expected_rfc_number_list )
197197
198198 @override_settings (APP_API_TOKENS = {"ietf.api.views_rpc" : ["valid-token" ]})
199- def test_upload_rfc_files (self ):
199+ @mock .patch ("ietf.api.views_rpc.update_rfc_searchindex_task" )
200+ def test_upload_rfc_files (self , mock_update_searchindex_task ):
200201 def _valid_post_data ():
201202 """Generate a valid post data dict
202203
@@ -217,14 +218,7 @@ def _valid_post_data():
217218 }
218219
219220 url = urlreverse ("ietf.api.purple_api.upload_rfc_files" )
220- unused_rfc_number = (
221- Document .objects .filter (rfc_number__isnull = False ).aggregate (
222- unused_rfc_number = Max ("rfc_number" ) + 1
223- )["unused_rfc_number" ]
224- or 10000
225- )
226-
227- rfc = WgRfcFactory (rfc_number = unused_rfc_number )
221+ rfc = WgRfcFactory ()
228222 assert isinstance (rfc , Document ), "WgRfcFactory should generate a Document"
229223 with TemporaryDirectory () as rfc_dir :
230224 settings .RFC_PATH = rfc_dir # affects overridden settings
@@ -236,15 +230,17 @@ def _valid_post_data():
236230 # no api key
237231 r = self .client .post (url , _valid_post_data (), format = "multipart" )
238232 self .assertEqual (r .status_code , 403 )
233+ self .assertFalse (mock_update_searchindex_task .delay .called )
239234
240235 # invalid RFC
241236 r = self .client .post (
242237 url ,
243- _valid_post_data () | {"rfc" : unused_rfc_number + 1 },
238+ _valid_post_data () | {"rfc" : rfc . rfc_number + 10 },
244239 format = "multipart" ,
245240 headers = {"X-Api-Key" : "valid-token" },
246241 )
247242 self .assertEqual (r .status_code , 400 )
243+ self .assertFalse (mock_update_searchindex_task .delay .called )
248244
249245 # empty files
250246 r = self .client .post (
@@ -263,6 +259,7 @@ def _valid_post_data():
263259 headers = {"X-Api-Key" : "valid-token" },
264260 )
265261 self .assertEqual (r .status_code , 400 )
262+ self .assertFalse (mock_update_searchindex_task .delay .called )
266263
267264 # bad file type
268265 r = self .client .post (
@@ -276,9 +273,10 @@ def _valid_post_data():
276273 headers = {"X-Api-Key" : "valid-token" },
277274 )
278275 self .assertEqual (r .status_code , 400 )
276+ self .assertFalse (mock_update_searchindex_task .delay .called )
279277
280278 # Put a file in the way. Post should fail because replace = False
281- file_in_the_way = (rfc_path / f"rfc { unused_rfc_number } .txt" )
279+ file_in_the_way = (rfc_path / f"{ rfc . name } .txt" )
282280 file_in_the_way .touch ()
283281 r = self .client .post (
284282 url ,
@@ -287,11 +285,12 @@ def _valid_post_data():
287285 headers = {"X-Api-Key" : "valid-token" },
288286 )
289287 self .assertEqual (r .status_code , 409 ) # conflict
288+ self .assertFalse (mock_update_searchindex_task .delay .called )
290289 file_in_the_way .unlink ()
291290
292291 # Put a blob in the way. Post should fail because replace = False
293292 blob_in_the_way = Blob .objects .create (
294- bucket = "rfc" , name = f"txt/rfc { unused_rfc_number } .txt" , content = b""
293+ bucket = "rfc" , name = f"txt/{ rfc . name } .txt" , content = b""
295294 )
296295 r = self .client .post (
297296 url ,
@@ -300,6 +299,7 @@ def _valid_post_data():
300299 headers = {"X-Api-Key" : "valid-token" },
301300 )
302301 self .assertEqual (r .status_code , 409 ) # conflict
302+ self .assertFalse (mock_update_searchindex_task .delay .called )
303303 blob_in_the_way .delete ()
304304
305305 # valid post
@@ -310,8 +310,13 @@ def _valid_post_data():
310310 headers = {"X-Api-Key" : "valid-token" },
311311 )
312312 self .assertEqual (r .status_code , 200 )
313+ self .assertTrue (mock_update_searchindex_task .delay .called )
314+ self .assertEqual (
315+ mock_update_searchindex_task .delay .call_args ,
316+ mock .call (rfc .rfc_number ),
317+ )
313318 for extension in ["xml" , "txt" , "html" , "pdf" , "json" ]:
314- filename = f"rfc { unused_rfc_number } .{ extension } "
319+ filename = f"{ rfc . name } .{ extension } "
315320 self .assertEqual (
316321 (rfc_path / filename )
317322 .read_text (),
@@ -328,7 +333,7 @@ def _valid_post_data():
328333 f"{ extension } blob should contain the expected content" ,
329334 )
330335 # special case for notprepped
331- notprepped_fn = f"rfc { unused_rfc_number } .notprepped.xml"
336+ notprepped_fn = f"{ rfc . name } .notprepped.xml"
332337 self .assertEqual (
333338 (
334339 rfc_path / "prerelease" / notprepped_fn
@@ -347,22 +352,29 @@ def _valid_post_data():
347352 )
348353
349354 # re-post with replace = False should now fail
355+ mock_update_searchindex_task .reset_mock ()
350356 r = self .client .post (
351357 url ,
352358 _valid_post_data (),
353359 format = "multipart" ,
354360 headers = {"X-Api-Key" : "valid-token" },
355361 )
356362 self .assertEqual (r .status_code , 409 ) # conflict
357-
363+ self .assertFalse (mock_update_searchindex_task .delay .called )
364+
358365 # re-post with replace = True should succeed
359366 r = self .client .post (
360367 url ,
361368 _valid_post_data () | {"replace" : True },
362369 format = "multipart" ,
363370 headers = {"X-Api-Key" : "valid-token" },
364371 )
365- self .assertEqual (r .status_code , 200 ) # conflict
372+ self .assertEqual (r .status_code , 200 )
373+ self .assertTrue (mock_update_searchindex_task .delay .called )
374+ self .assertEqual (
375+ mock_update_searchindex_task .delay .call_args ,
376+ mock .call (rfc .rfc_number ),
377+ )
366378
367379 @override_settings (APP_API_TOKENS = {"ietf.api.views_rpc" : ["valid-token" ]})
368380 @mock .patch ("ietf.api.views_rpc.create_rfc_index_task" )
0 commit comments