Serialize files when using SessionClient
SessionClient can not json serialize TemplateFiles object. We should do them explictly. Change-Id: Ia67562ae9a13c0975cb5c39532c0dc413d82c4c3 Closes-Bug: #1589519
This commit is contained in:
@@ -306,10 +306,8 @@ class SessionClient(adapter.LegacyJsonAdapter):
|
|||||||
redirect = kwargs.get('redirect')
|
redirect = kwargs.get('redirect')
|
||||||
kwargs.setdefault('user_agent', USER_AGENT)
|
kwargs.setdefault('user_agent', USER_AGENT)
|
||||||
|
|
||||||
try:
|
if 'data' in kwargs:
|
||||||
kwargs.setdefault('json', kwargs.pop('data'))
|
kwargs['data'] = jsonutils.dumps(kwargs['data'])
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
resp, body = super(SessionClient, self).request(
|
resp, body = super(SessionClient, self).request(
|
||||||
url, method,
|
url, method,
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
# implied.
|
# implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import mock
|
import mock
|
||||||
import os
|
import os
|
||||||
@@ -833,7 +834,31 @@ class SessionClientTest(testtools.TestCase):
|
|||||||
resp = client.request('', 'GET', **kwargs)
|
resp = client.request('', 'GET', **kwargs)
|
||||||
|
|
||||||
self.assertEqual({'endpoint_override': 'http://no.where/',
|
self.assertEqual({'endpoint_override': 'http://no.where/',
|
||||||
'json': 'some_data',
|
'data': '"some_data"',
|
||||||
|
'user_agent': 'python-heatclient',
|
||||||
|
'raise_exc': False}, self.request.call_args[1])
|
||||||
|
self.assertEqual(200, resp.status_code)
|
||||||
|
|
||||||
|
@mock.patch.object(jsonutils, 'dumps')
|
||||||
|
def test_kwargs_with_files(self, mock_dumps):
|
||||||
|
fake = fakes.FakeHTTPResponse(
|
||||||
|
200,
|
||||||
|
'OK',
|
||||||
|
{'content-type': 'application/json'},
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
mock_dumps.return_value = "{'files': test}}"
|
||||||
|
data = six.BytesIO(b'test')
|
||||||
|
kwargs = {'endpoint_override': 'http://no.where/',
|
||||||
|
'data': {'files': data}}
|
||||||
|
client = http.SessionClient(mock.ANY)
|
||||||
|
|
||||||
|
self.request.return_value = (fake, {})
|
||||||
|
|
||||||
|
resp = client.request('', 'GET', **kwargs)
|
||||||
|
|
||||||
|
self.assertEqual({'endpoint_override': 'http://no.where/',
|
||||||
|
'data': "{'files': test}}",
|
||||||
'user_agent': 'python-heatclient',
|
'user_agent': 'python-heatclient',
|
||||||
'raise_exc': False}, self.request.call_args[1])
|
'raise_exc': False}, self.request.call_args[1])
|
||||||
self.assertEqual(200, resp.status_code)
|
self.assertEqual(200, resp.status_code)
|
||||||
|
Reference in New Issue
Block a user