def test_find_existing_friend_by_username_with_weird_stuff(self): Friend.all_objects.all().delete() existing_friend = Friend.objects.create(username='******') friend = external_user_finder.find_friend(metrix_user_id='123', name='Manuel, García García') self.assertEqual(friend.username, existing_friend.username)
def add_attendance(tournament, ts_tournament): for ts_result in get_results(ts_tournament): friend = external_user_finder.find_friend(ts_result['UserID'], ts_result['Name']) logger.info(f'Using Friend: {friend}') _, created = Attendance.objects.get_or_create(friend=friend, tournament=tournament) if created: logger.info(f'Added attendance of {friend} to {tournament}\n')
def add_results(tournament, ts_tournament): for ts_result in get_results(ts_tournament): friend = external_user_finder.find_friend(ts_result['UserID'], ts_result['Name']) logger.info(f'Using Friend: {friend}') result = Result.objects.create(tournament=tournament, friend=friend, position=get_position(ts_result), division=get_division(ts_result)) logger.info(f'Added result: {result}')
def test_find_non_existing_friend_without_metrix_user_id(self): Friend.all_objects.all().delete() existing_friend = external_user_finder.find_friend(metrix_user_id=None, name='Manuel García García') self.assertEqual(existing_friend.username, 'manuel-garcia-garcia') self.assertEqual(existing_friend.metrix_user_id, None) self.assertEqual(existing_friend.first_name, 'Manuel') self.assertEqual(existing_friend.last_name, 'García García') self.assertEqual(existing_friend.slug, 'manuel-garcia-garcia') self.assertEqual(existing_friend.is_active, False)
def test_find_existing_inactive_friend_by_username(self): Friend.all_objects.all().delete() existing_friend = Friend.objects.create(username='******', first_name='Manolo', last_name='García', is_active=False) friend = external_user_finder.find_friend(metrix_user_id='123', name='Manuel García García') # user changed (except its username) self.assertEqual(friend.username, existing_friend.username) self.assertEqual(friend.metrix_user_id, '123') self.assertEqual(friend.first_name, 'Manuel') self.assertEqual(friend.last_name, 'García García') self.assertEqual(friend.slug, 'manuel-garcia-garcia') self.assertEqual(friend.is_active, existing_friend.is_active)
def test_find_existing_friend_by_username(self): Friend.all_objects.all().delete() existing_friend = Friend.objects.create(username='******', first_name='Manolo', last_name='García', is_active=True) friend = external_user_finder.find_friend(metrix_user_id='123', name='Manuel García García') # user didn't change self.assertEqual(friend.username, existing_friend.username) self.assertEqual(friend.metrix_user_id, None) self.assertEqual(friend.first_name, existing_friend.first_name) self.assertEqual(friend.last_name, existing_friend.last_name) self.assertEqual(friend.slug, existing_friend.slug) self.assertEqual(friend.is_active, existing_friend.is_active)
def test_find_existing_friend_by_username_without_metrix_user_id(self): Friend.all_objects.all().delete() existing_friend = Friend.objects.create(metrix_user_id='123', username='******', first_name='Manolo', last_name='García', is_active=False) friend = external_user_finder.find_friend(metrix_user_id=None, name='Manuel García García') # user changed only first and last names and slug self.assertEqual(friend.username, existing_friend.username) self.assertEqual(friend.metrix_user_id, existing_friend.metrix_user_id) self.assertEqual(friend.first_name, 'Manuel') self.assertEqual(friend.last_name, 'García García') self.assertEqual(friend.slug, 'manuel-garcia-garcia') self.assertEqual(friend.is_active, existing_friend.is_active)
def test_find_non_existing_friend_with_similar_existing_friends_without_metrix_user_id(self): Friend.all_objects.all().delete() Friend.objects.create(username='******', slug='manolo', first_name='Manuel', last_name='García García') Friend.objects.create(username='******', slug='manolo2', first_name='Manuel', last_name='García García') friend = external_user_finder.find_friend(metrix_user_id=None, name='Manuel García García') self.assertEqual(friend.username, 'manuel-garcia-garcia') self.assertEqual(friend.metrix_user_id, None) self.assertEqual(friend.first_name, 'Manuel') self.assertEqual(friend.last_name, 'García García') self.assertEqual(friend.slug, 'manuel-garcia-garcia') self.assertEqual(friend.is_active, False)