コード例 #1
0
 def test_generate_username_with_random(self, mock_random):
     """
     It should return a username with a random integer
     at the end of the username generated.
     """
     saml_other_settings = {'RANDOM': True}
     mock_random.return_value = 4589
     generator = UsernameGenerator(saml_other_settings)
     new_username = generator.generate_username(self.fullname)
     return self.assertEqual(new_username, 'my_self_user_4589')
コード例 #2
0
 def test_username_without_modifications(self):
     """
     If the provided username does not exists
     in database, should return the username without
     any modifications of suffix number.
     """
     saml_other_settings = {'RANDOM': True}
     not_existing_user = '******'
     generator = UsernameGenerator(saml_other_settings)
     new_username = generator.generate_username(not_existing_user)
     return self.assertEqual(new_username, 'another_myself')
コード例 #3
0
 def test_generate_username_with_repetitive_random(self, mock_random):
     """
     If a random generated number is repeated, should append
     a suffix with another random that does not exists.
     """
     saml_other_settings = {'RANDOM': True}
     mock_random.side_effect = [4589, 9819]
     User.objects.create(username='******')
     User.objects.create(username='******')
     generator = UsernameGenerator(saml_other_settings)
     new_username = generator.generate_username('My Self')
     return self.assertEqual(new_username, 'my_self_9819')
コード例 #4
0
    def test_generate_username_unicode(self):
        """
        Ensure that unique usernames can be generated from unicode base names.

        Uses HTML escaping to accurately reproduce an issue experienced with unicode names in decoded HTML requests.
        """
        h = HTMLParser()
        escaped_name = 'חיים_עמרני'
        username = h.unescape(escaped_name)
        user_exists = User.objects.create(username=username)

        generator = UsernameGenerator()
        new_username = generator.generate_username(username)
        return self.assertEqual(new_username, u'{}_1'.format(username))
コード例 #5
0
 def test_generate_username_with_consecutive(self):
     """
     It should return a new user with a consecutive number.
     """
     saml_other_settings = {'RANDOM': False}
     for i in range(1, 6):
         User.objects.create(
             username='******'.format(i)
         )
     generator = UsernameGenerator(saml_other_settings)
     new_username = generator.generate_username(self.fullname)
     # We have 6 users: Five created in the loop with a consecutive
     # number and another one that comes from initial setUp,
     # the first has not consecutive number due to is
     # not neccesary append an differentiator. We expect a new user with
     # the consecutive number 6.
     return self.assertEqual(new_username, 'my_self_user_6')