示例#1
0
    def test_match_with_sources_list(self):
        """Test match when a list of sources to filter is given"""

        jsmith = UniqueIdentity(uuid='jsmith')
        jsmith.identities = [
            Identity(name='John Smith',
                     email='*****@*****.**',
                     source='scm',
                     uuid='jsmith'),
            Identity(name='John Smith', source='scm', uuid='jsmith'),
            Identity(username='******', source='github', uuid='jsmith'),
            Identity(email='', source='scm', uuid='jsmith')
        ]

        john_smith = UniqueIdentity(uuid='js')
        john_smith.identities = [
            Identity(name='J. Smith', username='******', source='scm'),
            Identity(username='******', source='GitHub-API'),
            Identity(name='Smith. J', source='mls'),
            Identity(name='Smith. J', email='*****@*****.**', source='mls')
        ]

        # With these lists there are not matches
        matcher = GitHubMatcher(sources=['scm'])
        result = matcher.match(jsmith, john_smith)
        self.assertEqual(result, False)

        matcher = GitHubMatcher(sources=['github'])
        result = matcher.match(jsmith, john_smith)
        self.assertEqual(result, False)

        # Only when github-api and github are combined there is a match
        matcher = GitHubMatcher(sources=['github-api', 'github'])
        result = matcher.match(jsmith, john_smith)
        self.assertEqual(result, True)
示例#2
0
    def test_match_same_identity(self):
        """Test whether there is a match comparing the same identity"""

        uid = UniqueIdentity(uuid='John Smith')

        matcher = GitHubMatcher()
        result = matcher.match(uid, uid)

        self.assertEqual(result, True)
示例#3
0
    def test_match_same_uuid(self):
        """Test if there is a match when compares identities with the same UUID"""

        uid1 = UniqueIdentity(uuid='John Smith')
        uid2 = UniqueIdentity(uuid='John Smith')

        matcher = GitHubMatcher()

        result = matcher.match(uid1, uid2)
        self.assertEqual(result, True)

        result = matcher.match(uid2, uid1)
        self.assertEqual(result, True)

        uid1 = UniqueIdentity(uuid=None)
        uid2 = UniqueIdentity(uuid=None)

        result = matcher.match(uid1, uid2)
        self.assertEqual(result, False)
示例#4
0
    def test_match(self):
        """Test match method"""

        # Let's define some identities first
        jsmith = UniqueIdentity(uuid='jsmith')
        jsmith.identities = [
            Identity(name='John Smith',
                     email='*****@*****.**',
                     source='scm'),
            Identity(name='John Smith', source='scm'),
            Identity(username='******', source='github'),
            Identity(email='', source='scm')
        ]

        john_smith = UniqueIdentity(uuid='js')
        john_smith.identities = [
            Identity(name='J. Smith', username='******', source='scm'),
            Identity(username='******', source='scm'),
            Identity(name='Smith. J', source='mls'),
            Identity(name='Smith. J', email='*****@*****.**', source='mls')
        ]

        jsmith_alt = UniqueIdentity(uuid='J. Smith')
        jsmith_alt.identities = [
            Identity(name='J. Smith', username='******', source='alt'),
            Identity(name='John Smith', username='******',
                     source='GitHub-API'),
            Identity(email='', source='alt'),
            Identity(email='jsmith', source='alt')
        ]

        jsmith_not_email = UniqueIdentity(uuid='John Smith')
        jsmith_not_email.identities = [Identity(email='jsmith', source='mls')]

        # Tests
        matcher = GitHubMatcher()

        # First and third must match
        result = matcher.match(jsmith, jsmith_alt)
        self.assertEqual(result, True)

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

        # Comparing with the second and fourth does not produce any match
        result = matcher.match(jsmith, john_smith)
        self.assertEqual(result, False)

        result = matcher.match(jsmith, jsmith_not_email)
        self.assertEqual(result, False)

        result = matcher.match(jsmith_alt, john_smith)
        self.assertEqual(result, False)

        result = matcher.match(jsmith_alt, jsmith_not_email)
        self.assertEqual(result, False)
示例#5
0
    def test_match_with_blacklist(self):
        """Test match when there are entries in the blacklist"""

        # Let's define some identities first
        jsmith = UniqueIdentity(uuid='jsmith')
        jsmith.identities = [
            Identity(name='John Smith',
                     email='*****@*****.**',
                     source='scm'),
            Identity(name='John Smith', source='scm'),
            Identity(username='******', source='github'),
            Identity(email='', source='scm')
        ]

        john_smith = UniqueIdentity(uuid='js')
        john_smith.identities = [
            Identity(name='J. Smith', username='******', source='scm'),
            Identity(username='******', source='GitHub-API'),
            Identity(name='Smith. J', source='mls'),
            Identity(name='Smith. J', email='*****@*****.**', source='mls')
        ]

        jrae = UniqueIdentity(uuid='jrae')
        jrae.identities = [
            Identity(name='Jane Rae', source='scm', uuid='jrae'),
            Identity(username='******',
                     email='*****@*****.**',
                     source='github',
                     uuid='jrae'),
            Identity(name='jrae', source='github', uuid='jrae'),
            Identity(email='*****@*****.**', source='scm', uuid='jrae')
        ]

        jane_rae = UniqueIdentity(uuid='Jane Rae')
        jane_rae.identities = [
            Identity(username='******', source='github', uuid='Jane Rae'),
            Identity(username='******',
                     email='*****@*****.**',
                     source='github',
                     uuid='Jane Rae')
        ]

        # Check matching
        matcher = GitHubMatcher()

        # First identities must match
        result = matcher.match(jsmith, john_smith)
        self.assertEqual(result, True)

        result = matcher.match(john_smith, jsmith)
        self.assertEqual(result, True)

        result = matcher.match(jrae, jane_rae)
        self.assertEqual(result, True)

        result = matcher.match(jane_rae, jrae)
        self.assertEqual(result, True)

        # Add a blacklist
        bl = [
            MatchingBlacklist(excluded='jsmith'),
            MatchingBlacklist(excluded='jrae')
        ]

        matcher = GitHubMatcher(blacklist=bl)

        result = matcher.match(jsmith, john_smith)
        self.assertEqual(result, False)

        result = matcher.match(john_smith, jsmith)
        self.assertEqual(result, False)

        result = matcher.match(jrae, jane_rae)
        self.assertEqual(result, True)

        result = matcher.match(jane_rae, jrae)
        self.assertEqual(result, True)

        # In this case, no match will be found
        bl = [
            MatchingBlacklist(excluded='jsmith'),
            MatchingBlacklist(excluded='jrae'),
            MatchingBlacklist(excluded='janerae')
        ]

        matcher = GitHubMatcher(blacklist=bl)

        result = matcher.match(jsmith, john_smith)
        self.assertEqual(result, False)

        result = matcher.match(john_smith, jsmith)
        self.assertEqual(result, False)

        result = matcher.match(jrae, jane_rae)
        self.assertEqual(result, False)

        result = matcher.match(jane_rae, jrae)
        self.assertEqual(result, False)