def test_match_filtered_identities(self):
        """Test whether filtered identities match"""

        jsmith = UsernameIdentity('1', None, 'jsmith')
        jsmith_alt = UsernameIdentity('2', 'jsmith', 'jsmith')
        jsmith_uuid = UsernameIdentity('3', 'jsmith', 'john.smith')

        matcher = UsernameMatcher()

        result = matcher.match_filtered_identities(jsmith, jsmith_alt)
        self.assertEqual(result, True)

        result = matcher.match_filtered_identities(jsmith, jsmith_uuid)
        self.assertEqual(result, False)

        result = matcher.match_filtered_identities(jsmith_alt, jsmith)
        self.assertEqual(result, True)

        result = matcher.match_filtered_identities(jsmith_alt, jsmith_uuid)
        self.assertEqual(result, True)

        result = matcher.match_filtered_identities(jsmith_uuid, jsmith)
        self.assertEqual(result, False)

        result = matcher.match_filtered_identities(jsmith_uuid, jsmith_alt)
        self.assertEqual(result, True)
Ejemplo n.º 2
0
    def test_match_filtered_identities_instances(self):
        """Test whether it raises an error when ids are not UsernameIdentities"""

        fid = UsernameIdentity('1', None, 'jsmith')

        matcher = UsernameMatcher()

        self.assertRaises(ValueError, matcher.match_filtered_identities, 'John Smith', fid)
        self.assertRaises(ValueError, matcher.match_filtered_identities, fid, 'John Smith')
        self.assertRaises(ValueError, matcher.match_filtered_identities, None, fid)
        self.assertRaises(ValueError, matcher.match_filtered_identities, fid, None)
        self.assertRaises(ValueError, matcher.match_filtered_identities, 'John Smith', 'John Doe')
    def test_match_filtered_identities_with_blacklist(self):
        """Test whether filtered identities match when there is a blacklist"""

        jsmith = UsernameIdentity('1', None, 'jsmith')
        jsmith_alt = UsernameIdentity('2', 'jsmith', 'jsmith')
        jsmith_uuid = UsernameIdentity('3', 'jsmith', 'john.smith')
        john_alt = UsernameIdentity('4', None, 'john.smith')
        jsmith_none = UsernameIdentity('4', 'john.smith', None)
        jdoe_none = UsernameIdentity('4', 'jdoe', None)

        bl = [MatchingBlacklist(excluded='JSMITH')]

        matcher = UsernameMatcher(blacklist=bl)

        result = matcher.match_filtered_identities(jsmith, jsmith_alt)
        self.assertEqual(result, False)

        result = matcher.match_filtered_identities(jsmith, jsmith_uuid)
        self.assertEqual(result, False)

        result = matcher.match_filtered_identities(jsmith_alt, jsmith)
        self.assertEqual(result, False)

        # Same UUID
        result = matcher.match_filtered_identities(jsmith_alt, jsmith_uuid)
        self.assertEqual(result, True)

        result = matcher.match_filtered_identities(jsmith_uuid, jsmith)
        self.assertEqual(result, False)

        # Same UUID
        result = matcher.match_filtered_identities(jsmith_uuid, jsmith_alt)
        self.assertEqual(result, True)

        result = matcher.match_filtered_identities(jsmith_uuid, john_alt)
        self.assertEqual(result, True)

        result = matcher.match_filtered_identities(john_alt, jsmith_uuid)
        self.assertEqual(result, True)

        # Although the UUID is equal to None, these two does not match
        result = matcher.match_filtered_identities(jsmith_none, jdoe_none)
        self.assertEqual(result, False)