Debian Codegraph @

aodhclient/tests/unit/test_exceptions.py

raw
1 # Copyright 2016 Hewlett Packard Enterprise Development Company, L.P.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 from unittest import mock
16
17 from oslotest import base
18
19 from aodhclient import exceptions
20
21
22 class AodhclientExceptionsTest(base.BaseTestCase):
23 def test_string_format_base_exception(self):
24 # ensure http_status has initial value N/A
25 self.assertEqual('Unknown Error (HTTP N/A)',
26 '%s' % exceptions.ClientException())
27
28 def test_no_match_exception_from_response(self):
29 resp = mock.MagicMock(status_code=520)
30 resp.headers = {
31 'Content-Type': 'text/plain',
32 'x-openstack-request-id': 'fake-request-id'
33 }
34 resp.text = 'Of course I still love you'
35 e = exceptions.from_response(resp, 'http://no.where:2333/v2/alarms')
36 self.assertIsInstance(e, exceptions.ClientException)
37 self.assertEqual('Of course I still love you (HTTP 520) '
38 '(Request-ID: fake-request-id)', '%s' % e)