
Valence exception messages are not displayed properly. This commit is to fix the same. Change-Id: If4da51f736d28e60a3cfa78094b2e60bedecdd83 Closes-Bug:#1715580
60 lines
2.5 KiB
Python
60 lines
2.5 KiB
Python
# Copyright 2017 99cloud, Inc.
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import mock
|
|
from six.moves import http_client
|
|
|
|
from valenceclient.common.apiclient import exceptions
|
|
from valenceclient import exc
|
|
from valenceclient.tests.unit import utils as test_utils
|
|
|
|
|
|
@mock.patch.object(exceptions, 'from_response')
|
|
class ExcTest(test_utils.BaseTestCase):
|
|
|
|
def setUp(self):
|
|
super(ExcTest, self).setUp()
|
|
self.error = {'code': 'Bad Request',
|
|
'status': '400',
|
|
'detail': 'unsupported parameters',
|
|
'title': 'BadRequest'}
|
|
|
|
self.method = 'call_spongebob'
|
|
self.url = 'http://foo.bar'
|
|
self.expected_json = {'error': {'message': 'unsupported parameters'}}
|
|
|
|
def test_from_response(self, mock_apiclient):
|
|
fake_response = mock.Mock(status_code=http_client.BAD_REQUEST)
|
|
exc.from_response(fake_response, error=self.error,
|
|
method=self.method, url=self.url)
|
|
self.assertEqual(http_client.BAD_REQUEST, fake_response.status_code)
|
|
self.assertEqual(self.expected_json, fake_response.json())
|
|
mock_apiclient.assert_called_once_with(
|
|
fake_response, method=self.method, url=self.url)
|
|
|
|
def test_from_response_status(self, mock_apiclient):
|
|
fake_response = mock.Mock(status=http_client.BAD_REQUEST)
|
|
fake_response.getheader.return_value = 'fake-header'
|
|
delattr(fake_response, 'status_code')
|
|
|
|
exc.from_response(fake_response, error=self.error, method=self.method,
|
|
url=self.url)
|
|
expected_header = {'Content-Type': 'fake-header'}
|
|
self.assertEqual(expected_header, fake_response.headers)
|
|
self.assertEqual(http_client.BAD_REQUEST, fake_response.status_code)
|
|
self.assertEqual(self.expected_json, fake_response.json())
|
|
mock_apiclient.assert_called_once_with(
|
|
fake_response, method=self.method, url=self.url)
|