diff options
author | Akshil Verma <akshilverma4@gmail.com> | 2016-12-11 13:37:25 -0600 |
---|---|---|
committer | Akshil Verma <akshilverma4@gmail.com> | 2016-12-19 12:10:03 -0600 |
commit | 78e621faf757e3bf4bd8475c29090bb1c83bc0cd (patch) | |
tree | 1408841f06d38a2b4be1af7b66f42def4da5e73a | |
parent | 56bb3dae5ff2a3a51e54d8fa42277602e7b50710 (diff) | |
download | python-novaclient-78e621faf757e3bf4bd8475c29090bb1c83bc0cd.tar.gz |
Fixed the __ne__ implementation in base.Resource
Any object of Resource class or its child class do not compare with
None as expected. For example if a server has been found and is
clearly not None, the test "server!=None" will be False.
This was occuring because the __eq__ implementation was returning the
'NotImplemented' keyword and the __ne__ implementation was returning
the not of __eq__, which in this case will return False as the
expected python behavior for a the not of NotImplemented is False.
Changed the __ne__ implementation to return the correct boolean value
and added the test case that fails with the older implementation and
passes in the current fix.
Change-Id: I6bf5a6e9c9eed4bbcf6678467df19dfea560b4de
Closes-Bug: #1648207
-rw-r--r-- | novaclient/base.py | 4 | ||||
-rw-r--r-- | novaclient/tests/unit/test_base.py | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/novaclient/base.py b/novaclient/base.py index a091f0b6..0ab0e8ca 100644 --- a/novaclient/base.py +++ b/novaclient/base.py @@ -210,7 +210,9 @@ class Resource(RequestIdMixin): return self._info == other._info def __ne__(self, other): - return not self.__eq__(other) + # Using not of '==' implementation because the not of + # __eq__, when it returns NotImplemented, is returning False. + return not self == other def is_loaded(self): return self._loaded diff --git a/novaclient/tests/unit/test_base.py b/novaclient/tests/unit/test_base.py index 74ceca39..eb70dff9 100644 --- a/novaclient/tests/unit/test_base.py +++ b/novaclient/tests/unit/test_base.py @@ -71,6 +71,12 @@ class BaseTest(utils.TestCase): r2 = base.Resource(None, {'name': 'joe', 'age': 12}) self.assertEqual(r1, r2) + def test_ne(self): + # Two resources of different types: never equal + r1 = base.Resource(None, {'id': 1, 'name': 'test'}) + r2 = object() + self.assertNotEqual(r1, r2) + def test_findall_invalid_attribute(self): cs = fakes.FakeClient(api_versions.APIVersion("2.0")) # Make sure findall with an invalid attribute doesn't cause errors. |