From 56c31e2612bc006403b8a32c519a5fd8ad5571ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Sat, 12 Sep 2020 15:03:23 +0200 Subject: [PATCH] Add a unit test for the password view --- gestion/tests/__init__.py | 0 gestion/tests/test_views.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 gestion/tests/__init__.py create mode 100644 gestion/tests/test_views.py diff --git a/gestion/tests/__init__.py b/gestion/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gestion/tests/test_views.py b/gestion/tests/test_views.py new file mode 100644 index 0000000..dfb65d3 --- /dev/null +++ b/gestion/tests/test_views.py @@ -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"))