示例#1
0
    def test_attachments_only_minidumps(self):
        self.project.update_option('sentry:store_crash_reports', False)
        self.upload_symbols()

        with self.feature('organizations:event-attachments'):
            attachment = BytesIO(b'Hello World!')
            attachment.name = 'hello.txt'
            with open(
                    os.path.join(os.path.dirname(__file__), 'fixtures',
                                 'windows.dmp'), 'rb') as f:
                resp = self._postMinidumpWithHeader(f, {
                    'sentry[logger]': 'test-logger',
                    'some_file': attachment,
                })
                assert resp.status_code == 200

        event = Event.objects.get()

        attachments = list(
            EventAttachment.objects.filter(event_id=event.event_id))
        assert len(attachments) == 1
        hello = attachments[0]

        assert hello.name == 'hello.txt'
        assert hello.file.type == 'event.attachment'
        assert hello.file.checksum == '2ef7bde608ce5404e97d5f042f95f89f1c232871'
示例#2
0
 def create_test_image_file():
     file = BytesIO()
     image = Image.new('RGBA', size=(100, 100), color=(155, 0, 0))
     image.save(file, 'png')
     file.name = 'test.png'
     file.seek(0)
     return file
示例#3
0
    def test_full_minidump(self):
        self.project.update_option('sentry:store_crash_reports', True)
        self.upload_symbols()

        with self.feature('organizations:event-attachments'):
            attachment = BytesIO(b'Hello World!')
            attachment.name = 'hello.txt'
            with open(os.path.join(os.path.dirname(__file__), 'fixtures', 'windows.dmp'), 'rb') as f:
                resp = self._postMinidumpWithHeader(f, {
                    'sentry[logger]': 'test-logger',
                    'some_file': attachment,
                })
                assert resp.status_code == 200

        event = Event.objects.get()

        insta_snapshot_stacktrace_data(self, event.data)

        attachments = sorted(
            EventAttachment.objects.filter(
                event_id=event.event_id),
            key=lambda x: x.name)
        hello, minidump = attachments

        assert hello.name == 'hello.txt'
        assert hello.file.type == 'event.attachment'
        assert hello.file.checksum == '2ef7bde608ce5404e97d5f042f95f89f1c232871'

        assert minidump.name == 'windows.dmp'
        assert minidump.file.type == 'event.minidump'
        assert minidump.file.checksum == '74bb01c850e8d65d3ffbc5bad5cabc4668fce247'
示例#4
0
def get_gif():
    """Return gif."""
    gif = BytesIO(
        b"GIF87a\x01\x00\x01\x00\x80\x01\x00\x00\x00\x00ccc,\x00"
        b"\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;")
    gif.name = "image.gif"
    return gif
示例#5
0
    def test_full_minidump(self):
        self.project.update_option('sentry:store_crash_reports', True)
        self.upload_symbols()

        with self.feature('organizations:event-attachments'):
            attachment = BytesIO(b'Hello World!')
            attachment.name = 'hello.txt'
            with open(get_fixture_path('windows.dmp'), 'rb') as f:
                resp = self._postMinidumpWithHeader(f, {
                    'sentry[logger]': 'test-logger',
                    'some_file': attachment,
                })
                assert resp.status_code == 200

        event = eventstore.get_events(
            filter_keys={'project_id': [self.project.id]})[0]
        insta_snapshot_stacktrace_data(self, event.data)

        attachments = sorted(
            EventAttachment.objects.filter(event_id=event.event_id),
            key=lambda x: x.name)
        hello, minidump = attachments

        assert hello.name == 'hello.txt'
        assert hello.file.type == 'event.attachment'
        assert hello.file.checksum == '2ef7bde608ce5404e97d5f042f95f89f1c232871'

        assert minidump.name == 'windows.dmp'
        assert minidump.file.type == 'event.minidump'
        assert minidump.file.checksum == '74bb01c850e8d65d3ffbc5bad5cabc4668fce247'
示例#6
0
    def test_full_minidump(self):
        self.project.update_option("sentry:store_crash_reports",
                                   STORE_CRASH_REPORTS_ALL)
        self.upload_symbols()

        with self.feature("organizations:event-attachments"):
            attachment = BytesIO(b"Hello World!")
            attachment.name = "hello.txt"
            with open(get_fixture_path("windows.dmp"), "rb") as f:
                resp = self._postMinidumpWithHeader(f, {
                    "sentry[logger]": "test-logger",
                    "some_file": attachment
                })
                assert resp.status_code == 200
                event_id = resp.content

        event = eventstore.get_event_by_id(self.project.id, event_id)
        insta_snapshot_stacktrace_data(self, event.data)
        assert event.data.get("logger") == "test-logger"
        # assert event.data.get("extra") == {"foo": "bar"}

        attachments = sorted(
            EventAttachment.objects.filter(event_id=event.event_id),
            key=lambda x: x.name)
        hello, minidump = attachments

        assert hello.name == "hello.txt"
        assert hello.file.type == "event.attachment"
        assert hello.file.checksum == "2ef7bde608ce5404e97d5f042f95f89f1c232871"

        assert minidump.name == "windows.dmp"
        assert minidump.file.type == "event.minidump"
        assert minidump.file.checksum == "74bb01c850e8d65d3ffbc5bad5cabc4668fce247"
