def test_send(self, time, send_remote): time.return_value = 1328055286.51 client = Client( servers=['http://example.com'], public_key='public', secret_key='secret', project=1, ) client.send(**{ 'foo': 'bar', }) send_remote.assert_called_once_with( url='http://example.com', data=six.b('eJyrVkrLz1eyUlBKSixSqgUAIJgEVA=='), headers={ 'User-Agent': 'raven-python/%s' % (raven.VERSION, ), 'Content-Type': 'application/octet-stream', 'X-Sentry-Auth': ('Sentry sentry_timestamp=1328055286.51, ' 'sentry_client=raven-python/%s, sentry_version=4, ' 'sentry_key=public, ' 'sentry_secret=secret' % (raven.VERSION, )) }, )
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
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
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
def test_send_with_auth_header(self, time, send_remote): time.return_value = 1328055286.51 client = Client(servers=["http://example.com"], public_key="public", secret_key="secret", project=1) client.send(auth_header="foo", **{"foo": "bar"}) send_remote.assert_called_once_with( url="http://example.com", data="eJyrVkrLz1eyUlBKSixSqgUAIJgEVA==", headers={ "User-Agent": "raven-python/%s" % (raven.VERSION,), "Content-Type": "application/octet-stream", "X-Sentry-Auth": "foo", }, )
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", }, )
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=six.b('eJyrVkrLz1eyUlBKSixSqgUAIJgEVA=='), headers={ 'User-Agent': 'raven-python/%s' % (raven.VERSION, ), 'Content-Type': 'application/octet-stream', 'X-Sentry-Auth': 'foo' }, )
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', }, )
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=six.b('eJyrVkrLz1eyUlBKSixSqgUAIJgEVA=='), headers={ 'User-Agent': 'raven-python/%s' % (raven.VERSION,), 'Content-Type': 'application/octet-stream', 'X-Sentry-Auth': 'foo' }, )
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) )
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', }, )
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_send_with_auth_header(self, time, send_remote): time.return_value = 1328055286.51 client = Client( servers=['http://example.com'], public_key='public', secret_key='secret', project=1, ) client.send(auth_header='foo', **{ 'foo': 'bar', }) send_remote.assert_called_once_with( url='http://example.com', data='eJyrVkrLz1eyUlBKSixSqgUAIJgEVA==', headers={ 'Content-Type': 'application/octet-stream', 'X-Sentry-Auth': 'foo' }, )
def send(self, **kwargs): """ Serializes and signs ``data`` and passes the payload off to ``send_remote`` raven.contrib.django.client.DjangoClient does a check for self.servers, just bypass that and delegate to the primary raven.base.Client base class which will juse encode and fwd the data on to send_encoded. """ return Client.send(self, **kwargs)
def test_send(self, time, send_remote): time.return_value = 1328055286.51 client = Client( servers=['http://example.com'], public_key='public', secret_key='secret', project=1, ) client.send(**{ 'foo': 'bar', }) send_remote.assert_called_once_with( url='http://example.com', data='eJyrVkrLz1eyUlBKSixSqgUAIJgEVA==', headers={ 'Content-Type': 'application/octet-stream', 'X-Sentry-Auth': 'Sentry sentry_timestamp=1328055286.51, ' 'sentry_client=raven-python/%s, sentry_version=2.0, sentry_key=public' % (raven.VERSION,) }, )
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