Files
deb-python-ceilometerclient/ceilometerclient/tests/test_exc.py
ZhiQiang Fan 55227d6d32 Fix hacking rules: H302,H305,H307,H402
Currently, OpenStack Proposal Bot tries to update requirements with
global requirements, while the upgraded hacking has introduced some
new rules which are not fully handled by current code.

This patch fixes some simple rules which are quite straight-forward.

Change-Id: If8334f69fb1ad34fbbd6ad898e0e92eb3f81e95a
2014-06-11 17:32:16 +08:00

72 lines
3.0 KiB
Python

# Copyright 2013 eNovance
# 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 json
from ceilometerclient import exc
from ceilometerclient.tests import utils
HTTPEXCEPTIONS = {'HTTPBadRequest': exc.HTTPBadRequest,
'HTTPUnauthorized': exc.HTTPUnauthorized,
'HTTPForbidden': exc.HTTPForbidden,
'HTTPNotFound': exc.HTTPNotFound,
'HTTPMethodNotAllowed': exc.HTTPMethodNotAllowed,
'HTTPConflict': exc.HTTPConflict,
'HTTPOverLimit': exc.HTTPOverLimit,
'HTTPInternalServerError': exc.HTTPInternalServerError,
'HTTPNotImplemented': exc.HTTPNotImplemented,
'HTTPBadGateway': exc.HTTPBadGateway,
'HTTPServiceUnavailable': exc.HTTPServiceUnavailable}
class HTTPExceptionsTest(utils.BaseTestCase):
def test_str_no_details(self):
for k, v in HTTPEXCEPTIONS.items():
exception = v()
ret_str = k + " (HTTP " + str(exception.code) + ")"
self.assertEqual(ret_str, str(exception))
def test_str_no_json(self):
for k, v in HTTPEXCEPTIONS.items():
exception = v(details="foo")
ret_str = k + " (HTTP " + str(exception.code) + ")"
self.assertEqual(ret_str, str(exception))
def test_str_no_error_message(self):
for k, v in HTTPEXCEPTIONS.items():
exception = v(details=json.dumps({}))
ret_str = k + " (HTTP " + str(exception.code) + ")"
self.assertEqual(ret_str, str(exception))
def test_str_no_faultstring(self):
for k, v in HTTPEXCEPTIONS.items():
exception = v(
details=json.dumps({"error_message": {"foo": "bar"}}))
ret_str = k + " (HTTP " + str(exception.code) + ")"
self.assertEqual(ret_str, str(exception))
def test_str_error_message_unknown_format(self):
for k, v in HTTPEXCEPTIONS.items():
exception = v(details=json.dumps({"error_message": "oops"}))
ret_str = k + " (HTTP " + str(exception.code) + ")"
self.assertEqual(ret_str, str(exception))
def test_str_faultstring(self):
for k, v in HTTPEXCEPTIONS.items():
exception = v(details=json.dumps(
{"error_message": {"faultstring": "oops"}}))
ret_str = k + " (HTTP " + str(exception.code) + ") ERROR oops"
self.assertEqual(ret_str, str(exception))