@@ -822,30 +822,29 @@ def test_upload_bundle_analysis_tokenless_mismatched_branch(
822822 assert not upload .called
823823
824824
825- def test_bundle_analysis_view_exception_handling (db , client , mocker , mock_redis ):
826- with patch (
827- "upload.views.bundle_analysis.BundleAnalysisView._handle_upload" ,
828- side_effect = Exception ("Test Exception" ),
829- ):
830- client = APIClient ()
831- repository = RepositoryFactory .create ()
832- client .credentials (HTTP_AUTHORIZATION = f"token { repository .upload_token } " )
833-
834- mock_inc_counter = mocker .patch ("upload.views.bundle_analysis.inc_counter" )
835-
836- res = client .post (
837- reverse ("upload-bundle-analysis" ),
838- {
839- "commit" : "6fd5b89357fc8cdf34d6197549ac7c6d7e5977ef" ,
840- "slug" : f"{ repository .author .username } ::::{ repository .name } " ,
841- },
842- format = "json" ,
843- )
844-
845- assert res .status_code == 201
846- assert res .json ()["url" ] is None
847-
848- # Check that the labels["result"] is "error"
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"
849848 mock_inc_counter .assert_any_call (
850849 ANY ,
851850 labels = mocker .ANY ,
0 commit comments