|
@@ -1,12 +1,15 @@
|
|
|
+import pytest
|
|
|
from django.test import override_settings
|
|
|
|
|
|
from sentry.attachments.base import CachedAttachment
|
|
|
+from sentry.models.activity import Activity
|
|
|
from sentry.models.eventattachment import EventAttachment
|
|
|
from sentry.testutils.cases import APITestCase, PermissionTestCase
|
|
|
from sentry.testutils.helpers.datetime import before_now, iso_format
|
|
|
from sentry.testutils.helpers.features import with_feature
|
|
|
from sentry.testutils.helpers.response import close_streaming_response
|
|
|
from sentry.testutils.skips import requires_snuba
|
|
|
+from sentry.types.activity import ActivityType
|
|
|
|
|
|
pytestmark = [requires_snuba]
|
|
|
|
|
@@ -14,7 +17,7 @@ ATTACHMENT_CONTENT = b"File contents here" * 10_000
|
|
|
|
|
|
|
|
|
class CreateAttachmentMixin:
|
|
|
- def create_attachment(self, content: bytes | None = None):
|
|
|
+ def create_attachment(self, content: bytes | None = None, group_id: int | None = None):
|
|
|
self.project = self.create_project()
|
|
|
self.release = self.create_release(self.project, self.user)
|
|
|
min_ago = iso_format(before_now(minutes=1))
|
|
@@ -39,6 +42,7 @@ class CreateAttachmentMixin:
|
|
|
self.attachment = EventAttachment.objects.create(
|
|
|
event_id=self.event.event_id,
|
|
|
project_id=self.event.project_id,
|
|
|
+ group_id=group_id,
|
|
|
type=attachment.type,
|
|
|
name=attachment.name,
|
|
|
content_type=file.content_type,
|
|
@@ -138,6 +142,34 @@ class EventAttachmentDetailsTest(APITestCase, CreateAttachmentMixin):
|
|
|
assert response.status_code == 204, response.content
|
|
|
assert EventAttachment.objects.count() == 0
|
|
|
|
|
|
+ @with_feature("organizations:event-attachments")
|
|
|
+ def test_delete_activity_no_group(self):
|
|
|
+ self.login_as(user=self.user)
|
|
|
+
|
|
|
+ self.create_attachment(group_id=None)
|
|
|
+ path = f"/api/0/projects/{self.organization.slug}/{self.project.slug}/events/{self.event.event_id}/attachments/{self.attachment.id}/"
|
|
|
+ response = self.client.delete(path)
|
|
|
+ assert response.status_code == 204
|
|
|
+
|
|
|
+ # an activity with no group cannot be associated with an issue or displayed in an issue details page
|
|
|
+ with pytest.raises(Activity.DoesNotExist):
|
|
|
+ Activity.objects.get(type=ActivityType.DELETED_ATTACHMENT.value)
|
|
|
+
|
|
|
+ @with_feature("organizations:event-attachments")
|
|
|
+ def test_delete_activity_with_group(self):
|
|
|
+ self.login_as(user=self.user)
|
|
|
+
|
|
|
+ group_id = self.create_group().id
|
|
|
+ self.create_attachment(group_id=group_id)
|
|
|
+ path = f"/api/0/projects/{self.organization.slug}/{self.project.slug}/events/{self.event.event_id}/attachments/{self.attachment.id}/"
|
|
|
+ response = self.client.delete(path)
|
|
|
+ assert response.status_code == 204
|
|
|
+
|
|
|
+ delete_activity = Activity.objects.get(type=ActivityType.DELETED_ATTACHMENT.value)
|
|
|
+ assert delete_activity.project == self.project
|
|
|
+ assert delete_activity.group_id == group_id
|
|
|
+ assert delete_activity.group.id == group_id
|
|
|
+
|
|
|
|
|
|
class EventAttachmentDetailsPermissionTest(PermissionTestCase, CreateAttachmentMixin):
|
|
|
def setUp(self):
|