Skip to content

Commit

Permalink
define GitlabObject.__eq__() and __ne__() equivalence methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rhansen committed Feb 12, 2016
1 parent f15a7cf commit 01802c0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions gitlab/objects.py
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 01802c0

Please sign in to comment.