@@ -361,6 +361,50 @@ def test_reset_notification(self, urlopen):
361361 self .assert_make_post_request (request )
362362 self .assert_quay_token_included (request )
363363
364+ @patch .dict (os .environ , {"QUAY_TOKEN" : QUAY_TOKEN })
365+ @patch ("sys.argv" , ["reset_notifications" , "--namespace" , "sample" ])
366+ @patch ("reset_notifications.urlopen" )
367+ def test_get_notifications_http_error_returns_empty (self , urlopen ):
368+ """When fetching notifications returns 504 (or any HTTPError), job continues with empty list."""
369+ fetch_repos = MagicMock ()
370+ response = MagicMock ()
371+ response .status = 200
372+ response .read .return_value = json .dumps (
373+ {
374+ "repositories" : [
375+ {"namespace" : "sample" , "name" : "hello-image" },
376+ ],
377+ }
378+ ).encode ()
379+ fetch_repos .__enter__ .return_value = response
380+
381+ mock_error = HTTPError (
382+ url = "http://example.com" ,
383+ code = 504 ,
384+ msg = "Gateway Timeout" ,
385+ hdrs = None ,
386+ fp = io .BytesIO (b"" ),
387+ )
388+
389+ urlopen .side_effect = [
390+ fetch_repos ,
391+ mock_error , # get_quay_notifications raises
392+ ]
393+
394+ with self .assertLogs (LOGGER ) as logs :
395+ main ()
396+ run_log = [
397+ msg
398+ for msg in logs .output
399+ if re .search (
400+ r"Failed to fetch notifications for sample/hello-image" ,
401+ msg ,
402+ )
403+ ]
404+ self .assertEqual (1 , len (run_log ))
405+
406+ self .assertEqual (2 , urlopen .call_count )
407+
364408 @patch ("reset_notifications.urlopen" )
365409 def test_handle_image_repos_pagination (self , urlopen ):
366410 first_fetch_rv = MagicMock ()
0 commit comments