Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test results): accept null branch and add default branch #708

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions upload/tests/views/test_test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_upload_test_results(db, client, mocker, mock_redis):
"buildURL": "test-build-url",
"job": "test-job",
"service": "test-service",
"branch": "aaaaaa",
},
format="json",
headers={"User-Agent": "codecov-cli/0.4.7"},
Expand Down Expand Up @@ -63,6 +64,7 @@ def test_upload_test_results(db, client, mocker, mock_redis):
# creates commit
commit = Commit.objects.get(commitid=commit_sha)
assert commit
assert commit.branch is not None

# saves args in Redis
redis = get_redis_connection()
Expand Down Expand Up @@ -123,6 +125,7 @@ def test_test_results_org_token(db, client, mocker, mock_redis):
{
"commit": "6fd5b89357fc8cdf34d6197549ac7c6d7e5977ef",
"slug": f"{repository.author.username}::::{repository.name}",
"branch": "aaaaaa",
},
format="json",
)
Expand Down Expand Up @@ -157,6 +160,7 @@ def test_test_results_github_oidc_token(
{
"commit": "6fd5b89357fc8cdf34d6197549ac7c6d7e5977ef",
"slug": f"{repository.author.username}::::{repository.name}",
"branch": "aaaaaa",
},
format="json",
)
Expand Down Expand Up @@ -223,6 +227,65 @@ def test_upload_test_results_missing_args(db, client, mocker, mock_redis):
assert not upload.called


def test_upload_test_results_missing_branch_no_commit(db, client, mocker, mock_redis):
upload = mocker.patch.object(TaskService, "upload")
mocker.patch(
"services.archive.StorageService.create_presigned_put",
return_value="test-presigned-put",
)

repository = RepositoryFactory.create()

client = APIClient()
client.credentials(HTTP_AUTHORIZATION=f"token {repository.upload_token}")

commit_sha = "aaaaaa"
res = client.post(
reverse("upload-test-results"),
{
"commit": "aaaaaa",
"slug": f"{repository.author.username}::::{repository.name}",
},
format="json",
)
assert res.status_code == 201

assert upload.called

commit = Commit.objects.get(commitid=commit_sha)
assert commit.branch is not None


def test_upload_test_results_branch_none_no_commit(db, client, mocker, mock_redis):
upload = mocker.patch.object(TaskService, "upload")
mocker.patch(
"services.archive.StorageService.create_presigned_put",
return_value="test-presigned-put",
)

repository = RepositoryFactory.create()

client = APIClient()
client.credentials(HTTP_AUTHORIZATION=f"token {repository.upload_token}")

commit_sha = "aaaaaa"
res = client.post(
reverse("upload-test-results"),
{
"commit": "aaaaaa",
"slug": f"{repository.author.username}::::{repository.name}",
"branch": None,
},
format="json",
)
assert res.status_code == 201

assert upload.called

commit = Commit.objects.get(commitid=commit_sha)
assert commit.branch is not None


def test_update_repo_fields_when_upload_is_triggered(
db, client, mocker, mock_redis
) -> None:
Expand Down
4 changes: 2 additions & 2 deletions upload/views/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class UploadSerializer(serializers.Serializer):
job = serializers.CharField(required=False)
flags = FlagListField(required=False)
pr = serializers.CharField(required=False)
branch = serializers.CharField(required=False)
branch = serializers.CharField(required=False, allow_null=True)
service = serializers.CharField(required=False)
storage_path = serializers.CharField(required=False)

Expand Down Expand Up @@ -105,7 +105,7 @@ def post(self, request):
commitid=data["commit"],
repository=repo,
defaults={
"branch": data.get("branch"),
"branch": data.get("branch") or repo.branch,
"pullid": data.get("pr"),
"merged": False if data.get("pr") is not None else None,
"state": "pending",
Expand Down
Loading