Coverage for website/manager.py: 94%

18 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2025-09-13 15:29 -0300

1from django.contrib.auth.base_user import BaseUserManager 

2 

3 

4class UserManager(BaseUserManager): 

5 def create_user(self, email, password, **extra_fields): 

6 """ 

7 Creates and saves an User with the given email and password. 

8 """ 

9 if not email: 

10 raise ValueError("Users must have an email address") 

11 

12 user = self.model(email=self.normalize_email(email), **extra_fields) 

13 

14 user.set_password(password) 

15 user.save() 

16 return user 

17 

18 def create_superuser(self, email, password, **extra_fields): 

19 """ 

20 Creates and saves a superuser with the given email and password. 

21 """ 

22 extra_fields.setdefault("is_staff", True) 

23 extra_fields.setdefault("is_superuser", True) 

24 extra_fields.setdefault("is_active", True) 

25 

26 if extra_fields.get("is_staff") is not True: 

27 raise ValueError("Superuser must have is_staff=True.") 

28 if extra_fields.get("is_superuser") is not True: 

29 raise ValueError("Superuser must have is_superuser=True.") 

30 

31 return self.create_user(email, password=password, **extra_fields)