Coverage for website/tests/test_signup_password_validation.py: 100%

18 statements  

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

1from django.contrib.auth import get_user_model 

2from django.test import Client, TestCase 

3 

4User = get_user_model() 

5 

6 

7class SignUpPasswordValidationTests(TestCase): 

8 def setUp(self): 

9 # use the test client so middleware (messages, sessions) are exercised 

10 self.client = Client() 

11 

12 def test_rejects_weak_password(self): 

13 data = { 

14 "email": "weak@example.com", 

15 "nome": "Weak User", 

16 "password1": "short", 

17 "password2": "short", 

18 "phone": "+5511999999999", 

19 } 

20 # sign-up URL is mounted at /cadastre-se/ in the project urls 

21 self.client.post("/cadastre-se/", data=data) 

22 self.assertFalse(User.objects.filter(email="weak@example.com").exists()) 

23 

24 def test_accepts_strong_password(self): 

25 # pick a strong password that fits the app's legacy max-length (<=16) 

26 strong = "Strong$Pass1" 

27 data = { 

28 "email": "strong@example.com", 

29 "nome": "Strong User", 

30 "password1": strong, 

31 "password2": strong, 

32 "phone": "+5511999999999", 

33 } 

34 self.client.post("/cadastre-se/", data=data) 

35 user = User.objects.filter(email="strong@example.com").first() 

36 self.assertIsNotNone(user) 

37 if user: 

38 self.assertTrue(user.check_password(strong))