diff --git a/manilaclient/openstack/common/apiclient/base.py b/manilaclient/openstack/common/apiclient/base.py index a4c151515..858bf9150 100644 --- a/manilaclient/openstack/common/apiclient/base.py +++ b/manilaclient/openstack/common/apiclient/base.py @@ -506,6 +506,9 @@ class Resource(object): return self.id == other.id return self._info == other._info + def __ne__(self, other): + return not self == other + def is_loaded(self): return self._loaded diff --git a/manilaclient/tests/unit/test_base.py b/manilaclient/tests/unit/test_base.py index c8775171d..2a43620bf 100644 --- a/manilaclient/tests/unit/test_base.py +++ b/manilaclient/tests/unit/test_base.py @@ -28,19 +28,28 @@ class BaseTest(utils.TestCase): def test_eq(self): # Two resources of the same type with the same id: equal + # The truth of r1==r2 does not imply that r1!=r2 is false in PY2. + # Test that inequality operator is defined and that comparing equal + # items returns False. r1 = common_base.Resource(None, {'id': 1, 'name': 'hi'}) r2 = common_base.Resource(None, {'id': 1, 'name': 'hello'}) - self.assertEqual(r1, r2) + self.assertTrue(r1 == r2) + self.assertFalse(r1 != r2) # Two resources of different types: never equal r1 = common_base.Resource(None, {'id': 1}) r2 = shares.Share(None, {'id': 1}) self.assertNotEqual(r1, r2) + self.assertTrue(r1 != r2) # Two resources with no ID: equal if their info is equal + # The truth of r1==r2 does not imply that r1!=r2 is false in PY2. + # Test that inequality operator is defined and that comparing equal + # items returns False. r1 = common_base.Resource(None, {'name': 'joe', 'age': 12}) r2 = common_base.Resource(None, {'name': 'joe', 'age': 12}) - self.assertEqual(r1, r2) + self.assertTrue(r1 == r2) + self.assertFalse(r1 != r2) def test_findall_invalid_attribute(self): # Make sure findall with an invalid attribute doesn't cause errors.