Adds unit tests for the LeftHand Exception class

The Exception class for the LeftHand client did not have any
unit tests.

This patch adds unit tests that check the output from the
from_response function and the ClientException class when an
error is passed in.

This patch also removed the use of 'ref' from the
ClientException class. It was added in fa50dedd but was
never officially released so it will not be deprecated.

Change-Id: Ifeb0687e00808155fda116ac97abcf6afaedbff5
This commit is contained in:
Anthony Lee 2015-08-24 08:41:28 -07:00
parent f97ba335db
commit f920a8302f
7 changed files with 69 additions and 13 deletions

View File

@ -70,3 +70,5 @@ Changes in Version 1.0.6
was missing a description.
* Fixes clusterId bug in createVolume (Issue #3)
* Snapshotting of multiples volumes at one time has been enabled
* Added unit test for the Exception class.
* Removed unused error property from LeftHand exceptions.

View File

@ -73,8 +73,6 @@ class ClientException(Exception):
self._error_code = error['messageID']
if 'message' in error:
self._error_desc = error['message']
if 'ref' in error:
self._error_ref = error['ref']
if 'debug1' in error:
self._debug1 = error['debug1']
@ -87,9 +85,6 @@ class ClientException(Exception):
def get_description(self):
return self._error_desc
def get_ref(self):
return self._error_ref
def __str__(self):
formatted_string = "%s (HTTP %s)" % (self.message, self.http_status)
if self._error_code:

View File

@ -0,0 +1,63 @@
# (c) Copyright 2015 Hewlett Packard Development Company, L.P.
#
# 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.
"""Test class of LeftHand Client handling exceptions """
import test_HPLeftHandClient_base
from hplefthandclient import exceptions
class HPLeftHandClientExceptionTestCase(test_HPLeftHandClient_base.
HPLeftHandClientBaseTestCase):
def setUp(self):
super(HPLeftHandClientExceptionTestCase, self).setUp()
def tearDown(self):
super(HPLeftHandClientExceptionTestCase, self).tearDown()
def test_from_response_string_format(self):
self.printHeader('from_response')
# Fake response representing an internal server error.
class FakeResponse(object):
status = 500
fake_response = FakeResponse()
output = exceptions.from_response(fake_response, {}).__str__()
self.assertEquals('Error (HTTP 500)', output)
self.printFooter('from_response')
def test_client_exception_string_format(self):
self.printHeader('client_exception')
fake_error = {'messageID': 999,
'message': 'Fake Description',
'debug1': 'Fake Debug 1',
'debug2': 'Fake Debug 2', }
# Create a fake exception and check that the output is
# converted properly.
client_ex = exceptions.ClientException(error=fake_error)
client_ex.message = "Fake Error"
client_ex.http_status = 500
output = client_ex.__str__()
self.assertEquals("Fake Error (HTTP 500) 999 - Fake Description "
"(1: 'Fake Debug 1') (2: 'Fake Debug 2')",
output)
self.printFooter('client_exception')

View File

@ -1,5 +1,4 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2009-2012 10gen, Inc.
# (c) Copyright 2015 Hewlett Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@ -1,5 +1,4 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2009-2012 10gen, Inc.
# (c) Copyright 2015 Hewlett Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@ -1,5 +1,4 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2009-2012 10gen, Inc.
# (c) Copyright 2015 Hewlett Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.

View File

@ -1,5 +1,4 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2009-2012 10gen, Inc.
# (c) Copyright 2015 Hewlett Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.