Merge "Serialize files when using SessionClient"

This commit is contained in:
Jenkins 2016-06-09 06:11:32 +00:00 committed by Gerrit Code Review
commit 1e86edb08c
2 changed files with 28 additions and 5 deletions

View File

@ -306,10 +306,8 @@ class SessionClient(adapter.LegacyJsonAdapter):
redirect = kwargs.get('redirect')
kwargs.setdefault('user_agent', USER_AGENT)
try:
kwargs.setdefault('json', kwargs.pop('data'))
except KeyError:
pass
if 'data' in kwargs:
kwargs['data'] = jsonutils.dumps(kwargs['data'])
resp, body = super(SessionClient, self).request(
url, method,

View File

@ -11,6 +11,7 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import mock
import os
@ -833,7 +834,31 @@ class SessionClientTest(testtools.TestCase):
resp = client.request('', 'GET', **kwargs)
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',
'raise_exc': False}, self.request.call_args[1])
self.assertEqual(200, resp.status_code)