Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix equality and hash for BaseLDAPEntry #101

Open
adiroiban opened this issue May 12, 2018 · 1 comment
Open

Fix equality and hash for BaseLDAPEntry #101

adiroiban opened this issue May 12, 2018 · 1 comment

Comments

@adiroiban
Copy link
Member

Equality is implemented as

    def __eq__(self, other):
        if not isinstance(other, BaseLDAPEntry):
            return NotImplemented
        if self.dn != other.dn:
            return 0

        my = self.keys()
        my.sort()
        its = other.keys()
        its.sort()
        if my != its:
            return 0
        for key in my:
            myAttr = self[key]
            itsAttr = other[key]
            if myAttr != itsAttr:
                return 0
        return 1

while hash as

    def __hash__(self):
        return hash(self.dn)

I think that this is wrong is it can lead to objects with same hash but which are not equal.

@adiroiban
Copy link
Member Author

A bunch of tests to consider

    def testEquality(self):
        """
        They are equal as they have the same DN and same attributes and
        values.
        """

    def testHashEquality(self):
        """
        Objects which are equal have the same hash.
        """

    def testHashInequalityEquality(self):
        """
        Objects which are not equal have different hash,
        even if the have the same DN (but different attributes).
        """

    def testInequalityWithSameType(self):
        """
        Instances for different DN are not equal.
        """


    def testInequalityWithOtherTypes(self):
        """
        Instances are not equal to other types.
        """

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant