summaryrefslogtreecommitdiff
path: root/gitlab/objects.py
diff options
context:
space:
mode:
authorRichard Hansen <rhansen@rhansen.org>2016-02-11 22:43:25 -0500
committerRichard Hansen <rhansen@rhansen.org>2016-02-12 02:40:58 -0500
commit01802c0ceb7c677ea0eb9c6a1b2382048b9fed86 (patch)
tree0e6e31590fa3572d8dc386b68960241efdf493d8 /gitlab/objects.py
parentf15a7cfd7edbbc55ff4fb5d41995dee033517963 (diff)
downloadgitlab-01802c0ceb7c677ea0eb9c6a1b2382048b9fed86.tar.gz
define GitlabObject.__eq__() and __ne__() equivalence methods
Diffstat (limited to 'gitlab/objects.py')
-rw-r--r--gitlab/objects.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/gitlab/objects.py b/gitlab/objects.py
index c03e77e..9849179 100644
--- a/gitlab/objects.py
+++ b/gitlab/objects.py
@@ -491,6 +491,14 @@ class GitlabObject(object):
return {k: v for k, v in six.iteritems(self.__dict__)
if (not isinstance(v, BaseManager) and not k[0] == '_')}
+ def __eq__(self, other):
+ if type(other) is type(self):
+ return self.as_dict() == other.as_dict()
+ return False
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
class UserKey(GitlabObject):
_url = '/users/%(user_id)s/keys'
@@ -544,6 +552,15 @@ class User(GitlabObject):
raise_error_from_response(r, GitlabUnblockError)
self.state = 'active'
+ def __eq__(self, other):
+ if type(other) is type(self):
+ selfdict = self.as_dict()
+ otherdict = other.as_dict()
+ selfdict.pop(u'password', None)
+ otherdict.pop(u'password', None)
+ return selfdict == otherdict
+ return False
+
class UserManager(BaseManager):
obj_cls = User