def format(self, record): message = {'message': record.getMessage(), 'asctime': self.formatTime(record, self.datefmt), 'name': record.name, 'msg': record.msg, 'args': record.args, 'levelname': record.levelname, 'levelno': record.levelno, 'pathname': record.pathname, 'filename': record.filename, 'module': record.module, 'lineno': record.lineno, 'funcname': record.funcName, 'created': record.created, 'msecs': record.msecs, 'relative_created': record.relativeCreated, 'thread': record.thread, 'thread_name': record.threadName, 'process_name': record.processName, 'process': record.process, 'traceback': None} if hasattr(record, 'extra'): message['extra'] = record.extra if record.exc_info: message['traceback'] = self.formatException(record.exc_info) return jsonutils.dumps(message)
def meta(self, value): if value: self.metadata = base64.encodestring(jsonutils.dumps(value)) else: self.metadata = None self._meta = value
def request(self, url, method, **kwargs): try: json = kwargs.pop('json') except KeyError: pass else: kwargs['content_type'] = 'application/json' kwargs['params'] = jsonutils.dumps(json) expected_status = kwargs.pop('expected_status', None) try: func = self.METHODS[method.lower()] except KeyError: self.fail("Unsupported HTTP Method: %s" % method) else: response = func(self.app, url, **kwargs) if expected_status: self.assertEqual(response.status_code, expected_status, 'Status code %s is not expected %s)\n\n%s' % (response.status_code, expected_status, response.body)) return response
def _ticket_metadata(self, requestor=DEFAULT_REQUESTOR, target=DEFAULT_TARGET, nonce=DEFAULT_NONCE, timestamp=None, b64encode=True): if not timestamp: timestamp = timeutils.utcnow() metadata = {'requestor': requestor, 'target': target, 'nonce': nonce, 'timestamp': timestamp} if b64encode: metadata = base64.b64encode(jsonutils.dumps(metadata)) return metadata
def tobasetype(self, value): text = jsonutils.dumps(value) return super(Base64JsonType, self).tobasetype(text)