Skip to content

Commit 01802c0

Browse files
committed
define GitlabObject.__eq__() and __ne__() equivalence methods
1 parent f15a7cf commit 01802c0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

gitlab/objects.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,14 @@ def as_dict(self):
491491
return {k: v for k, v in six.iteritems(self.__dict__)
492492
if (not isinstance(v, BaseManager) and not k[0] == '_')}
493493

494+
def __eq__(self, other):
495+
if type(other) is type(self):
496+
return self.as_dict() == other.as_dict()
497+
return False
498+
499+
def __ne__(self, other):
500+
return not self.__eq__(other)
501+
494502

495503
class UserKey(GitlabObject):
496504
_url = '/users/%(user_id)s/keys'
@@ -544,6 +552,15 @@ def unblock(self, **kwargs):
544552
raise_error_from_response(r, GitlabUnblockError)
545553
self.state = 'active'
546554

555+
def __eq__(self, other):
556+
if type(other) is type(self):
557+
selfdict = self.as_dict()
558+
otherdict = other.as_dict()
559+
selfdict.pop(u'password', None)
560+
otherdict.pop(u'password', None)
561+
return selfdict == otherdict
562+
return False
563+
547564

548565
class UserManager(BaseManager):
549566
obj_cls = User

0 commit comments

Comments
 (0)