Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 0d404d1

Browse files
committed
fix the thing
1 parent 1890296 commit 0d404d1

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

upload/tests/views/test_bundle_analysis.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

upload/views/bundle_analysis.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
import uuid
3-
from typing import Any, Callable
3+
from typing import Any, Callable, Tuple
44

55
from django.conf import settings
66
from django.http import HttpRequest
@@ -86,10 +86,13 @@ class BundleAnalysisView(APIView, ShelterMixin):
8686
def get_exception_handler(self) -> Callable:
8787
return repo_auth_custom_exception_handler
8888

89-
def _handle_upload(self, request: HttpRequest) -> str | None:
89+
def _handle_upload(self, request: HttpRequest) -> Tuple[str, Response]:
9090
serializer = UploadSerializer(data=request.data)
9191
if not serializer.is_valid():
92-
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
92+
return (
93+
"bad_request",
94+
Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST),
95+
)
9396
data = serializer.validated_data
9497

9598
if isinstance(request.user, Owner):
@@ -211,7 +214,7 @@ def _handle_upload(self, request: HttpRequest) -> str | None:
211214
),
212215
)
213216

214-
return url
217+
return ("success", Response({"url": url}, status=201))
215218

216219
def post(self, request: HttpRequest) -> Response:
217220
labels = generate_upload_prometheus_metrics_labels(
@@ -223,15 +226,14 @@ def post(self, request: HttpRequest) -> Response:
223226
include_empty_labels=False,
224227
)
225228
labels["result"] = "pending"
226-
url = None
227229
inc_counter(
228230
BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER,
229231
labels=labels,
230232
)
231233

232-
upload_result = "success"
233234
try:
234-
url = self._handle_upload(request)
235+
upload_result, response = self._handle_upload(request)
236+
return response
235237
except Exception as e:
236238
log.error(
237239
"Error handling bundle analysis upload",
@@ -241,11 +243,11 @@ def post(self, request: HttpRequest) -> Response:
241243
exc_info=True,
242244
)
243245
upload_result = "error"
244-
245-
labels["position"] = "end"
246-
labels["result"] = upload_result
247-
inc_counter(
248-
BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER,
249-
labels=labels,
250-
)
251-
return Response({"url": url}, status=201)
246+
raise
247+
finally:
248+
labels["position"] = "end"
249+
labels["result"] = upload_result
250+
inc_counter(
251+
BUNDLE_ANALYSIS_UPLOAD_VIEWS_COUNTER,
252+
labels=labels,
253+
)

0 commit comments

Comments
 (0)