@@ -103,6 +103,95 @@ def test_upload_bundle_analysis_success(db, client, mocker, mock_redis):
103103 )
104104
105105
106+ @pytest .mark .django_db (databases = {"default" , "timeseries" })
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+ },
135+ format = "json" ,
136+ headers = {"User-Agent" : "codecov-cli/0.4.7" },
137+ )
138+ assert res .status_code == 201
139+
140+ # returns presigned storage URL
141+ assert res .json () == {"url" : "test-presigned-put" }
142+
143+ create_presigned_put .assert_called_once_with ("bundle-analysis" , ANY , 30 )
144+ call = create_presigned_put .mock_calls [0 ]
145+ _ , storage_path , _ = call .args
146+ match = re .match (r"v1/uploads/([\d\w\-]+)\.json" , storage_path )
147+ assert match
148+ (reportid ,) = match .groups ()
149+
150+ # creates commit
151+ commit = Commit .objects .get (commitid = commit_sha )
152+ assert commit
153+
154+ # saves args in Redis
155+ redis = get_redis_connection ()
156+ args = redis .rpop (f"uploads/{ repository .repoid } /{ commit_sha } /bundle_analysis" )
157+ assert json .loads (args ) == {
158+ "reportid" : reportid ,
159+ "build" : "test-build" ,
160+ "build_url" : "test-build-url" ,
161+ "job" : "test-job" ,
162+ "service" : "test-service" ,
163+ "url" : f"v1/uploads/{ reportid } .json" ,
164+ "commit" : commit_sha ,
165+ "report_code" : None ,
166+ "bundle_analysis_compare_sha" : "6fd5b89357fc8cdf34d6197549ac7c6d7e5aaaaa" ,
167+ }
168+
169+ # sets latest upload timestamp
170+ ts = redis .get (f"latest_upload/{ repository .repoid } /{ commit_sha } /bundle_analysis" )
171+ assert ts
172+
173+ # triggers upload task
174+ upload .assert_called_with (
175+ commitid = commit_sha ,
176+ repoid = repository .repoid ,
177+ countdown = 4 ,
178+ report_code = None ,
179+ report_type = "bundle_analysis" ,
180+ )
181+ mock_sentry_metrics .assert_called_with (
182+ "upload" ,
183+ tags = {
184+ "agent" : "cli" ,
185+ "version" : "0.4.7" ,
186+ "action" : "bundle_analysis" ,
187+ "endpoint" : "bundle_analysis" ,
188+ "repo_visibility" : "private" ,
189+ "is_using_shelter" : "no" ,
190+ "position" : "end" ,
191+ },
192+ )
193+
194+
106195@pytest .mark .django_db (databases = {"default" , "timeseries" })
107196def test_upload_bundle_analysis_org_token (db , client , mocker , mock_redis ):
108197 mocker .patch .object (TaskService , "upload" )
0 commit comments