From fac6b08b911fd3265e14dc86501396410de587d2 Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Thu, 20 Sep 2012 16:52:17 +0000 Subject: [PATCH] Fix solidfire unit tests A couple of tests attempted to reimplement assertRaises(), but did so badly. self.fail() will raise AssertionError, which is a subclass of Exception, so even if the tested exception wasn't raised, it would silently treat it as a success. This buggy testing code hid a failure to properly test the intended functionality in test_delete_volume_fails_no_volume. Change-Id: I4e31bf6cb3b042aa2d9ba2a5ccaf40319d0fc124 --- nova/tests/test_solidfire.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/nova/tests/test_solidfire.py b/nova/tests/test_solidfire.py index 73018031..475281d2 100644 --- a/nova/tests/test_solidfire.py +++ b/nova/tests/test_solidfire.py @@ -84,6 +84,13 @@ class SolidFireVolumeTestCase(test.TestCase): else: LOG.error('Crap, unimplemented API call in Fake:%s' % method) + def fake_issue_api_request_no_volume(obj, method, params): + if method is 'ListVolumesForAccount': + LOG.info('Called Fake ListVolumesForAccount...') + return {'result': {'volumes': []}} + else: + return obj.fake_issue_api_request(method, params) + def fake_issue_api_request_fails(obj, method, params): return {'error': {'code': 000, 'name': 'DummyError', @@ -126,11 +133,8 @@ class SolidFireVolumeTestCase(test.TestCase): 'size': 1, 'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66'} sfv = SolidFire() - try: - sfv.create_volume(testvol) - self.fail("Should have thrown Error") - except Exception: - pass + self.assertRaises(exception.SolidFireAPIDataException, + sfv.create_volume, testvol) def test_create_sfaccount(self): sfv = SolidFire() @@ -172,17 +176,14 @@ class SolidFireVolumeTestCase(test.TestCase): def test_delete_volume_fails_no_volume(self): self.stubs.Set(SolidFire, '_issue_api_request', - self.fake_issue_api_request) + self.fake_issue_api_request_no_volume) testvol = {'project_id': 'testprjid', 'name': 'no-name', 'size': 1, 'id': 'a720b3c0-d1f0-11e1-9b23-0800200c9a66'} sfv = SolidFire() - try: - model_update = sfv.delete_volume(testvol) - self.fail("Should have thrown Error") - except Exception: - pass + self.assertRaises(exception.VolumeNotFound, + sfv.delete_volume, testvol) def test_delete_volume_fails_account_lookup(self): self.stubs.Set(SolidFire, '_issue_api_request',