1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 15:15:22 +00:00

Test password change view

This commit is contained in:
Real-Gecko 2020-06-16 15:17:21 +06:00
parent b85e246aed
commit d9785e397b

View file

@ -1,4 +1,4 @@
from django.contrib.auth.models import User
from django.contrib.auth.models import Permission, User
from django.shortcuts import reverse
from django.test import Client, TestCase
@ -6,7 +6,9 @@ from django.test import Client, TestCase
class AccountsTestCase(TestCase):
def setUp(self):
self.client.login(username='admin', password='admin')
User.objects.create_user(username='test', password='test')
user = User.objects.create_user(username='test', password='test')
permission = Permission.objects.get(codename='change_password')
user.user_permissions.add(permission)
def test_profile(self):
response = self.client.get(reverse('profile'))
@ -26,3 +28,37 @@ class AccountsTestCase(TestCase):
response = client.get(reverse('logout'))
self.assertRedirects(response, reverse('login'))
def test_password_change(self):
client = Client()
logged_in = client.login(username='test', password='test')
self.assertTrue(logged_in)
response = client.get(reverse('change_password'))
self.assertEqual(response.status_code, 200)
response = client.post(
reverse('change_password'),
{
'old_password': 'wrongpass',
'new_password1': 'newpw',
'new_password2': 'newpw',
},
)
self.assertEqual(response.status_code, 200)
response = client.post(
reverse('change_password'),
{
'old_password': 'test',
'new_password1': 'newpw',
'new_password2': 'newpw',
},
)
self.assertRedirects(response, reverse('profile'))
client.logout()
logged_in = client.login(username='test', password='newpw')
self.assertTrue(logged_in)