示例#7
0
def test_025(res):
    content = six.b('éàù@')
    f = StringIO(six.b('éàù@'))
    f.name = 'test.txt'
    b = {'a': 'aa', 'b': six.b('éàù@'), 'f': f}
    h = {'content-type': "multipart/form-data"}
    r = res.post('/multipart4', payload=b, headers=h)
    t.eq(r.status_int, 200)
    t.eq(r.body_string(), content)
 def test_absfile(self):
     fileobj = BytesIO(b"This is my absolute file.")
     fileobj.name = "hello2.txt"
     response = self.client.post('/api/v1/file/', {'myabsfile': fileobj})
     self.assertEqual(201, response.status_code)
     self.assertEqual('application/json', response['Content-Type'])
     content = json.loads(response.content.decode('utf-8'))
     self.assertIn('resource_uri', content)
     self.assertTrue(content['myabsfile'].startswith("http://"))
示例#9
0
def test_025(res):
    content = six.b('éàù@')
    f = StringIO(six.b('éàù@'))
    f.name = 'test.txt'
    b = {'a': 'aa', 'b': six.b('éàù@'), 'f': f}
    h = {'content-type': "multipart/form-data"}
    r = res.post('/multipart4', payload=b, headers=h)
    t.eq(r.status_int, 200)
    t.eq(r.body_string(), content)
示例#10
0
    def test_stdout_was_closed(self):
        prego.init()
        out = BytesIO()
        out.name = "bytes-io"

        task = prego.Task()
        task.command(u'echo hi', stdout=out)
        task.run()

        self.assert_(out.closed)
示例#11
0
def test_write_extracted_values_tee_stdout(tmpdir):
    readable = BytesIO(wexin)
    readable.name = tmpdir.join('0' + EXT_WEXIN).strpath
    def extract(src):
        yield 1
    writer = command.WriteExtractedValues(TeeStdOut, extract)
    ret = writer(readable)
    assert ret is None
    with tmpdir.join('0' + EXT_WEXOUT).open() as fp:
        assert fp.read() == '1\n'
示例#12
0
def create_image(storage,
                 filename,
                 size=(100, 100),
                 image_mode="RGB",
                 image_format="PNG"):
    img_file = BytesIO()
    Image.new(image_mode, size).save(img_file, image_format)
    img_file.name = filename
    img_file.seek(0)
    return img_file
示例#13
0
def test_007():
    from six import BytesIO as StringIO
    u = "http://%s:%s/multipart4" % (HOST, PORT)
    content = six.b('éàù@')
    f = StringIO(six.b('éàù@'))
    f.name = 'test.txt'
    b = {'a': 'aa', 'b': six.b('éàù@'), 'f': f}
    h = {'content-type': "multipart/form-data"}
    body, headers = multipart_form_encode(b, h, uuid.uuid4().hex)
    r = request(u, method='POST', body=body, headers=headers)
    t.eq(r.status_int, 200)
    t.eq(r.body_string(), content)
示例#14
0
def get_temporary_file(prefix):
    """Get a temporary file.

    :return:
    """
    image = Image.new('RGBA', size=(100, 100), color=(256, 0, 0))
    tmp_file = BytesIO()
    _tmp_file = tempfile.NamedTemporaryFile(prefix=prefix, suffix='.png')
    image.save(tmp_file, "PNG")
    tmp_file.seek(0)
    tmp_file.name = _tmp_file.name
    return tmp_file
示例#15
0
def test_write_extracted_values_tee_stdout(tmpdir):
    readable = BytesIO(wexin)
    readable.name = tmpdir.join('0' + EXT_WEXIN).strpath

    def extract(src):
        yield 1

    writer = command.WriteExtractedValues(TeeStdOut, extract)
    ret = writer(readable)
    assert ret is None
    with tmpdir.join('0' + EXT_WEXOUT).open() as fp:
        assert fp.read() == '1\n'
