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" )
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")
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" )
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()
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()
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")
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('', '')
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")
def test_clear_strings(self, mock_user): mock_user.objects.filter().exists.return_value = False self.assertEqual(gen_username('foo', 'bar'), 'foo bar')
def test_umlauts(self): self.assertEqual(gen_username('äöü', 'ßüäö'), 'äöü ßüäö')
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')
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, '', '')