|
@@ -5,9 +5,11 @@ from django.core.files.base import ContentFile
|
|
|
from django.urls import reverse
|
|
|
|
|
|
from sentry.models import ApiToken, FileBlob, FileBlobOwner
|
|
|
+from sentry.models.artifactbundle import ArtifactBundle
|
|
|
from sentry.silo import SiloMode
|
|
|
from sentry.tasks.assemble import ChunkFileState, assemble_artifacts
|
|
|
from sentry.testutils.cases import APITestCase
|
|
|
+from sentry.testutils.helpers.features import with_feature
|
|
|
from sentry.testutils.silo import assume_test_silo_mode, region_silo_test
|
|
|
|
|
|
|
|
@@ -79,6 +81,7 @@ class OrganizationReleaseAssembleTest(APITestCase):
|
|
|
"version": self.release.version,
|
|
|
"chunks": [blob1.checksum],
|
|
|
"checksum": total_checksum,
|
|
|
+ "project_ids": [],
|
|
|
"upload_as_artifact_bundle": False,
|
|
|
}
|
|
|
)
|
|
@@ -128,3 +131,52 @@ class OrganizationReleaseAssembleTest(APITestCase):
|
|
|
|
|
|
assert response.status_code == 200, response.content
|
|
|
assert response.data["state"] == ChunkFileState.ERROR
|
|
|
+
|
|
|
+ @patch("sentry.tasks.assemble.assemble_artifacts")
|
|
|
+ @with_feature("organizations:sourcemaps-upload-release-as-artifact-bundle")
|
|
|
+ def test_assemble_as_artifact_bundle(self, mock_assemble_artifacts):
|
|
|
+ bundle_file = self.create_artifact_bundle_zip(
|
|
|
+ org=self.organization.slug, release=self.release.version
|
|
|
+ )
|
|
|
+ total_checksum = sha1(bundle_file).hexdigest()
|
|
|
+
|
|
|
+ blob1 = FileBlob.from_file(ContentFile(bundle_file))
|
|
|
+ FileBlobOwner.objects.get_or_create(organization_id=self.organization.id, blob=blob1)
|
|
|
+
|
|
|
+ response = self.client.post(
|
|
|
+ self.url,
|
|
|
+ data={"checksum": total_checksum, "chunks": [blob1.checksum]},
|
|
|
+ HTTP_AUTHORIZATION=f"Bearer {self.token.token}",
|
|
|
+ )
|
|
|
+
|
|
|
+ assert response.status_code == 200, response.content
|
|
|
+ assert response.data["state"] == ChunkFileState.CREATED
|
|
|
+ assert set(response.data["missingChunks"]) == set()
|
|
|
+
|
|
|
+ # assert that we are uploading as artifact bundle
|
|
|
+ kwargs = {
|
|
|
+ "org_id": self.organization.id,
|
|
|
+ "version": self.release.version,
|
|
|
+ "checksum": total_checksum,
|
|
|
+ "chunks": [blob1.checksum],
|
|
|
+ "project_ids": [self.project.id],
|
|
|
+ "upload_as_artifact_bundle": True,
|
|
|
+ }
|
|
|
+ mock_assemble_artifacts.apply_async.assert_called_once_with(kwargs=kwargs)
|
|
|
+ # actually call through to assemble :-)
|
|
|
+ assemble_artifacts(**kwargs)
|
|
|
+
|
|
|
+ response = self.client.post(
|
|
|
+ self.url,
|
|
|
+ data={"checksum": total_checksum, "chunks": [blob1.checksum]},
|
|
|
+ HTTP_AUTHORIZATION=f"Bearer {self.token.token}",
|
|
|
+ )
|
|
|
+
|
|
|
+ assert response.status_code == 200, response.content
|
|
|
+ assert response.data["state"] == ChunkFileState.OK
|
|
|
+
|
|
|
+ # make sure that we have an artifact bundle now
|
|
|
+ artifact_bundles = ArtifactBundle.objects.filter(
|
|
|
+ organization_id=self.organization.id,
|
|
|
+ )
|
|
|
+ assert len(artifact_bundles) == 1
|