Fixes unit-test in troveclient

1. Renames tes___eq__ to be test___eq__,
   because earlier method was not being called.
2. Corrects the test-code in test___eq__,
   for the failures it gave when it started running.
3. Removes some unused code from tests,
   there were few lines/methods which were not used by tests
   just removed/updated them.

Change-Id: I90aa8cb9bb9f5d15697f00df0ba1defa0ef7be59
Closes-Bug: #1441518
This commit is contained in:
Sushil Kumar 2015-04-08 09:06:28 +00:00
parent 0ebf8b3948
commit 5125628c28
4 changed files with 10 additions and 51 deletions

View File

@ -87,10 +87,6 @@ class ManagerTest(testtools.TestCase):
# no cache object, nothing should happen
manager.write_to_completion_cache("non-exist", "val")
def side_effect_func(val):
return val
manager._mock_cache = mock.Mock()
manager._mock_cache.write = mock.Mock(return_value=None)
manager.write_to_completion_cache("mock", "val")
@ -214,9 +210,6 @@ class ManagerListTest(ManagerTest):
def tearDown(self):
super(ManagerListTest, self).tearDown()
def obj_class(self, res, loaded=True):
return res
def test_list_with_body_none(self):
body = None
l = self.manager._list("url", self.response_key, obj_class, body)
@ -490,28 +483,25 @@ class ResourceTest(testtools.TestCase):
self.assertEqual("test-human-id", robj.name)
self.assertEqual(5, robj.test_attr)
def tes___eq__(self):
def test___eq__(self):
robj = self.get_mock_resource_obj()
other = base.Resource()
info_ = {"name": "test-human-id", "test_attr": 5}
robj._info = info_
other._info = {}
self.assertNotTrue(robj.__eq__(other))
robj._info = info_
self.assertTrue(robj.__eq__(other))
self.assertFalse(robj.__eq__(other))
robj.id = "rid"
other.id = "oid"
self.assertNotTrue(robj.__eq__(other))
self.assertFalse(robj.__eq__(other))
other.id = "rid"
self.assertTrue(robj.__eq__(other))
# not instance of the same class
other = mock.Mock()
self.assertNotTrue(robj.__eq__(other))
self.assertEqual(robj.__eq__(other), NotImplemented)
def test_is_loaded(self):
robj = self.get_mock_resource_obj()

View File

@ -118,8 +118,6 @@ class ConfigurationsTest(testtools.TestCase):
self.configurations.instances(123))
def test_update(self):
def side_effect_func(path, config):
return path
self.configurations.api.client.put = self._get_mock_method()
self._resp.status_code = 200
config = '{"test":12}'
@ -129,8 +127,6 @@ class ConfigurationsTest(testtools.TestCase):
self.assertRaises(Exception, self.configurations.update, 34)
def test_edit(self):
def side_effect_func(path, config):
return path
self.configurations.api.client.patch = self._get_mock_method()
self._resp.status_code = 200
config = '{"test":12}'
@ -154,18 +150,6 @@ class ConfigurationParametersTest(testtools.TestCase):
super(ConfigurationParametersTest, self).tearDown()
configurations.ConfigurationParameters.__init__ = self.orig__init
def _get_mock_method(self):
self._resp = mock.Mock()
self._body = None
self._url = None
def side_effect_func(url, body=None):
self._body = body
self._url = url
return (self._resp, body)
return mock.Mock(side_effect=side_effect_func)
def test_list_parameters(self):
def side_effect_func(path, config):
return path

View File

@ -23,18 +23,6 @@ Unit tests for databases.py
"""
class DatabaseTest(testtools.TestCase):
def setUp(self):
super(DatabaseTest, self).setUp()
self.orig__init = databases.Database.__init__
databases.Database.__init__ = mock.Mock(return_value=None)
self.database = databases.Database()
def tearDown(self):
super(DatabaseTest, self).tearDown()
databases.Database.__init__ = self.orig__init
class DatabasesTest(testtools.TestCase):
def setUp(self):
super(DatabasesTest, self).setUp()

View File

@ -23,23 +23,20 @@ from troveclient import utils
class UtilsTest(testtools.TestCase):
def test_add_hookable_mixin(self):
def func():
pass
def func(self):
pass
def test_add_hookable_mixin(self):
hook_type = "hook_type"
mixin = utils.HookableMixin()
mixin.add_hook(hook_type, func)
mixin.add_hook(hook_type, self.func)
self.assertTrue(hook_type in mixin._hooks_map)
self.assertTrue(func in mixin._hooks_map[hook_type])
self.assertTrue(self.func in mixin._hooks_map[hook_type])
def test_run_hookable_mixin(self):
def func():
pass
hook_type = "hook_type"
mixin = utils.HookableMixin()
mixin.add_hook(hook_type, func)
mixin.add_hook(hook_type, self.func)
mixin.run_hooks(hook_type)
def test_environment(self):