Esempio n. 1
0
    def test_async_send_remote_failover(self, should_try, get_transport):
        should_try.return_value = True
        async_transport = AsyncTransport()
        async_transport.async_send = async_send = mock.Mock()
        get_transport.return_value = async_transport

        client = Client(
            dsn='http://*****:*****@example.com/1',
        )

        # test immediate raise of error
        async_send.side_effect = Exception()
        client.send_remote('http://example.com/api/1/store/', client.encode({}))
        self.assertEquals(client.state.status, client.state.ERROR)

        # test recovery
        client.send_remote('http://example.com/api/1/store/', client.encode({}))
        success_cb = async_send.call_args[0][3]
        success_cb()
        self.assertEquals(client.state.status, client.state.ONLINE)

        # test delayed raise of error
        client.send_remote('http://example.com/api/1/store/', client.encode({}))
        failure_cb = async_send.call_args[0][4]
        failure_cb(Exception())
        self.assertEquals(client.state.status, client.state.ERROR)
Esempio n. 2
0
    def test_async_send_remote_failover(self, should_try, get_transport):
        should_try.return_value = True
        async_transport = AsyncTransport()
        async_transport.async_send = async_send = mock.Mock()
        get_transport.return_value = async_transport

        client = Client(dsn='http://*****:*****@example.com/1', )

        # test immediate raise of error
        async_send.side_effect = Exception()
        client.send_remote('http://example.com/api/1/store/',
                           client.encode({}))
        self.assertEquals(client.state.status, client.state.ERROR)

        # test recovery
        client.send_remote('http://example.com/api/1/store/',
                           client.encode({}))
        success_cb = async_send.call_args[0][3]
        success_cb()
        self.assertEquals(client.state.status, client.state.ONLINE)

        # test delayed raise of error
        client.send_remote('http://example.com/api/1/store/',
                           client.encode({}))
        failure_cb = async_send.call_args[0][4]
        failure_cb(Exception())
        self.assertEquals(client.state.status, client.state.ERROR)
Esempio n. 3
0
    def test_send_remote_failover(self, should_try, send):
        should_try.return_value = True

        client = Client(dsn="sync+http://public:[email protected]/1")

        # test error
        send.side_effect = Exception()
        client.send_remote("sync+http://example.com/api/store", client.encode({}))
        self.assertEquals(client.state.status, client.state.ERROR)

        # test recovery
        send.side_effect = None
        client.send_remote("sync+http://example.com/api/store", client.encode({}))
        self.assertEquals(client.state.status, client.state.ONLINE)
Esempio n. 4
0
    def test_send_remote_failover(self, should_try, send):
        should_try.return_value = True

        client = Client(dsn='sync+http://public:[email protected]/1')

        # test error
        send.side_effect = Exception()
        client.send_remote('sync+http://example.com/api/store',
                           client.encode({}))
        self.assertEquals(client.state.status, client.state.ERROR)

        # test recovery
        send.side_effect = None
        client.send_remote('sync+http://example.com/api/store',
                           client.encode({}))
        self.assertEquals(client.state.status, client.state.ONLINE)
Esempio n. 5
0
    def test_send_remote_failover_with_retry_after(self, should_try, send):
        should_try.return_value = True

        client = Client(dsn="sync+http://public:[email protected]/1")

        # test error
        send.side_effect = RateLimited("foo", 5)
        client.send_remote("sync+http://example.com/api/1/store/", client.encode({}))
        self.assertEquals(client.state.status, client.state.ERROR)
        self.assertEqual(client.state.retry_after, 5)

        # test recovery
        send.side_effect = None
        client.send_remote("sync+http://example.com/api/1/store/", client.encode({}))
        self.assertEquals(client.state.status, client.state.ONLINE)
        self.assertEqual(client.state.retry_after, 0)
