Crash de la vue pour changer de mot de passe #32
2 changed files with 32 additions and 0 deletions
0
gestion/tests/__init__.py
Normal file
0
gestion/tests/__init__.py
Normal file
32
gestion/tests/test_views.py
Normal file
32
gestion/tests/test_views.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.test import Client, TestCase
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
|
class TestPasswordChangeView(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.user = User.objects.create_user("alice", password="changeme")
|
||||||
|
self.url = reverse("change_password")
|
||||||
|
|
||||||
|
def test_get(self):
|
||||||
|
client = Client()
|
||||||
|
client.force_login(self.user)
|
||||||
|
resp = client.get(self.url)
|
||||||
|
self.assertEqual(resp.status_code, 200)
|
||||||
|
|
||||||
|
def test_post(self):
|
||||||
|
client = Client()
|
||||||
|
client.force_login(self.user)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"old_password": "changeme",
|
||||||
|
"new_password1": "s3cr3tp4ss",
|
||||||
|
"new_password2": "s3cr3tp4ss",
|
||||||
|
}
|
||||||
|
resp = client.post(self.url, data)
|
||||||
|
self.assertEqual(resp.status_code, 200)
|
||||||
|
|
||||||
|
client.logout()
|
||||||
|
self.assertTrue(client.login(username="alice", password="s3cr3tp4ss"))
|
Loading…
Reference in a new issue