Example #1
0
 def run(self):
     try:
         self.check_messages()
     except Exception:
         info = sys.exc_info()
         raven_conf = getattr(settings, "RAVEN_CONFIG", False)
         if raven_conf and raven_conf.get("dsn"):
             client = DjangoClient(raven_conf.get("dsn"))
             exc_type, exc_value, exc_traceback = info
             error = str(
                 traceback.format_exception(exc_type, exc_value,
                                            exc_traceback))
             client.capture("raven.events.Message",
                            message="Error Sending message",
                            extra={
                                "info": error,
                                "number": self.phone.number
                            })
         raise Exception(info[1], None, info[2])
Example #2
0
class ServerTest(TestCase):
    def setUp(self):
        self.raven = DjangoClient(include_paths=['tests'])

    def test_text(self):
        event_id, checksum = self.raven.capture('Message', message='hello')

        self.assertEquals(Group.objects.count(), 1)
        self.assertEquals(Event.objects.count(), 1)

        message = Event.objects.get()
        self.assertEquals(message.event_id, event_id)
        self.assertEquals(message.checksum, checksum)
        self.assertEquals(message.message, 'hello')
        self.assertEquals(message.logger, 'root')
        self.assertEquals(message.level, logging.ERROR)
        data = message.data
        self.assertTrue('modules' in data)
        versions = data['modules']
        self.assertTrue('tests' in versions)
        self.assertEquals(versions['tests'], 1.0)
        self.assertTrue('sentry.interfaces.Message' in data)
        message = data['sentry.interfaces.Message']
        self.assertEquals(message['message'], 'hello')
        self.assertEquals(message['params'], ())

    def test_exception(self):
        try:
            raise ValueError('hello')
        except:
            pass
        else:
            self.fail('Whatttt?')

        event_id, checksum = self.raven.capture('Exception')

        self.assertEquals(Group.objects.count(), 1)
        self.assertEquals(Event.objects.count(), 1)

        message = Event.objects.get()
        self.assertEquals(message.event_id, event_id)
        self.assertEquals(message.checksum, checksum)
        self.assertEquals(message.message, 'ValueError: hello')
        self.assertEquals(message.logger, 'root')
        self.assertEquals(message.level, logging.ERROR)
        data = message.data
        self.assertTrue('modules' in data)
        versions = data['modules']
        self.assertTrue('tests' in versions)
        self.assertEquals(versions['tests'], 1.0)
        self.assertTrue('sentry.interfaces.Exception' in data)
        exc = data['sentry.interfaces.Exception']
        self.assertEquals(exc['type'], 'ValueError')
        self.assertEquals(exc['value'], 'hello')
        self.assertTrue('sentry.interfaces.Stacktrace' in data)
        frames = data['sentry.interfaces.Stacktrace']['frames']
        frame = frames[0]
        self.assertEquals(frame['function'], 'test_exception')
        self.assertEquals(frame['module'], __name__)
        self.assertEquals(frame['filename'], 'tests/integration/tests.py')
        self.assertEquals(frame['abs_path'], __file__.replace('.pyc', '.py'))