|
@@ -401,28 +401,27 @@ def test_deobfuscate_view_hierarchy(default_project, task_runner):
|
|
|
|
|
|
|
|
|
@django_db_all
|
|
|
+@pytest.mark.parametrize("feature_enabled", [True, False], ids=["with_feature", "without_feature"])
|
|
|
@pytest.mark.parametrize(
|
|
|
- "event_attachments", [True, False], ids=["with_feature", "without_feature"]
|
|
|
-)
|
|
|
-@pytest.mark.parametrize(
|
|
|
- "chunks",
|
|
|
+ "attachment",
|
|
|
[
|
|
|
- ((b"Hello ", b"World!"), "event.attachment", "application/octet-stream"),
|
|
|
- ((b"",), "event.attachment", "application/octet-stream"),
|
|
|
- ((), "event.attachment", "application/octet-stream"),
|
|
|
+ ([b"Hello ", b"World!"], "event.attachment", "application/octet-stream"),
|
|
|
+ ([b""], "event.attachment", "application/octet-stream"),
|
|
|
+ ([], "event.attachment", "application/octet-stream"),
|
|
|
(
|
|
|
- (b'{"rendering_system":"flutter","windows":[]}',),
|
|
|
+ [b'{"rendering_system":"flutter","windows":[]}'],
|
|
|
"event.view_hierarchy",
|
|
|
"application/json",
|
|
|
),
|
|
|
+ (b"inline attachment", "event.attachment", "application/octet-stream"),
|
|
|
],
|
|
|
- ids=["basic", "zerolen", "nochunks", "view_hierarchy"],
|
|
|
+ ids=["basic", "zerolen", "nochunks", "view_hierarchy", "inline"],
|
|
|
)
|
|
|
@pytest.mark.parametrize("with_group", [True, False], ids=["with_group", "without_group"])
|
|
|
def test_individual_attachments(
|
|
|
- default_project, factories, monkeypatch, event_attachments, chunks, with_group, django_cache
|
|
|
+ default_project, factories, monkeypatch, feature_enabled, attachment, with_group, django_cache
|
|
|
):
|
|
|
- monkeypatch.setattr("sentry.features.has", lambda *a, **kw: event_attachments)
|
|
|
+ monkeypatch.setattr("sentry.features.has", lambda *a, **kw: feature_enabled)
|
|
|
|
|
|
event_id = uuid.uuid4().hex
|
|
|
attachment_id = "ca90fb45-6dd9-40a0-a18f-8693aa621abb"
|
|
@@ -437,27 +436,34 @@ def test_individual_attachments(
|
|
|
group_id = event.group.id
|
|
|
assert group_id, "this test requires a group to work"
|
|
|
|
|
|
- for i, chunk in enumerate(chunks[0]):
|
|
|
- process_attachment_chunk(
|
|
|
- {
|
|
|
- "payload": chunk,
|
|
|
- "event_id": event_id,
|
|
|
- "project_id": project_id,
|
|
|
- "id": attachment_id,
|
|
|
- "chunk_index": i,
|
|
|
- }
|
|
|
- )
|
|
|
+ chunks, attachment_type, content_type = attachment
|
|
|
+ attachment_meta = {
|
|
|
+ "attachment_type": attachment_type,
|
|
|
+ "chunks": len(chunks),
|
|
|
+ "content_type": content_type,
|
|
|
+ "id": attachment_id,
|
|
|
+ "name": "foo.txt",
|
|
|
+ }
|
|
|
+ if isinstance(chunks, bytes):
|
|
|
+ attachment_meta["data"] = chunks
|
|
|
+ expected_content = chunks
|
|
|
+ else:
|
|
|
+ for i, chunk in enumerate(chunks):
|
|
|
+ process_attachment_chunk(
|
|
|
+ {
|
|
|
+ "payload": chunk,
|
|
|
+ "event_id": event_id,
|
|
|
+ "project_id": project_id,
|
|
|
+ "id": attachment_id,
|
|
|
+ "chunk_index": i,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ expected_content = b"".join(chunks)
|
|
|
|
|
|
process_individual_attachment(
|
|
|
{
|
|
|
"type": "attachment",
|
|
|
- "attachment": {
|
|
|
- "attachment_type": chunks[1],
|
|
|
- "chunks": len(chunks[0]),
|
|
|
- "content_type": chunks[2],
|
|
|
- "id": attachment_id,
|
|
|
- "name": "foo.txt",
|
|
|
- },
|
|
|
+ "attachment": attachment_meta,
|
|
|
"event_id": event_id,
|
|
|
"project_id": project_id,
|
|
|
},
|
|
@@ -466,16 +472,16 @@ def test_individual_attachments(
|
|
|
|
|
|
attachments = list(EventAttachment.objects.filter(project_id=project_id, event_id=event_id))
|
|
|
|
|
|
- if not event_attachments:
|
|
|
+ if not feature_enabled:
|
|
|
assert not attachments
|
|
|
else:
|
|
|
(attachment,) = attachments
|
|
|
assert attachment.name == "foo.txt"
|
|
|
assert attachment.group_id == group_id
|
|
|
- assert attachment.content_type == chunks[2]
|
|
|
+ assert attachment.content_type == content_type
|
|
|
|
|
|
with attachment.getfile() as file_contents:
|
|
|
- assert file_contents.read() == b"".join(chunks[0])
|
|
|
+ assert file_contents.read() == expected_content
|
|
|
|
|
|
|
|
|
@django_db_all
|