Coverage for accounts/tests/test_models.py: 90.91%
44 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-10 15:27 -0700
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-10 15:27 -0700
1from django.contrib.auth import get_user_model
2from django.test import TestCase
5class CustomUserTests(TestCase):
6 def setUp(self):
7 User = get_user_model()
8 self.user = User.objects.create_user(
9 username="kevin",
10 email="kevin@example.com",
11 password="T3stP@5s123",
12 )
14 self.super_user = User.objects.create_superuser(
15 username="superadmin",
16 email="superadmin@example.com",
17 password="T3stP@5s123",
18 )
20 def test___str__(self):
21 assert self.user.__str__() == self.user.username 1f
22 assert str(self.user) == self.user.username 1f
24 def test_user_get_absolute_url(self):
25 assert self.user.get_absolute_url() == f"/accounts/{self.user.username}/" 1g
27 def test_create_user(self):
28 self.assertEqual(self.user.username, "kevin") 1c
29 self.assertEqual(self.user.email, "kevin@example.com") 1c
30 self.assertTrue(self.user.is_active) 1c
31 self.assertFalse(self.user.is_staff) 1c
32 self.assertFalse(self.user.is_superuser) 1c
34 def test_user_asserts(self):
35 User = get_user_model() 1b
36 try: 1b
37 self.assertIsNotNone(self.user.username) 1b
38 except AttributeError:
39 pass
40 with self.assertRaises(TypeError): 1b
41 User.objects.create_user() 1b
42 with self.assertRaises(TypeError): 1b
43 User.objects.create_user(email="") 1b
44 with self.assertRaises(ValueError): 1b
45 User.objects.create_user(username="", email="", password="foo") 1b
47 def test_create_superuser(self):
48 self.assertEqual(self.super_user.username, "superadmin") 1d
49 self.assertEqual(self.super_user.email, "superadmin@example.com") 1d
50 self.assertTrue(self.super_user.is_active) 1d
51 self.assertTrue(self.super_user.is_staff) 1d
52 self.assertTrue(self.super_user.is_superuser) 1d
54 def test_superuser_asserts(self):
55 User = get_user_model() 1e
56 try: 1e
57 self.assertIsNotNone(self.super_user.username) 1e
58 except AttributeError:
59 pass
60 with self.assertRaises(ValueError): 1e
61 User.objects.create_superuser( 1e
62 username="",
63 email="super@user.com",
64 password="foo",
65 is_superuser=False,
66 )