Skip to content
Browse files

Add test coverage for send_remote

  • Loading branch information...
1 parent fc1d266 commit bdeee12d779ddd6e4a3146a819cf21b90719e5e5 @dcramer committed Jun 25, 2011
Showing with 34 additions and 1 deletion.
  1. +3 −1 sentry/client/base.py
  2. +5 −0 sentry/utils/__init__.py
  3. +26 −0 tests/test_web/test_api.py
View
4 sentry/client/base.py
@@ -227,13 +227,15 @@ def send_remote(self, url, data, headers=None):
def send(self, **kwargs):
"Sends the message to the server."
if app.config['REMOTES']:
+ if kwargs.get('date'):
+ kwargs['date'] = kwargs['date'].strftime('%Y-%m-%dT%H:%M:%S.%f')
for url in app.config['REMOTES']:
message = base64.b64encode(simplejson.dumps(kwargs).encode('zlib'))
timestamp = time.time()
nonce = uuid.uuid4().hex
signature = get_mac_signature(app.config['KEY'], message, nonce, timestamp)
headers={
- 'Authorization': get_auth_header(signature, timestamp, '%s/%s' % (self.__class__.__name__, sentry.VERSION)),
+ 'Authorization': get_auth_header(signature, timestamp, '%s/%s' % (self.__class__.__name__, sentry.VERSION), nonce),
'Content-Type': 'application/octet-stream',
}
View
5 sentry/utils/__init__.py
@@ -6,6 +6,7 @@
:license: BSD, see LICENSE for more details.
"""
+import datetime
import hashlib
import logging
import sys
@@ -90,6 +91,10 @@ def transform(value, stack=[], context=None):
ret = type(value)(transform_rec(o) for o in value)
elif isinstance(value, uuid.UUID):
ret = repr(value)
+ elif isinstance(value, datetime.datetime):
+ ret = value.strftime('%Y-%m-%dT%H:%M:%S.%f')
+ elif isinstance(value, datetime.date):
+ ret = value.strftime('%Y-%m-%d')
elif isinstance(value, dict):
ret = dict((k, transform_rec(v)) for k, v in value.iteritems())
elif isinstance(value, unicode):
View
26 tests/test_web/test_api.py
@@ -2,8 +2,34 @@
import base64
import simplejson
+from sentry import app
+from sentry.client.base import SentryClient
from sentry.models import Event
+class InternalRemoteSentryClient(SentryClient):
+ def send_remote(self, url, data, headers=None):
+ if headers is None:
+ headers = {}
+ client = app.test_client()
+ return client.post(url, data=data, headers=headers)
+
+class StoreIntegrationTest(BaseTest):
+ @with_settings(PUBLIC_WRITES=True, REMOTES=['/api/store/'])
+ def test_client(self):
+ client = InternalRemoteSentryClient()
+ event_id = client.capture('Message', message='foo')
+
+ event = Event.objects.get(event_id)
+
+ self.assertEquals(event.type, 'sentry.events.Message')
+ self.assertEquals(event.time_spent, 0)
+ self.assertTrue('sentry.interfaces.Message' in event.data)
+ event_data = event.data['sentry.interfaces.Message']
+ self.assertTrue('message' in event_data)
+ self.assertEquals(event_data['message'], 'foo')
+ self.assertTrue('params' in event_data)
+ self.assertEquals(event_data['params'], [])
+
class StoreTest(BaseTest):
@with_settings(PUBLIC_WRITES=True)
def test_simple(self):

0 comments on commit bdeee12

Please sign in to comment.
Something went wrong with that request. Please try again.