本文整理汇总了Python中sortinghat.api.unique_identities函数的典型用法代码示例。如果您正苦于以下问题:Python unique_identities函数的具体用法?Python unique_identities怎么用?Python unique_identities使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了unique_identities函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unify_fast_matching
def test_unify_fast_matching(self):
"""Test unify method using a default matcher and fast matching mode"""
before = api.unique_identities(self.db)
self.assertEqual(len(before), 6)
code = self.cmd.unify(matching='default', fast_matching=True)
self.assertEqual(code, CMD_SUCCESS)
after = api.unique_identities(self.db)
self.assertEqual(len(after), 5)
# jsmith identities with same email address
jsmith = after[0]
self.assertEqual(jsmith.uuid, '178315df7941fc76a6ffb06fd5b00f6932ad9c41')
identities = jsmith.identities
identities.sort(key=lambda x: x.id)
self.assertEqual(len(identities), 7)
id_ = identities[1]
self.assertEqual(id_.email, '[email protected]')
self.assertEqual(id_.source, 'mls')
id_ = identities[3]
self.assertEqual(id_.email, '[email protected]')
self.assertEqual(id_.source, 'scm')
output = sys.stdout.getvalue().strip()
self.assertEqual(output, UNIFY_DEFAULT_OUTPUT)
示例2: test_unify
def test_unify(self):
"""Test unify method using a default matcher"""
before = api.unique_identities(self.db)
self.assertEqual(len(before), 6)
code = self.cmd.unify(matching='default')
self.assertEqual(code, CMD_SUCCESS)
after = api.unique_identities(self.db)
self.assertEqual(len(after), 5)
# jsmith identities with same email address
jsmith = after[1]
self.assertEqual(jsmith.uuid, '72ae225d363c83456d788da14eeb0718efe7a0fc')
identities = jsmith.identities
identities.sort(key=lambda x: x.id)
self.assertEqual(len(identities), 7)
id_ = identities[0]
self.assertEqual(id_.email, '[email protected]')
self.assertEqual(id_.source, 'mls')
id_ = identities[2]
self.assertEqual(id_.email, '[email protected]')
self.assertEqual(id_.source, 'scm')
output = sys.stdout.getvalue().strip()
self.assertEqual(output, UNIFY_DEFAULT_OUTPUT)
示例3: test_unify_email_name_matcher
def test_unify_email_name_matcher(self):
"""Test unify method using the email-name matcher"""
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), 3)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, UNIFY_EMAIL_NAME_OUTPUT)
示例4: test_unify_no_strict
def test_unify_no_strict(self):
"""Test unify method with no strict mode set"""
before = api.unique_identities(self.db)
self.assertEqual(len(before), 6)
code = self.cmd.unify(matching='email-name',
no_strict_matching=True)
self.assertEqual(code, CMD_SUCCESS)
after = api.unique_identities(self.db)
self.assertEqual(len(after), 2)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, UNIFY_NO_STRICT_OUTPUT)
示例5: test_dates_out_of_bounds
def test_dates_out_of_bounds(self):
"""Check dates when they are out of bounds"""
parser = self.get_parser(datadir('sortinghat_ids_dates_out_of_bounds.json'))
# This command returns a success value even when some data is wrong
code = self.cmd.import_identities(parser)
self.assertEqual(code, CMD_SUCCESS)
# Check the contents of the registry
uids = api.unique_identities(self.db)
self.assertEqual(len(uids), 1)
# Jane Roe
uid = uids[0]
self.assertEqual(uid.uuid, '17ab00ed3825ec2f50483e33c88df223264182ba')
enrollments = api.enrollments(self.db, uid.uuid)
self.assertEqual(len(enrollments), 2)
rol0 = enrollments[0]
self.assertEqual(rol0.organization.name, 'Bitergia')
self.assertEqual(rol0.start, datetime.datetime(1999, 1, 1, 0, 0))
# The json file has 2200-01-01T00:00:00
self.assertEqual(rol0.end, datetime.datetime(2100, 1, 1, 0, 0))
rol1 = enrollments[1]
self.assertEqual(rol1.organization.name, 'Example')
# The json file has 1800-01-01T00:00:00
self.assertEqual(rol1.start, datetime.datetime(1900, 1, 1, 0, 0))
self.assertEqual(rol1.end, datetime.datetime(2100, 1, 1, 0, 0))
示例6: test_unify_with_blacklist
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, '[email protected]')
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)
示例7: test_unify_with_sources_list
def test_unify_with_sources_list(self):
"""Test unify method using a sources list"""
sources = ['mls', 'alt']
before = api.unique_identities(self.db)
self.assertEqual(len(before), 6)
code = self.cmd.unify(matching='email-name', sources=sources)
self.assertEqual(code, CMD_SUCCESS)
# Only jrae identities are merged
after = api.unique_identities(self.db)
self.assertEqual(len(after), 5)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, UNIFY_SOURCES_OUTPUT)
示例8: test_valid_identities_already_exist
def test_valid_identities_already_exist(self):
"""Check method when an identity already exists but with distinct UUID"""
# The identity already exists but with a different UUID
uuid = api.add_identity(self.db, 'unknown', email='[email protected]')
api.add_identity(self.db, source='scm', email='[email protected]',
name='John Smith', username='jsmith', uuid=uuid)
api.edit_profile(self.db, uuid, name='John Smith', is_bot=False,
country_code='US')
parser = self.get_parser('data/sortinghat_valid.json')
code = self.cmd.import_identities(parser)
self.assertEqual(code, CMD_SUCCESS)
# Check the contents of the registry
uids = api.unique_identities(self.db)
self.assertEqual(len(uids), 2)
# John Smith
uid = uids[0]
self.assertEqual(uid.uuid, '23fe3a011190a27a7c5cf6f8925de38ff0994d8d')
# The profile was not updated because it was already available
prf = uid.profile
self.assertEqual(prf.uuid, '23fe3a011190a27a7c5cf6f8925de38ff0994d8d')
self.assertEqual(prf.name, 'John Smith')
self.assertEqual(prf.email, None)
self.assertEqual(prf.is_bot, False)
self.assertEqual(prf.country_code, 'US')
self.assertEqual(prf.country.code, 'US')
self.assertEqual(prf.country.name, 'United States of America')
ids = self.sort_identities(uid.identities)
self.assertEqual(len(ids), 3)
id0 = ids[0]
self.assertEqual(id0.id, '03e12d00e37fd45593c49a5a5a1652deca4cf302')
self.assertEqual(id0.name, 'John Smith')
self.assertEqual(id0.email, '[email protected]')
self.assertEqual(id0.username, 'jsmith')
self.assertEqual(id0.source, 'scm')
id1 = ids[1]
self.assertEqual(id1.id, '23fe3a011190a27a7c5cf6f8925de38ff0994d8d')
self.assertEqual(id1.name, None)
self.assertEqual(id1.email, '[email protected]')
self.assertEqual(id1.username, None)
self.assertEqual(id1.source, 'unknown')
id2 = ids[2]
self.assertEqual(id2.id, '75d95d6c8492fd36d24a18bd45d62161e05fbc97')
self.assertEqual(id2.name, 'John Smith')
self.assertEqual(id2.email, '[email protected]')
self.assertEqual(id2.username, None)
self.assertEqual(id2.source, 'scm')
示例9: test_valid_identities_already_exist
def test_valid_identities_already_exist(self):
"""Check method when an identity already exists but with distinct UUID"""
# The identity already exists but with a different UUID
uuid = api.add_identity(self.db, 'unknown', email='[email protected]')
api.add_identity(self.db, source='scm', email='[email protected]',
name='John Smith', username='jsmith', uuid=uuid)
api.edit_profile(self.db, uuid, name='John Smith', is_bot=False,
country_code='US')
parser = self.get_parser(datadir('sortinghat_valid.json'))
code = self.cmd.import_identities(parser)
self.assertEqual(code, CMD_SUCCESS)
# Check the contents of the registry
uids = api.unique_identities(self.db)
self.assertEqual(len(uids), 2)
# John Smith
uid = uids[1]
self.assertEqual(uid.uuid, '2371a34a0ac65fbd9d631464ee41d583ec0e1e88')
# The profile is updated because a new one was given
prf = uid.profile
self.assertEqual(prf.uuid, '2371a34a0ac65fbd9d631464ee41d583ec0e1e88')
self.assertEqual(prf.name, None)
self.assertEqual(prf.email, '[email protected]')
self.assertEqual(prf.gender, 'male')
self.assertEqual(prf.gender_acc, 100)
self.assertEqual(prf.is_bot, True)
self.assertEqual(prf.country, None)
ids = self.sort_identities(uid.identities)
self.assertEqual(len(ids), 3)
id0 = ids[0]
self.assertEqual(id0.id, '2371a34a0ac65fbd9d631464ee41d583ec0e1e88')
self.assertEqual(id0.name, None)
self.assertEqual(id0.email, '[email protected]')
self.assertEqual(id0.username, None)
self.assertEqual(id0.source, 'unknown')
id1 = ids[1]
self.assertEqual(id1.id, '880b3dfcb3a08712e5831bddc3dfe81fc5d7b331')
self.assertEqual(id1.name, 'John Smith')
self.assertEqual(id1.email, '[email protected]')
self.assertEqual(id1.username, None)
self.assertEqual(id1.source, 'scm')
id2 = ids[2]
self.assertEqual(id2.id, 'a9b403e150dd4af8953a52a4bb841051e4b705d9')
self.assertEqual(id2.name, 'John Smith')
self.assertEqual(id2.email, '[email protected]')
self.assertEqual(id2.username, 'jsmith')
self.assertEqual(id2.source, 'scm')
示例10: test_identities_load_file
def test_identities_load_file(self):
""" Check the local loading of identities files """
setup_http_server()
config = Config(CONF_FILE)
task = TaskIdentitiesLoad(config)
task.execute()
# Check the number of identities loaded from local and remote files
nuids = len(api.unique_identities(self.sh_db))
self.assertEqual(nuids, 4)
示例11: test_unify_email_name_matcher_with_blacklist
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, '[email protected]')
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)
示例12: test_create_profile_from_identities
def test_create_profile_from_identities(self):
"""Check whether a profile is created using the data identities"""
parser = self.get_parser(datadir('sortinghat_identities_profiles.json'))
code = self.cmd.import_identities(parser)
self.assertEqual(code, CMD_SUCCESS)
# Check the contents of the registry
uids = api.unique_identities(self.db)
self.assertEqual(len(uids), 3)
# Jane Rae
uid = uids[0]
self.assertEqual(uid.uuid, '17ab00ed3825ec2f50483e33c88df223264182ba')
prf = uid.profile
self.assertEqual(prf.uuid, '17ab00ed3825ec2f50483e33c88df223264182ba')
self.assertEqual(prf.name, 'Jane Roe')
self.assertEqual(prf.email, '[email protected]')
self.assertEqual(prf.gender, None)
self.assertEqual(prf.gender_acc, None)
self.assertEqual(prf.is_bot, False)
self.assertEqual(prf.country_code, None)
self.assertEqual(prf.country, None)
# John Smith
uid = uids[1]
self.assertEqual(uid.uuid, 'a9b403e150dd4af8953a52a4bb841051e4b705d9')
prf = uid.profile
self.assertEqual(prf.uuid, 'a9b403e150dd4af8953a52a4bb841051e4b705d9')
self.assertEqual(prf.name, 'John Smith')
self.assertEqual(prf.email, '[email protected]')
self.assertEqual(prf.gender, None)
self.assertEqual(prf.gender_acc, None)
self.assertEqual(prf.is_bot, False)
self.assertEqual(prf.country_code, None)
self.assertEqual(prf.country, None)
# John Doe
uid = uids[2]
self.assertEqual(uid.uuid, 'c2f8c3d7b49cdbfb0af9fc9db2ca098ec6c06c2f')
prf = uid.profile
self.assertEqual(prf.uuid, 'c2f8c3d7b49cdbfb0af9fc9db2ca098ec6c06c2f')
self.assertEqual(prf.name, 'jdoe')
self.assertEqual(prf.email, '[email protected]')
self.assertEqual(prf.gender, None)
self.assertEqual(prf.gender_acc, None)
self.assertEqual(prf.is_bot, False)
self.assertEqual(prf.country_code, None)
self.assertEqual(prf.country, None)
示例13: test_unify_success_no_recovery_mode
def test_unify_success_no_recovery_mode(self):
"""Test unify method when the recovery file exists but the recovery mode is not active"""
original_log = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/unify_matches.log')
shutil.copyfile(original_log, self.recovery_path)
with unittest.mock.patch('sortinghat.cmd.unify.RecoveryFile.location') as mock_location:
mock_location.return_value = self.recovery_path
before = api.unique_identities(self.db)
self.assertEqual(len(before), 6)
self.assertTrue(os.path.exists(self.recovery_path))
code = self.cmd.unify(matching='default')
self.assertEqual(code, CMD_SUCCESS)
after = api.unique_identities(self.db)
self.assertEqual(len(after), 5)
# jsmith identities with same email address
jsmith = after[0]
self.assertEqual(jsmith.uuid, '178315df7941fc76a6ffb06fd5b00f6932ad9c41')
identities = jsmith.identities
identities.sort(key=lambda x: x.id)
self.assertEqual(len(identities), 7)
id_ = identities[1]
self.assertEqual(id_.email, '[email protected]')
self.assertEqual(id_.source, 'mls')
id_ = identities[3]
self.assertEqual(id_.email, '[email protected]')
self.assertEqual(id_.source, 'scm')
output = sys.stdout.getvalue().strip()
self.assertEqual(output, UNIFY_DEFAULT_OUTPUT)
self.assertTrue(os.path.exists(self.recovery_path))
示例14: test_autogender
def test_autogender(self):
"""Test whether autogender SH command is executed"""
config = Config(CONF_FILE)
# Test default value
self.assertEqual(config.get_conf()['sortinghat']['gender'], False)
config.get_conf()['sortinghat']['gender'] = True
# Load some identities
task = TaskIdentitiesLoad(config)
task.execute()
# Check the number of identities loaded from local and remote files
uids = api.unique_identities(self.sh_db)
task = TaskIdentitiesMerge(config)
self.assertEqual(task.do_autogender(), None)
uids = api.unique_identities(self.sh_db)
found_genders = [uid.profile.gender for uid in uids]
expected_genders = ['male', 'female', 'male', 'male']
self.assertEqual(found_genders, expected_genders)
示例15: test_load
def test_load(self):
"""Test to load identities and organizations from a file"""
code = self.cmd.run(datadir('sortinghat_valid.json'), '--verbose')
self.assertEqual(code, CMD_SUCCESS)
uids = api.unique_identities(self.db)
self.assertEqual(len(uids), 2)
orgs = api.registry(self.db)
self.assertEqual(len(orgs), 3)
output = sys.stdout.getvalue().strip()
self.assertEqual(output, LOAD_OUTPUT)