From 01802c0ceb7c677ea0eb9c6a1b2382048b9fed86 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 11 Feb 2016 22:43:25 -0500 Subject: [PATCH] define GitlabObject.__eq__() and __ne__() equivalence methods --- gitlab/objects.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gitlab/objects.py b/gitlab/objects.py index c03e77e48..9849179f9 100644 --- a/gitlab/objects.py +++ b/gitlab/objects.py @@ -491,6 +491,14 @@ def as_dict(self): 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 @@ def unblock(self, **kwargs): 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