示例#16
0
def get_temporary_file(prefix):
    """Get a temporary file.

    :return:
    """
    image = Image.new('RGBA', size=(100, 100), color=(256, 0, 0))
    tmp_file = BytesIO()
    _tmp_file = tempfile.NamedTemporaryFile(prefix=prefix, suffix='.png')
    image.save(tmp_file, "PNG")
    tmp_file.seek(0)
    tmp_file.name = _tmp_file.name
    return tmp_file
示例#17
0
    def test_upload(self):
        fileobj = BytesIO(b"This is my file.")
        fileobj.name = "hello.txt"
        response = self.client.post('/api/v1/file/', {'myfile': fileobj})
        self.assertEqual(201, response.status_code)
        self.assertEqual('application/json', response['Content-Type'])
        content = json.loads(response.content.decode('utf-8'))
        self.assertIn('resource_uri', content)

        # Now we should be able to get this file?
        response = self.client.get(content['resource_uri'])
        self.assertEqual(200, response.status_code)
        self.assertEqual('application/json', response['Content-Type'])
        content = json.loads(response.content.decode('utf-8'))
        self.assertEqual('hello.txt', content['myfile'])
示例#18
0
    def test_disabled_attachments(self):
        self.upload_symbols()

        attachment = BytesIO(b'Hello World!')
        attachment.name = 'hello.txt'
        with open(os.path.join(os.path.dirname(__file__), 'fixtures', 'windows.dmp'), 'rb') as f:
            resp = self._postMinidumpWithHeader(f, {
                'sentry[logger]': 'test-logger',
                'some_file': attachment,
            })
            assert resp.status_code == 200

        event = Event.objects.get()
        attachments = list(EventAttachment.objects.filter(event_id=event.event_id))
        assert attachments == []
示例#19
0
    def test_disabled_attachments(self):
        self.upload_symbols()

        attachment = BytesIO(b'Hello World!')
        attachment.name = 'hello.txt'
        with open(
                os.path.join(os.path.dirname(__file__), 'fixtures',
                             'windows.dmp'), 'rb') as f:
            resp = self._postMinidumpWithHeader(f, {
                'sentry[logger]': 'test-logger',
                'some_file': attachment,
            })
            assert resp.status_code == 200

        event = Event.objects.get()
        attachments = list(
            EventAttachment.objects.filter(event_id=event.event_id))
        assert attachments == []
示例#20
0
    def test_attachments_only_minidumps(self):
        self.project.update_option('sentry:store_crash_reports', False)
        self.upload_symbols()

        with self.feature('organizations:event-attachments'):
            attachment = BytesIO(b'Hello World!')
            attachment.name = 'hello.txt'
            with open(os.path.join(os.path.dirname(__file__), 'fixtures', 'windows.dmp'), 'rb') as f:
                resp = self._postMinidumpWithHeader(f, {
                    'sentry[logger]': 'test-logger',
                    'some_file': attachment,
                })
                assert resp.status_code == 200

        event = Event.objects.get()

        attachments = list(EventAttachment.objects.filter(event_id=event.event_id))
        assert len(attachments) == 1
        hello = attachments[0]

        assert hello.name == 'hello.txt'
        assert hello.file.type == 'event.attachment'
        assert hello.file.checksum == '2ef7bde608ce5404e97d5f042f95f89f1c232871'
示例#21
0
 def create_testfile(self, s):
     """Takes a str object and returns a file-like object that can be put in a POST request"""
     testfile = BytesIO(s.encode('utf-8'))
     testfile.name = 'testfile'
     return testfile
示例#22
0
 def test_stringio_with_name(self):
     """If a file object (StringIO) has a name attribute, use that in output"""
     file_obj = StringIO(b('test data'))
     file_obj.name = 'Test StringIO Object'
     put(file_obj, '/')
     assert re.search(file_obj.name, sys.stdout.getvalue())
示例#23
0
 def test_empty_minidump(self):
     f = BytesIO()
     f.name = 'empty.dmp'
     response = self._postMinidumpWithHeader(f)
     assert response.status_code == 400
     assert response.content == '{"error":"Empty minidump upload received"}'
示例#24
0
 def test_empty_minidump(self):
     f = BytesIO()
     f.name = 'empty.dmp'
     response = self._postMinidumpWithHeader(f)
     assert response.status_code == 400
     assert response.content == '{"error":"Empty minidump upload received"}'
示例#25
0
 def test_stringio_with_name(self):
     """If a file object (StringIO) has a name attribute, use that in output"""
     file_obj = StringIO(b("test data"))
     file_obj.name = "Test StringIO Object"
     put(file_obj, "/")
     assert re.search(file_obj.name, sys.stdout.getvalue())
示例#26
0
def photo():
    data = BytesIO()
    Image.new("RGB", (100, 100), (255, 255, 255)).save(data, "png")
    data.name = "test.png"
    data.seek(0)
    return data