Coverage for authentication\test\test_passwordRegistration.py: 100%
26 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-13 15:18 +0200
« prev ^ index » next coverage.py v7.10.7, created at 2025-10-13 15:18 +0200
1from django.urls import reverse
2from rest_framework import status
3from rest_framework.test import APITestCase
4from rest_framework.response import Response
5from typing import cast
7class ClientPasswordValidationTests(APITestCase):
8 def setUp(self):
9 self.url = reverse('register-client')
10 self.base_data = {
11 'email': 'client@example.com',
12 'nom': 'Durand',
13 'prenom': 'Alice',
14 'telephone': '0601020304',
15 }
17 def _post_with_password(self, password: str) -> Response:
18 data = self.base_data.copy()
19 data['password'] = password
20 return cast(Response, self.client.post(self.url, data, format='json'))
22 def test_password_too_short(self):
23 response = self._post_with_password('abc123')
24 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
25 self.assertIn('password', response.data)
26 self.assertIn('au moins 12 caractère', str(response.data['password']).lower())
28 def test_password_numeric_only(self):
29 response = self._post_with_password('12345678910112137878')
30 self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
31 self.assertIn('password', response.data)
32 self.assertIn('au moins une majuscule', str(response.data['password']).lower())
35 def test_password_valid(self):
36 response = self._post_with_password('Secur3P@ssw0rd!')
37 self.assertEqual(response.status_code, status.HTTP_201_CREATED)