コード例 #1
0
    def test_unify_email_name_matcher_with_blacklist(self):
        """Test unify method using a blacklist"""

        # Add some entries to the blacklist
        api.add_to_matching_blacklist(self.db, 'Jane Rae Doe')
        api.add_to_matching_blacklist(self.db, '*****@*****.**')

        before = api.unique_identities(self.db)
        self.assertEqual(len(before), 6)

        code = self.cmd.unify(matching='email-name')
        self.assertEqual(code, CMD_SUCCESS)

        after = api.unique_identities(self.db)
        self.assertEqual(len(after), 5)

        # Only two identities were merged due to the blacklist
        jsmith = after[0]
        self.assertEqual(jsmith.uuid,
                         '178315df7941fc76a6ffb06fd5b00f6932ad9c41')
        self.assertEqual(len(jsmith.identities), 4)

        jsmith = after[1]
        self.assertEqual(jsmith.uuid,
                         '400fdfaab5918d1b7e0e0efba4797abdc378bd7d')
        self.assertEqual(len(jsmith.identities), 6)
コード例 #2
0
    def _load_test_dataset(self):
        import datetime

        self.db.clear()

        # Add country
        with self.db.connect() as session:
            # Add a country
            us = Country(code='US', name='United States of America', alpha3='USA')
            session.add(us)

        # Add organizations
        api.add_organization(self.db, 'Example')
        api.add_domain(self.db, 'Example', 'example.com', is_top_domain=True)
        api.add_domain(self.db, 'Example', 'example.net', is_top_domain=True)

        api.add_organization(self.db, 'Bitergia')
        api.add_domain(self.db, 'Bitergia', 'bitergia.net', is_top_domain=True)
        api.add_domain(self.db, 'Bitergia', 'bitergia.com', is_top_domain=True)
        api.add_domain(self.db, 'Bitergia', 'api.bitergia.com', is_top_domain=False)
        api.add_domain(self.db, 'Bitergia', 'test.bitergia.com', is_top_domain=False)

        api.add_organization(self.db, 'Unknown')

        # Add John Smith identity
        jsmith_uuid = api.add_identity(self.db, 'scm', '*****@*****.**',
                                       'John Smith', 'jsmith')
        api.add_identity(self.db, 'scm', '*****@*****.**', 'John Smith',
                         uuid=jsmith_uuid)
        api.edit_profile(self.db, jsmith_uuid, email='*****@*****.**', is_bot=True)

        # Add Joe Roe identity
        jroe_uuid = api.add_identity(self.db, 'scm', '*****@*****.**',
                                     'Jane Roe', 'jroe')
        api.add_identity(self.db, 'scm', '*****@*****.**',
                         uuid=jroe_uuid)
        api.add_identity(self.db, 'unknown', '*****@*****.**',
                         uuid=jroe_uuid)
        api.edit_profile(self.db, jroe_uuid, name='Jane Roe', email='*****@*****.**',
                         is_bot=False, country_code='US')

        # Add unique identity, this one won't have neither identities
        # nor enrollments
        api.add_unique_identity(self.db,
                                '0000000000000000000000000000000000000000')

        # Add enrollments
        api.add_enrollment(self.db, jsmith_uuid, 'Example')

        api.add_enrollment(self.db, jroe_uuid, 'Example')
        api.add_enrollment(self.db, jroe_uuid, 'Bitergia',
                           datetime.datetime(1999, 1, 1),
                           datetime.datetime(2000, 1, 1))
        api.add_enrollment(self.db, jroe_uuid, 'Bitergia',
                           datetime.datetime(2006, 1, 1),
                           datetime.datetime(2008, 1, 1))

        # Add blacklist
        api.add_to_matching_blacklist(self.db, '*****@*****.**')
        api.add_to_matching_blacklist(self.db, 'John Smith')
コード例 #3
0
    def test_default_matching_method_with_blacklist(self):
        """Check whether new identities are merged using a blacklist"""

        # Add some entries to the blacklist
        api.add_to_matching_blacklist(self.db, 'John Smith')
        api.add_to_matching_blacklist(self.db, '*****@*****.**')

        # Add this identity to 'Jonh Smith' and merge
        code = self.cmd.add('unknown',
                            name='John Smith',
                            email='*****@*****.**',
                            matching='default')
        self.assertEqual(code, CMD_SUCCESS)

        # These two will not match due to the blacklist
        code1 = self.cmd.add('scm',
                             name='Jane Rae',
                             email='*****@*****.**',
                             matching='default')
        code2 = self.cmd.add('mls',
                             name='Jane Rae',
                             email='*****@*****.**',
                             matching='default')
        self.assertEqual(code1, CMD_SUCCESS)
        self.assertEqual(code2, CMD_SUCCESS)

        # Check output
        output = sys.stdout.getvalue().strip()
        self.assertEqual(output, ADD_OUTPUT_BLACKLIST)
コード例 #4
0
    def test_unify_with_blacklist(self):
        """Test unify method using a blacklist"""

        # Add some entries to the blacklist
        api.add_to_matching_blacklist(self.db, 'Jane Rae Doe')
        api.add_to_matching_blacklist(self.db, '*****@*****.**')

        before = api.unique_identities(self.db)
        self.assertEqual(len(before), 6)

        code = self.cmd.unify(matching='default')
        self.assertEqual(code, CMD_SUCCESS)

        # No match was found
        after = api.unique_identities(self.db)
        self.assertEqual(len(after), 6)
