@@ -104,6 +104,7 @@ def test_upload_bundle_analysis_success(db, client, mocker, mock_redis):
104104 "endpoint" : "bundle_analysis" ,
105105 "is_using_shelter" : "no" ,
106106 "position" : "end" ,
107+ "result" : "success" ,
107108 },
108109 )
109110
@@ -207,6 +208,7 @@ def test_upload_bundle_analysis_success_shelter(db, client, mocker, mock_redis):
207208 "endpoint" : "bundle_analysis" ,
208209 "is_using_shelter" : "no" ,
209210 "position" : "end" ,
211+ "result" : "success" ,
210212 },
211213 )
212214
@@ -245,6 +247,7 @@ def test_upload_bundle_analysis_org_token(db, client, mocker, mock_redis):
245247 "endpoint" : "bundle_analysis" ,
246248 "is_using_shelter" : "no" ,
247249 "position" : "end" ,
250+ "result" : "success" ,
248251 },
249252 )
250253
@@ -292,6 +295,7 @@ def test_upload_bundle_analysis_existing_commit(db, client, mocker, mock_redis):
292295 "endpoint" : "bundle_analysis" ,
293296 "is_using_shelter" : "no" ,
294297 "position" : "end" ,
298+ "result" : "success" ,
295299 },
296300 )
297301
@@ -340,7 +344,8 @@ def test_upload_bundle_analysis_missing_args(db, client, mocker, mock_redis):
340344 "action" : "bundle_analysis" ,
341345 "endpoint" : "bundle_analysis" ,
342346 "is_using_shelter" : "no" ,
343- "position" : "start" ,
347+ "position" : "end" ,
348+ "result" : "bad_request" ,
344349 },
345350 )
346351
@@ -412,6 +417,7 @@ def test_upload_bundle_analysis_github_oidc_auth(
412417 "endpoint" : "bundle_analysis" ,
413418 "is_using_shelter" : "no" ,
414419 "position" : "end" ,
420+ "result" : "success" ,
415421 },
416422 )
417423
@@ -472,6 +478,7 @@ def test_upload_bundle_analysis_measurement_datasets_created(
472478 "endpoint" : "bundle_analysis" ,
473479 "is_using_shelter" : "no" ,
474480 "position" : "end" ,
481+ "result" : "success" ,
475482 },
476483 )
477484
@@ -533,6 +540,7 @@ def test_upload_bundle_analysis_measurement_timeseries_disabled(
533540 "endpoint" : "bundle_analysis" ,
534541 "is_using_shelter" : "no" ,
535542 "position" : "end" ,
543+ "result" : "success" ,
536544 },
537545 )
538546
@@ -574,7 +582,8 @@ def test_upload_bundle_analysis_no_repo(db, client, mocker, mock_redis):
574582 "action" : "bundle_analysis" ,
575583 "endpoint" : "bundle_analysis" ,
576584 "is_using_shelter" : "no" ,
577- "position" : "start" ,
585+ "position" : "end" ,
586+ "result" : "error" ,
578587 },
579588 )
580589
@@ -629,6 +638,7 @@ def test_upload_bundle_analysis_tokenless_success(db, client, mocker, mock_redis
629638 "endpoint" : "bundle_analysis" ,
630639 "is_using_shelter" : "no" ,
631640 "position" : "end" ,
641+ "result" : "success" ,
632642 },
633643 )
634644
@@ -810,3 +820,34 @@ def test_upload_bundle_analysis_tokenless_mismatched_branch(
810820 assert res .status_code == 401
811821 assert res .json () == {"detail" : "Not valid tokenless upload" }
812822 assert not upload .called
823+
824+
825+ def test_upload_bundle_analysis_view_exception_handling (db , client , mocker , mock_redis ):
826+ try :
827+ with patch (
828+ "upload.views.bundle_analysis.BundleAnalysisView._handle_upload" ,
829+ side_effect = Exception ("Test Exception" ),
830+ ):
831+ client = APIClient ()
832+ repository = RepositoryFactory .create ()
833+ client .credentials (HTTP_AUTHORIZATION = f"token { repository .upload_token } " )
834+
835+ mock_inc_counter = mocker .patch ("upload.views.bundle_analysis.inc_counter" )
836+
837+ client .post (
838+ reverse ("upload-bundle-analysis" ),
839+ {
840+ "commit" : "6fd5b89357fc8cdf34d6197549ac7c6d7e5977ef" ,
841+ "slug" : f"{ repository .author .username } ::::{ repository .name } " ,
842+ },
843+ format = "json" ,
844+ )
845+ except Exception as e :
846+ # Check that the Test Exception was raised and the inc_counter went up
847+ assert str (e ) == "Test Exception"
848+ mock_inc_counter .assert_any_call (
849+ ANY ,
850+ labels = mocker .ANY ,
851+ )
852+ labels = mock_inc_counter .call_args [1 ]["labels" ]
853+ assert labels ["result" ] == "error"
0 commit comments