Esempio n. 6
0
    def test_send_remote_failover_with_retry_after(self, should_try, send):
        should_try.return_value = True

        client = Client(dsn='sync+http://public:[email protected]/1')

        # test error
        send.side_effect = RateLimited('foo', 5)
        client.send_remote('sync+http://example.com/api/1/store/',
                           client.encode({}))
        self.assertEquals(client.state.status, client.state.ERROR)
        self.assertEqual(client.state.retry_after, 5)

        # test recovery
        send.side_effect = None
        client.send_remote('sync+http://example.com/api/1/store/',
                           client.encode({}))
        self.assertEquals(client.state.status, client.state.ONLINE)
        self.assertEqual(client.state.retry_after, 0)
Esempio n. 7
0
    def test_custom_transport(self):
        c = Client(dsn="mock://*****:*****@localhost:8143/1")

        data = dict(a=42, b=55, c=list(range(50)))
        c.send(**data)

        expected_message = c.encode(data)
        self.assertIn('mock://localhost:8143/api/store/', Client._registry._transports)
        mock_cls = Client._registry._transports['mock://localhost:8143/api/store/']
        assert mock_cls._data == expected_message
Esempio n. 8
0
    def test_custom_transport(self):
        c = Client(dsn="mock://*****:*****@localhost:8143/1")

        data = dict(a=42, b=55, c=list(range(50)))
        c.send(**data)

        expected_message = c.encode(data)
        self.assertIn('mock://localhost:8143/api/1/store/', Client._registry._transports)
        mock_cls = Client._registry._transports['mock://localhost:8143/api/1/store/']
        assert mock_cls._data == expected_message
Esempio n. 9
0
    def test_custom_transport(self):
        try:
            Client.register_scheme('mock', DummyScheme)
        except:
            pass
        c = Client(dsn="mock://*****:*****@localhost:8143/1")

        data = dict(a=42, b=55, c=range(50))
        c.send(**data)

        expected_message = c.encode(data)
        mock_cls = Client._registry._transports['mock']
        assert mock_cls._data == expected_message
Esempio n. 10
0
    def test_custom_transport(self):
        try:
            Client.register_scheme('mock', DummyScheme)
        except:
            pass
        c = Client(dsn="mock://*****:*****@localhost:8143/1")

        data = dict(a=42, b=55, c=range(50))
        c.send(**data)

        expected_message = c.encode(data)
        mock_cls = Client._registry._transports['mock']
        assert mock_cls._data == expected_message
Esempio n. 11
0
 def test_send_with_auth_header(self, time, send_remote):
     time.return_value = 1328055286.51
     client = Client(dsn="http://*****:*****@example.com/1")
     client.send(auth_header="foo", **{"foo": "bar"})
     send_remote.assert_called_once_with(
         url="http://example.com/api/1/store/",
         data=client.encode({"foo": "bar"}),
         headers={
             "User-Agent": "raven-python/%s" % (raven.VERSION,),
             "Content-Type": "application/octet-stream",
             "Content-Encoding": client.get_content_encoding(),
             "X-Sentry-Auth": "foo",
         },
     )
Esempio n. 12
0
 def test_send_with_auth_header(self, time, send_remote):
     time.return_value = 1328055286.51
     client = Client(dsn='http://*****:*****@example.com/1', )
     client.send(auth_header='foo', **{
         'foo': 'bar',
     })
     send_remote.assert_called_once_with(
         url='http://example.com/api/1/store/',
         data=client.encode({'foo': 'bar'}),
         headers={
             'User-Agent': 'raven-python/%s' % (raven.VERSION, ),
             'Content-Type': 'application/octet-stream',
             'Content-Encoding': client.get_content_encoding(),
             'X-Sentry-Auth': 'foo',
         },
     )
Esempio n. 13
0
    def test_custom_transport(self):
        c = Client(dsn="mock://*****:*****@localhost:8143/1")

        data = dict(a=42, b=55, c=list(range(50)))
        c.send(**data)

        mock_cls = c._transport_cache['mock://*****:*****@localhost:8143/1'].get_transport()

        expected_message = zlib.decompress(c.encode(data))
        actual_message = zlib.decompress(mock_cls._data)

        # These loads()/dumps() pairs order the dict keys before comparing the string.
        # See GH504
        self.assertEqual(
            json.dumps(json.loads(expected_message.decode('utf-8')), sort_keys=True),
            json.dumps(json.loads(actual_message.decode('utf-8')), sort_keys=True)
        )
