~ubuntu-branches/ubuntu/trusty/heat/trusty-security

« back to all changes in this revision

Viewing changes to heat/tests/test_fault_middleware.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-09-08 21:51:19 UTC
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: package-import@ubuntu.com-20130908215119-7tcek6gn73275x5k
Tags: upstream-2013.2~b3
ImportĀ upstreamĀ versionĀ 2013.2~b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
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 heat.common import exception as heat_exc
 
16
from heat.openstack.common.rpc import common as rpc_common
 
17
from heat.tests.common import HeatTestCase
 
18
from oslo.config import cfg
 
19
 
 
20
import heat.api.middleware.fault as fault
 
21
 
 
22
 
 
23
class FaultMiddlewareTest(HeatTestCase):
 
24
 
 
25
    def test_openstack_exception_with_kwargs(self):
 
26
        wrapper = fault.FaultWrapper(None)
 
27
        msg = wrapper._error(heat_exc.StackNotFound(stack_name='a'))
 
28
        expected = {'code': 404,
 
29
                    'error': {'message': 'The Stack (a) could not be found.',
 
30
                              'traceback': 'None\n',
 
31
                              'type': 'StackNotFound'},
 
32
                    'explanation': 'The resource could not be found.',
 
33
                    'title': 'Not Found'}
 
34
        self.assertEqual(msg, expected)
 
35
 
 
36
    def test_openstack_exception_without_kwargs(self):
 
37
        wrapper = fault.FaultWrapper(None)
 
38
        msg = wrapper._error(heat_exc.NoServiceEndpoint())
 
39
        expected = {'code': 500,
 
40
                    'error': {'message': 'Response from Keystone does '
 
41
                                         'not contain a Heat endpoint.',
 
42
                              'traceback': 'None\n',
 
43
                              'type': 'NoServiceEndpoint'},
 
44
                    'explanation': 'The server has either erred or is '
 
45
                                   'incapable of performing the requested '
 
46
                                   'operation.',
 
47
                    'title': 'Internal Server Error'}
 
48
        self.assertEqual(msg, expected)
 
49
 
 
50
    def test_remote_exception(self):
 
51
        error = heat_exc.StackNotFound(stack_name='a')
 
52
        exc_info = (type(error), error, None)
 
53
        serialized = rpc_common.serialize_remote_exception(exc_info)
 
54
        remote_error = rpc_common.deserialize_remote_exception(cfg.CONF,
 
55
                                                               serialized)
 
56
        wrapper = fault.FaultWrapper(None)
 
57
        msg = wrapper._error(remote_error)
 
58
        expected_message, expected_traceback = str(remote_error).split('\n', 1)
 
59
        expected = {'code': 404,
 
60
                    'error': {'message': expected_message,
 
61
                              'traceback': expected_traceback,
 
62
                              'type': 'StackNotFound'},
 
63
                    'explanation': 'The resource could not be found.',
 
64
                    'title': 'Not Found'}
 
65
        self.assertEqual(msg, expected)