@@ -103,6 +103,97 @@ def test_upload_bundle_analysis_success(db, client, mocker, mock_redis):
103103 )
104104
105105
106+ @pytest .mark .django_db (databases = {"default" , "timeseries" })
107+ @override_settings (SHELTER_SHARED_SECRET = "shelter-shared-secret" )
108+ def test_upload_bundle_analysis_success_shelter (db , client , mocker , mock_redis ):
109+ upload = mocker .patch .object (TaskService , "upload" )
110+ mock_sentry_metrics = mocker .patch (
111+ "upload.views.bundle_analysis.sentry_metrics.incr"
112+ )
113+ create_presigned_put = mocker .patch (
114+ "services.archive.StorageService.create_presigned_put" ,
115+ return_value = "test-presigned-put" ,
116+ )
117+
118+ repository = RepositoryFactory .create ()
119+ commit_sha = "6fd5b89357fc8cdf34d6197549ac7c6d7e5977ef"
120+
121+ client = APIClient ()
122+ client .credentials (HTTP_AUTHORIZATION = f"token { repository .upload_token } " )
123+
124+ res = client .post (
125+ reverse ("upload-bundle-analysis" ),
126+ {
127+ "commit" : commit_sha ,
128+ "slug" : f"{ repository .author .username } ::::{ repository .name } " ,
129+ "build" : "test-build" ,
130+ "buildURL" : "test-build-url" ,
131+ "job" : "test-job" ,
132+ "service" : "test-service" ,
133+ "compareSha" : "6fd5b89357fc8cdf34d6197549ac7c6d7e5aaaaa" ,
134+ "storage_path" : "shelter/test/path.txt" ,
135+ "upload_external_id" : "test-47078f85-2cee-4511-b38d-183c334ef43b" ,
136+ },
137+ format = "json" ,
138+ headers = {"User-Agent" : "codecov-cli/0.4.7" },
139+ )
140+ assert res .status_code == 201
141+
142+ # returns presigned storage URL
143+ assert res .json () == {"url" : "test-presigned-put" }
144+
145+ create_presigned_put .assert_called_once_with ("bundle-analysis" , ANY , 30 )
146+ call = create_presigned_put .mock_calls [0 ]
147+ _ , storage_path , _ = call .args
148+ match = re .match (r"v1/uploads/([\d\w\-]+)\.json" , storage_path )
149+ assert match
150+ (reportid ,) = match .groups ()
151+
152+ # creates commit
153+ commit = Commit .objects .get (commitid = commit_sha )
154+ assert commit
155+
156+ # saves args in Redis
157+ redis = get_redis_connection ()
158+ args = redis .rpop (f"uploads/{ repository .repoid } /{ commit_sha } /bundle_analysis" )
159+ assert json .loads (args ) == {
160+ "reportid" : reportid ,
161+ "build" : "test-build" ,
162+ "build_url" : "test-build-url" ,
163+ "job" : "test-job" ,
164+ "service" : "test-service" ,
165+ "url" : f"v1/uploads/{ reportid } .json" ,
166+ "commit" : commit_sha ,
167+ "report_code" : None ,
168+ "bundle_analysis_compare_sha" : "6fd5b89357fc8cdf34d6197549ac7c6d7e5aaaaa" ,
169+ }
170+
171+ # sets latest upload timestamp
172+ ts = redis .get (f"latest_upload/{ repository .repoid } /{ commit_sha } /bundle_analysis" )
173+ assert ts
174+
175+ # triggers upload task
176+ upload .assert_called_with (
177+ commitid = commit_sha ,
178+ repoid = repository .repoid ,
179+ countdown = 4 ,
180+ report_code = None ,
181+ report_type = "bundle_analysis" ,
182+ )
183+ mock_sentry_metrics .assert_called_with (
184+ "upload" ,
185+ tags = {
186+ "agent" : "cli" ,
187+ "version" : "0.4.7" ,
188+ "action" : "bundle_analysis" ,
189+ "endpoint" : "bundle_analysis" ,
190+ "repo_visibility" : "private" ,
191+ "is_using_shelter" : "no" ,
192+ "position" : "end" ,
193+ },
194+ )
195+
196+
106197@pytest .mark .django_db (databases = {"default" , "timeseries" })
107198def test_upload_bundle_analysis_org_token (db , client , mocker , mock_redis ):
108199 mocker .patch .object (TaskService , "upload" )
0 commit comments