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