コード例 #5
0
    def test_unify_with_blacklist(self):
        """Test unify method using a blacklist"""

        # Add some entries to the blacklist
        api.add_to_matching_blacklist(self.db, 'Jane Rae Doe')
        api.add_to_matching_blacklist(self.db, '*****@*****.**')

        before = api.unique_identities(self.db)
        self.assertEqual(len(before), 6)

        code = self.cmd.unify(matching='default')
        self.assertEqual(code, CMD_SUCCESS)

        # No match was found
        after = api.unique_identities(self.db)
        self.assertEqual(len(after), 6)
コード例 #6
0
    def test_unify_email_name_matcher_with_blacklist(self):
        """Test unify method using a blacklist"""

        # Add some entries to the blacklist
        api.add_to_matching_blacklist(self.db, 'Jane Rae Doe')
        api.add_to_matching_blacklist(self.db, '*****@*****.**')

        before = api.unique_identities(self.db)
        self.assertEqual(len(before), 6)

        code = self.cmd.unify(matching='email-name')
        self.assertEqual(code, CMD_SUCCESS)

        after = api.unique_identities(self.db)
        self.assertEqual(len(after), 5)

        # Only two identities were merged due to the blacklist
        jsmith = after[2]
        self.assertEqual(jsmith.uuid, '75d95d6c8492fd36d24a18bd45d62161e05fbc97')
        self.assertEqual(len(jsmith.identities), 6)
コード例 #7
0
    def test_unify_email_name_matcher_with_blacklist(self):
        """Test unify method using a blacklist"""

        # Add some entries to the blacklist
        api.add_to_matching_blacklist(self.db, 'Jane Rae Doe')
        api.add_to_matching_blacklist(self.db, '*****@*****.**')

        before = api.unique_identities(self.db)
        self.assertEqual(len(before), 6)

        code = self.cmd.unify(matching='email-name')
        self.assertEqual(code, CMD_SUCCESS)

        after = api.unique_identities(self.db)
        self.assertEqual(len(after), 5)

        # Only two identities were merged due to the blacklist
        jsmith = after[2]
        self.assertEqual(jsmith.uuid,
                         '75d95d6c8492fd36d24a18bd45d62161e05fbc97')
        self.assertEqual(len(jsmith.identities), 6)
コード例 #8
0
ファイル: test_cmd_add.py プロジェクト: jgbarah/sortinghat
    def test_default_matching_method_with_blacklist(self):
        """Check whether new identities are merged using a blacklist"""

        # Add some entries to the blacklist
        api.add_to_matching_blacklist(self.db, 'John Smith')
        api.add_to_matching_blacklist(self.db, '*****@*****.**')

        # Add this identity to 'Jonh Smith' and merge
        code = self.cmd.add('unknown', name='John Smith', email='*****@*****.**',
                            matching='default')
        self.assertEqual(code, CMD_SUCCESS)

        # These two will not match due to the blacklist
        code1 = self.cmd.add('scm', name='Jane Rae', email='*****@*****.**',
                            matching='default')
        code2 = self.cmd.add('mls', name='Jane Rae', email='*****@*****.**',
                            matching='default')
        self.assertEqual(code1, CMD_SUCCESS)
        self.assertEqual(code2, CMD_SUCCESS)

        # Check output
        output = sys.stdout.getvalue().strip()
        self.assertEqual(output, ADD_OUTPUT_BLACKLIST)
コード例 #9
0
    def test_unify_email_name_matcher_with_blacklist(self):
        """Test unify method using a blacklist"""

        # Add some entries to the blacklist
        api.add_to_matching_blacklist(self.db, 'Jane Rae Doe')
        api.add_to_matching_blacklist(self.db, '*****@*****.**')

        before = api.unique_identities(self.db)
        self.assertEqual(len(before), 6)

        code = self.cmd.unify(matching='email-name')
        self.assertEqual(code, CMD_SUCCESS)

        after = api.unique_identities(self.db)
        self.assertEqual(len(after), 5)

        # Only two identities were merged due to the blacklist
        jsmith = after[0]
        self.assertEqual(jsmith.uuid, '178315df7941fc76a6ffb06fd5b00f6932ad9c41')
        self.assertEqual(len(jsmith.identities), 4)

        jsmith = after[1]
        self.assertEqual(jsmith.uuid, '400fdfaab5918d1b7e0e0efba4797abdc378bd7d')
        self.assertEqual(len(jsmith.identities), 6)
コード例 #10
0
    def setUp(self):
        if not hasattr(sys.stdout, 'getvalue'):
            self.fail('This test needs to be run in buffered mode')

        self.db = Database(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST, DB_PORT)

        api.add_to_matching_blacklist(self.db, '*****@*****.**')
        api.add_to_matching_blacklist(self.db, 'John Smith')
        api.add_to_matching_blacklist(self.db, 'Bitergia')
        api.add_to_matching_blacklist(self.db, 'John Doe')

        # Create command
        self.kwargs = {'user' : DB_USER,
                       'password' : DB_PASSWORD,
                       'database' :DB_NAME,
                       'host' : DB_HOST,
                       'port' : DB_PORT}

        self.cmd = Blacklist(**self.kwargs)
コード例 #11
0
ファイル: test_cmd_blacklist.py プロジェクト: acs/sortinghat
 def load_test_dataset(self):
     api.add_to_matching_blacklist(self.db, '*****@*****.**')
     api.add_to_matching_blacklist(self.db, 'John Smith')
     api.add_to_matching_blacklist(self.db, 'Bitergia')
     api.add_to_matching_blacklist(self.db, 'John Doe')
コード例 #12
0
 def load_test_dataset(self):
     api.add_to_matching_blacklist(self.db, '*****@*****.**')
     api.add_to_matching_blacklist(self.db, 'John Smith')
     api.add_to_matching_blacklist(self.db, 'Bitergia')
     api.add_to_matching_blacklist(self.db, 'John Doe')