示例#1
0
 def test_querystring_prefix(self):
     http = Http('http://example.com/foo/', 'GET', {}, '?bar=baz')
     result = http.serialize()
     self.assertTrue('url' in result, result)
     self.assertEquals(result['url'], 'http://example.com/foo/')
     self.assertTrue('querystring' in result, result)
     self.assertEquals(result['querystring'], 'bar=baz')
示例#2
0
 def test_serialize(self):
     http = Http('http://example.com/foo/', 'GET', {}, 'bar=baz')
     result = http.serialize()
     self.assertTrue('url' in result, result)
     self.assertEquals(result['url'], 'http://example.com/foo/')
     self.assertTrue('method' in result, result)
     self.assertEquals(result['method'], 'GET')
     self.assertTrue('data' in result, result)
     self.assertEquals(result['data'], {})
     self.assertTrue('querystring' in result, result)
     self.assertEquals(result['querystring'], 'bar=baz')
示例#3
0
 def test_serialize_and_unserialize(self):
     http = Http('http://example.com/foo/', 'GET', {}, 'bar=baz')
     result = unserialize(Http, http.serialize()).serialize()
     self.assertTrue('url' in result, result)
     self.assertEquals(result['url'], 'http://example.com/foo/')
     self.assertTrue('method' in result, result)
     self.assertEquals(result['method'], 'GET')
     self.assertTrue('data' in result, result)
     self.assertEquals(result['data'], {})
     self.assertTrue('querystring' in result, result)
     self.assertEquals(result['querystring'], 'bar=baz')
示例#4
0
    def convert_legacy_kwargs(self, kwargs):
        from sentry.interfaces import Http, User, Exception, Stacktrace, Template
        from sentry.utils.template_info import get_template_info

        data = kwargs.pop('data', None) or {}
        sentry = data.pop('__sentry__', None) or {}

        result = {
            'event_id': kwargs.pop('message_id', None),
            'level': kwargs.pop('level', None),
            'logger': kwargs.pop('logger', None),
            'server_name': kwargs.pop('server_name', None),
            'message': kwargs.pop('message', ''),
            'culprit': kwargs.pop('view', None),
            'timestamp': kwargs.pop('timestamp', None),
        }

        result = dict((k, v) for k, v in result.iteritems() if v is not None)

        class_name = kwargs.pop('class_name', None)
        if class_name:
            result['message'] = '%s: %s' % (class_name, result['message'])

        if 'url' in data or 'url' in kwargs and 'META' in data:
            meta = data.pop('META', {})
            if 'GET' in data:
                del data['GET']
            result['sentry.interfaces.Http'] = Http(
                url=data.pop('url', None) or kwargs['url'],
                method=meta.get('REQUEST_METHOD'),
                query_string=meta.get('QUERY_STRING'),
                data=data.pop('POST', None),
                cookies=data.pop('COOKIES', None),
                env=meta,
            ).serialize()

        if 'user' in sentry:
            user = sentry['user']
            result['sentry.interfaces.User'] = User(
                **user
            ).serialize()

        if 'exception' in sentry:
            exc = sentry['exception']
            result['sentry.interfaces.Exception'] = Exception(
                type=exc[0],
                value=u' '.join(itertools.imap(unicode, exc[1])),
            ).serialize()

        if 'frames' in sentry:
            frames = []
            keys = ('filename', 'function', 'vars', 'pre_context', 'context_line', 'post_context', 'lineno')
            for frame in sentry['frames']:
                if 'vars' in frame:
                    frame['vars'] = dict(frame['vars'])
                frames.append(dict((k, v) for k, v in frame.iteritems() if k in keys))

            if frames:
                result['sentry.interfaces.Stacktrace'] = Stacktrace(
                    frames=frames,
                ).serialize()

        if 'template' in sentry:
            template = sentry['template']
            print get_template_info(template)
            result['sentry.interfaces.Template'] = Template(
                **get_template_info(template)
            ).serialize()

        result['extra'] = data
        return result
示例#5
0
 def test_lowercase_method(self):
     http = Http('http://example.com/foo/?bar=baz', 'get')
     result = http.serialize()
     self.assertTrue('method' in result, result)
     self.assertEquals(result['method'], 'GET')
示例#6
0
 def test_lowercase_method(self):
     http = Http('http://example.com/foo/?bar=baz', 'get')
     result = http.serialize()
     self.assertTrue('method' in result, result)
     self.assertEquals(result['method'], 'GET')