Esempio n. 1
0
def test_individual_attachments_missing_chunks(default_project, factories, monkeypatch):
    monkeypatch.setattr("sentry.features.has", lambda *a, **kw: True)

    event_id = "515539018c9b4260a6f999572f1661ee"
    attachment_id = "ca90fb45-6dd9-40a0-a18f-8693aa621abb"
    project_id = default_project.id

    process_individual_attachment(
        {
            "type": "attachment",
            "attachment": {
                "attachment_type": "event.attachment",
                "chunks": 123,
                "content_type": "application/octet-stream",
                "id": attachment_id,
                "name": "foo.txt",
            },
            "event_id": event_id,
            "project_id": project_id,
        },
        projects={default_project.id: default_project},
    )

    attachments = list(EventAttachment.objects.filter(project_id=project_id, event_id=event_id))

    assert not attachments
def test_individual_attachments(
    default_project, factories, monkeypatch, event_attachments, chunks, with_group
):
    monkeypatch.setattr("sentry.features.has", lambda *a, **kw: event_attachments)

    event_id = "515539018c9b4260a6f999572f1661ee"
    attachment_id = "ca90fb45-6dd9-40a0-a18f-8693aa621abb"
    project_id = default_project.id
    group_id = None

    if with_group:
        event = factories.store_event(
            data={"event_id": event_id, "message": "existence is pain"}, project_id=project_id
        )

        group_id = event.group.id
        assert group_id, "this test requires a group to work"

    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,
            },
            projects={default_project.id: default_project},
        )

    process_individual_attachment(
        {
            "type": "attachment",
            "attachment": {
                "attachment_type": "event.attachment",
                "chunks": len(chunks),
                "content_type": "application/octet-stream",
                "id": attachment_id,
                "name": "foo.txt",
            },
            "event_id": event_id,
            "project_id": project_id,
        },
        projects={default_project.id: default_project},
    )

    attachments = list(EventAttachment.objects.filter(project_id=project_id, event_id=event_id))

    if not event_attachments:
        assert not attachments
    else:
        (attachment,) = attachments
        file = File.objects.get(id=attachment.file_id)
        assert file.type == "event.attachment"
        assert file.headers == {"Content-Type": "application/octet-stream"}
        assert attachment.group_id == group_id
        file_contents = file.getfile()
        assert file_contents.read() == b"".join(chunks)
        assert file_contents.name == "foo.txt"
Esempio n. 3
0
def test_individual_attachments(default_project, monkeypatch,
                                event_attachments):
    has_feature = event_attachments == "with_feature"
    monkeypatch.setattr("sentry.features.has", lambda *a, **kw: has_feature)

    event_id = "515539018c9b4260a6f999572f1661ee"
    attachment_id = "ca90fb45-6dd9-40a0-a18f-8693aa621abb"
    project_id = default_project.id

    process_attachment_chunk({
        "payload": b"Hello ",
        "event_id": event_id,
        "project_id": project_id,
        "id": attachment_id,
        "chunk_index": 0,
    })

    process_attachment_chunk({
        "payload": b"World!",
        "event_id": event_id,
        "project_id": project_id,
        "id": attachment_id,
        "chunk_index": 1,
    })

    process_individual_attachment({
        "type": "attachment",
        "attachment": {
            "attachment_type": "event.attachment",
            "chunks": 2,
            "content_type": "application/octet-stream",
            "id": attachment_id,
            "name": "foo.txt",
        },
        "event_id": event_id,
        "project_id": project_id,
    })

    attachments = list(
        EventAttachment.objects.filter(
            project_id=project_id, event_id=event_id).select_related("file"))

    if not has_feature:
        assert not attachments
    else:
        att1, = attachments
        assert att1.file.type == "event.attachment"
        assert att1.file.headers == {
            "Content-Type": "application/octet-stream"
        }
        f = att1.file.getfile()
        assert f.read() == b"Hello World!"
        assert f.name == "foo.txt"
Esempio n. 4
0
def test_individual_attachments(default_project, monkeypatch,
                                event_attachments, chunks):
    monkeypatch.setattr("sentry.features.has",
                        lambda *a, **kw: event_attachments)

    event_id = "515539018c9b4260a6f999572f1661ee"
    attachment_id = "ca90fb45-6dd9-40a0-a18f-8693aa621abb"
    project_id = default_project.id

    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,
            },
            projects={default_project.id: default_project},
        )

    process_individual_attachment(
        {
            "type": "attachment",
            "attachment": {
                "attachment_type": "event.attachment",
                "chunks": len(chunks),
                "content_type": "application/octet-stream",
                "id": attachment_id,
                "name": "foo.txt",
            },
            "event_id": event_id,
            "project_id": project_id,
        },
        projects={default_project.id: default_project},
    )

    attachments = list(
        EventAttachment.objects.filter(
            project_id=project_id, event_id=event_id).select_related("file"))

    if not event_attachments:
        assert not attachments
    else:
        att1, = attachments
        assert att1.file.type == "event.attachment"
        assert att1.file.headers == {
            "Content-Type": "application/octet-stream"
        }
        f = att1.file.getfile()
        assert f.read() == b"".join(chunks)
        assert f.name == "foo.txt"