def test_it_randomizes_names_If_collision(self): mock_func = Mock('func') mock_func.side_effect = [True, False] result = get_username({'username': '******'}, user_exists=mock_func) self.assertEqual('yar', result['username'][:3]) self.assertTrue(re.match('[a-f0-9]{16}', result['username'][3:])) # Check it called the exists function twice. self.assertEqual(2, len(mock_func.call_args_list)) self.assertEqual(call('yar'), mock_func.call_args_list[0]) self.assertEqual(call(result['username']), mock_func.call_args_list[1])
def test_random_nantional_characters(self): result = get_username({'username': u'æÆßøØœŒåÅij'}) self.assertEqual('aeaessoooeoeaaij', result['username'])
def test_it_mangles_lukasz_as_little_as_possible(self): # Most special letters get handled by the decompositoon step, # but the Polish Ł has no decomposition info. result = get_username({'username': u'ŁukaszKorecki'}, user_exists=lambda u: False) self.assertEqual('lukaszkorecki', result['username'])
def test_asciification_drops_accents(self): result = get_username({'username': '******'}, user_exists=lambda u: False) self.assertEqual('zoe', result['username'])
def test_it_shortens_proffered_username(self): result = get_username({'username': '******'}, user_exists=lambda u: False) self.assertEqual('long-name-more-than-thirty-cha', result['username'])
def test_it_slugifies_proffered_username(self): result = get_username({'username': '******'}, user_exists=lambda u: False) self.assertEqual('mister-apple-cheeks', result['username'])
def test_it_uses_proffered_username(self): result = get_username({'username': '******'}, user_exists=lambda u: False) self.assertEqual('smarfpon3', result['username'])
def test_it_uses_existing_user_if_supplied(self): user = User.objects.create(username='******') result = get_username({}, user) self.assertEqual('bantha69', result['username'])