|
7 | 7 | from shared.django_apps.codecov_auth.tests.factories import ( |
8 | 8 | OrganizationLevelTokenFactory, |
9 | 9 | ) |
| 10 | +from shared.django_apps.core.models import Commit |
10 | 11 | from shared.django_apps.core.tests.factories import ( |
11 | 12 | CommitFactory, |
12 | 13 | OwnerFactory, |
13 | 14 | RepositoryFactory, |
14 | 15 | ) |
15 | 16 |
|
16 | | -from core.models import Commit |
17 | 17 | from services.redis_configuration import get_redis_connection |
18 | 18 | from services.task import TaskService |
19 | 19 |
|
@@ -377,3 +377,73 @@ def test_update_repo_fields_when_upload_is_triggered( |
377 | 377 | assert repository.active is True |
378 | 378 | assert repository.activated is True |
379 | 379 | assert repository.test_analytics_enabled is True |
| 380 | + |
| 381 | + |
| 382 | +def test_upload_test_results_file_not_found(db, client, mocker, mock_redis): |
| 383 | + upload = mocker.patch.object(TaskService, "upload") |
| 384 | + create_presigned_put = mocker.patch( |
| 385 | + "shared.api_archive.archive.StorageService.create_presigned_put", |
| 386 | + return_value="test-presigned-put", |
| 387 | + ) |
| 388 | + |
| 389 | + owner = OwnerFactory(service="github", username="codecov") |
| 390 | + repository = RepositoryFactory.create(author=owner) |
| 391 | + commit_sha = "6fd5b89357fc8cdf34d6197549ac7c6d7e5977ef" |
| 392 | + |
| 393 | + client = APIClient() |
| 394 | + client.credentials(HTTP_AUTHORIZATION=f"token {repository.upload_token}") |
| 395 | + |
| 396 | + res = client.post( |
| 397 | + reverse("upload-test-results"), |
| 398 | + { |
| 399 | + "commit": commit_sha, |
| 400 | + "slug": f"{repository.author.username}::::{repository.name}", |
| 401 | + "build": "test-build", |
| 402 | + "buildURL": "test-build-url", |
| 403 | + "job": "test-job", |
| 404 | + "service": "github-actions", |
| 405 | + "branch": "aaaaaa", |
| 406 | + "file_not_found": True, |
| 407 | + }, |
| 408 | + format="json", |
| 409 | + headers={"User-Agent": "codecov-cli/0.4.7"}, |
| 410 | + ) |
| 411 | + assert res.status_code == 201 |
| 412 | + |
| 413 | + assert res.data is None |
| 414 | + |
| 415 | + create_presigned_put.assert_not_called() |
| 416 | + |
| 417 | + commit = Commit.objects.get(commitid=commit_sha) |
| 418 | + assert commit |
| 419 | + assert commit.branch is not None |
| 420 | + |
| 421 | + redis = get_redis_connection() |
| 422 | + args = json.loads( |
| 423 | + redis.rpop(f"uploads/{repository.repoid}/{commit_sha}/test_results") |
| 424 | + ) |
| 425 | + assert args == { |
| 426 | + "reportid": mocker.ANY, |
| 427 | + "build": "test-build", |
| 428 | + "build_url": "test-build-url", |
| 429 | + "job": "test-job", |
| 430 | + "service": "github-actions", |
| 431 | + "url": None, |
| 432 | + "commit": commit_sha, |
| 433 | + "report_code": None, |
| 434 | + "flags": None, |
| 435 | + } |
| 436 | + |
| 437 | + # sets latest upload timestamp |
| 438 | + ts = redis.get(f"latest_upload/{repository.repoid}/{commit_sha}/test_results") |
| 439 | + assert ts |
| 440 | + |
| 441 | + # triggers upload task |
| 442 | + upload.assert_called_with( |
| 443 | + commitid=commit_sha, |
| 444 | + repoid=repository.repoid, |
| 445 | + report_code=None, |
| 446 | + report_type="test_results", |
| 447 | + arguments=args, |
| 448 | + countdown=4, |
| 449 | + ) |
0 commit comments