Example #1
0
    def test_used_username(self, mock_user):
        mock_user.objects.filter().exists.side_effect = (True, False)

        self.assertEqual(
            gen_username('user', 'name'), 'user name 1',
            "If the username already exist, a number should be added to the name"
        )
Example #2
0
    def test_two_used_username(self, mock_user):
        mock_user.objects.filter().exists.side_effect = (True, True, False)

        self.assertEqual(
            gen_username('user', 'name'), 'user name 2',
            "If the username with a number already exist, a higher number should "
            "be added to the name")
Example #3
0
    def test_unstripped_strings(self, mock_user):
        mock_user.objects.filter().exists.return_value = False

        self.assertEqual(
            gen_username('foo ', '  bar\n'), 'foo bar',
            "The retuned value should only have one whitespace between the names"
        )
Example #4
0
 def setUp(self):
     self.user1 = User()
     self.user1.first_name = 'Max'
     self.user1.last_name = 'Mustermann'
     self.user1.username = gen_username(
         self.user1.first_name, self.user1.last_name)
     self.user1.default_password = gen_password()
     self.user1.save()
Example #5
0
 def setUp(self):
     self.user1 = User()
     self.user1.first_name = 'Max'
     self.user1.last_name = 'Mustermann'
     self.user1.username = gen_username(self.user1.first_name,
                                        self.user1.last_name)
     self.user1.default_password = gen_password()
     self.user1.save()
Example #6
0
    def test_umlauts(self, mock_user):
        mock_user.objects.filter().exists.return_value = False

        self.assertEqual(gen_username('äöü', 'ßüäö'), 'äöü ßüäö',
                         "gen_username has also to work with umlauts")
Example #7
0
    def test_two_empty_strings(self, mock_user):
        mock_user.objects.filter().exists.return_value = False

        with self.assertRaises(ValueError,
                               msg="A ValueError should be raised"):
            gen_username('', '')
Example #8
0
    def test_empty_first_string(self, mock_user):
        mock_user.objects.filter().exists.return_value = False

        self.assertEqual(
            gen_username('', 'foobar'), 'foobar',
            "The returned value should not have whitespaces at the beginning")
Example #9
0
    def test_clear_strings(self, mock_user):
        mock_user.objects.filter().exists.return_value = False

        self.assertEqual(gen_username('foo', 'bar'), 'foo bar')
Example #10
0
 def test_umlauts(self):
     self.assertEqual(gen_username('äöü', 'ßüäö'), 'äöü ßüäö')
Example #11
0
    def test_used_username(self):
        User.objects.create(username='******')
        self.assertEqual(gen_username('user', 'name'), 'user name 1')

        User.objects.create(username='******')
        self.assertEqual(gen_username('user', 'name'), 'user name 2')
Example #12
0
 def test_base(self):
     self.assertEqual(gen_username('foo', 'bar'), 'foo bar')
     self.assertEqual(gen_username('foo ', '  bar\n'), 'foo bar')
     self.assertEqual(gen_username('foobar', ''), 'foobar')
     self.assertEqual(gen_username('', 'foobar'), 'foobar')
     self.assertRaises(ValueError, gen_username, '', '')
Example #13
0
 def test_base(self):
     self.assertEqual(gen_username('foo', 'bar'), 'foo bar')
     self.assertEqual(gen_username('foo ', '  bar\n'), 'foo bar')
     self.assertEqual(gen_username('foobar', ''), 'foobar')
     self.assertEqual(gen_username('', 'foobar'), 'foobar')
     self.assertRaises(ValueError, gen_username, '', '')
Example #14
0
 def test_umlauts(self):
     self.assertEqual(gen_username('äöü', 'ßüäö'), 'äöü ßüäö')
Example #15
0
    def test_used_username(self):
        User.objects.create(username='******')
        self.assertEqual(gen_username('user', 'name'), 'user name 1')

        User.objects.create(username='******')
        self.assertEqual(gen_username('user', 'name'), 'user name 2')