Esempio n. 14
0
 def test_send_with_auth_header(self, time, send_remote):
     time.return_value = 1328055286.51
     client = Client(
         dsn='http://*****:*****@example.com/1',
     )
     client.send(auth_header='foo', **{
         'foo': 'bar',
     })
     send_remote.assert_called_once_with(
         url='http://example.com/api/1/store/',
         data=client.encode({'foo': 'bar'}),
         headers={
             'User-Agent': 'raven-python/%s' % (raven.VERSION,),
             'Content-Type': 'application/octet-stream',
             'Content-Encoding': client.get_content_encoding(),
             'X-Sentry-Auth': 'foo',
         },
     )
Esempio n. 15
0
    def test_custom_transport(self):
        c = Client(dsn="mock://*****:*****@localhost:8143/1")

        data = dict(a=42, b=55, c=list(range(50)))
        c.send(**data)

        expected_message = zlib.decompress(base64.b64decode(c.encode(data)))
        self.assertIn('mock://localhost:8143/api/1/store/', Client._registry._transports)
        mock_cls = Client._registry._transports['mock://localhost:8143/api/1/store/']

        actual_message = zlib.decompress(base64.b64decode(mock_cls._data))

        # These loads()/dumps() pairs order the dict keys before comparing the string.
        # See GH504
        self.assertEqual(
            json.dumps(json.loads(expected_message.decode('utf-8')), sort_keys=True),
            json.dumps(json.loads(actual_message.decode('utf-8')), sort_keys=True)
        )
Esempio n. 16
0
    def test_custom_transport(self):
        c = Client(dsn="mock://*****:*****@localhost:8143/1")

        data = dict(a=42, b=55, c=list(range(50)))
        c.send(**data)

        expected_message = zlib.decompress(base64.b64decode(c.encode(data)))
        self.assertIn('mock://localhost:8143/api/1/store/',
                      Client._registry._transports)
        mock_cls = Client._registry._transports[
            'mock://localhost:8143/api/1/store/']

        actual_message = zlib.decompress(base64.b64decode(mock_cls._data))

        # These loads()/dumps() pairs order the dict keys before comparing the string.
        # See GH504
        self.assertEqual(
            json.dumps(json.loads(expected_message.decode('utf-8')),
                       sort_keys=True),
            json.dumps(json.loads(actual_message.decode('utf-8')),
                       sort_keys=True))
def test_sqs_transport(sqs_queue):
    sqs = boto3.client("sqs", region_name="us-east-1")

    c = Client(
        dsn="mock://*****:*****@localhost:8143/1"
        "?sqs_region=us-east-1&sqs_account=123456789012&sqs_name=sentry-queue",
        transport=SQSTransport)

    data = dict(a=42, b=55, c=list(range(50)))
    expected_message = zlib.decompress(c.encode(data))

    c.send(**data)

    transport = c._transport_cache[
        "mock://*****:*****@localhost:8143/1"
        "?sqs_region=us-east-1&sqs_account=123456789012"
        "&sqs_name=sentry-queue"].get_transport()

    assert transport.sqs_account == "123456789012"
    assert transport.sqs_name == "sentry-queue"
    assert type(transport.sqs_client).__name__ == type(sqs).__name__
    assert transport.queue_url == "https://queue.amazonaws.com/123456789012/sentry-queue"

    # Check SQS for the message that was sent over:
    messages = sqs.receive_message(QueueUrl=transport.queue_url)["Messages"]
    assert len(messages) == 1

    body = json.loads(messages[0]["Body"])

    assert body["url"] == "mock://localhost:8143/api/1/store/"
    assert "sentry_secret=some_password" in body["headers"]["X-Sentry-Auth"]

    decoded_data = base64.b64decode(body["data"])

    assert json.dumps(json.loads(expected_message.decode('utf-8')), sort_keys=True) == \
           json.dumps(c.decode(decoded_data), sort_keys=True)   # noqa