Process json based on content-type
OpenStack provides content-type which we can respond to. That we do not currently provide it in our unittests is our fault. So let's provide it. Change-Id: Ib20f4df950cbedf404c0fbe3ef4c39660eb1b70f Depends-On: Iaef2a140e33fc48f8bfa8ff4769eded37ce152c6
This commit is contained in:
parent
2a38af599d
commit
16a058f16e
@ -90,24 +90,19 @@ class ShadeAdapter(adapter.Adapter):
|
|||||||
|
|
||||||
def _munch_response(self, response, result_key=None):
|
def _munch_response(self, response, result_key=None):
|
||||||
exc.raise_from_response(response)
|
exc.raise_from_response(response)
|
||||||
# Glance image downloads just return the data in the body
|
|
||||||
if response.headers.get('Content-Type') in (
|
|
||||||
'text/plain',
|
|
||||||
'application/octet-stream'):
|
|
||||||
return response
|
|
||||||
else:
|
|
||||||
if not response.content:
|
if not response.content:
|
||||||
# This doens't have any content
|
# This doens't have any content
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
# Some REST calls do not return json content. Don't decode it.
|
||||||
|
if 'application/json' not in response.headers.get('Content-Type'):
|
||||||
|
return response
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result_json = response.json()
|
result_json = response.json()
|
||||||
except Exception:
|
except Exception:
|
||||||
raise exc.OpenStackCloudHTTPError(
|
return response
|
||||||
"Problems decoding json from response."
|
|
||||||
" Reponse: {code} {reason}".format(
|
|
||||||
code=response.status_code,
|
|
||||||
reason=response.reason),
|
|
||||||
response=response)
|
|
||||||
|
|
||||||
request_id = response.headers.get('x-openstack-request-id')
|
request_id = response.headers.get('x-openstack-request-id')
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ import fixtures
|
|||||||
import mock
|
import mock
|
||||||
import os
|
import os
|
||||||
import os_client_config as occ
|
import os_client_config as occ
|
||||||
|
from requests import structures
|
||||||
from requests_mock.contrib import fixture as rm_fixture
|
from requests_mock.contrib import fixture as rm_fixture
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
@ -167,6 +168,11 @@ class RequestsMockTestCase(BaseTestCase):
|
|||||||
def register_uri(self, method, uri, **kwargs):
|
def register_uri(self, method, uri, **kwargs):
|
||||||
validate = kwargs.pop('validate', {})
|
validate = kwargs.pop('validate', {})
|
||||||
key = '{method}:{uri}'.format(method=method, uri=uri)
|
key = '{method}:{uri}'.format(method=method, uri=uri)
|
||||||
|
headers = structures.CaseInsensitiveDict(kwargs.pop('headers', {}))
|
||||||
|
if 'content-type' not in headers:
|
||||||
|
headers[u'content-type'] = 'application/json'
|
||||||
|
kwargs['headers'] = headers
|
||||||
|
|
||||||
if key in self._uri_registry:
|
if key in self._uri_registry:
|
||||||
self._uri_registry[key].append(kwargs)
|
self._uri_registry[key].append(kwargs)
|
||||||
self.adapter.register_uri(method, uri, self._uri_registry[key])
|
self.adapter.register_uri(method, uri, self._uri_registry[key])
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user