def test_safe_encode_list(self):
     o = object()
     unicode_text = u'\u7f51\u7edc'
     l = ['abc', unicode_text, unicode_text.encode('utf-8'), o]
     expected = ['abc', unicode_text.encode('utf-8'),
                 unicode_text.encode('utf-8'), o]
     self.assertEqual(utils.safe_encode_list(l), expected)
Ejemplo n.º 2
0
    def _cs_request(self, *args, **kwargs):
        kargs = {}
        kargs.setdefault('headers', kwargs.get('headers', {}))
        kargs['headers']['User-Agent'] = self.USER_AGENT

        if 'content_type' in kwargs:
            kargs['headers']['Content-Type'] = kwargs['content_type']
            kargs['headers']['Accept'] = kwargs['content_type']
        else:
            kargs['headers']['Content-Type'] = self.content_type
            kargs['headers']['Accept'] = self.content_type

        if 'body' in kwargs:
            kargs['body'] = kwargs['body']
        args = utils.safe_encode_list(args)
        kargs = utils.safe_encode_dict(kargs)
        utils.http_log_req(_logger, args, kargs)
        resp, body = self.request(*args, **kargs)
        utils.http_log_resp(_logger, resp, body)
        status_code = self.get_status_code(resp)
        if status_code == 401:
            raise exceptions.Unauthorized(message=body)
        elif status_code == 403:
            raise exceptions.Forbidden(message=body)
        return resp, body