mirror of
https://github.com/TrentSPalmer/trentpalmerdotorg.git
synced 2024-12-22 04:52:49 -08:00
add accounts/tests/test_password_change_view.py
This commit is contained in:
parent
a81ec6612f
commit
7bc56f507c
60
accounts/tests/test_password_change_view.py
Normal file
60
accounts/tests/test_password_change_view.py
Normal file
@ -0,0 +1,60 @@
|
||||
from django.test import TestCase
|
||||
from django.contrib.auth.models import User
|
||||
from accounts.models import Account
|
||||
from django.urls import reverse
|
||||
|
||||
|
||||
class PasswordChangeViewTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
user_a = User(email='user_a@example.com', username='user_a')
|
||||
user_a.set_password('password123456')
|
||||
user_a.save()
|
||||
Account.objects.create(user=user_a, twitter_handle='@user_a')
|
||||
|
||||
def test_password_change_view_no_login(self):
|
||||
response = self.client.post(reverse('accounts:password_change'), {
|
||||
'old_password': 'password123456',
|
||||
'new_password1': '123456password',
|
||||
'new_password2': '123456password'
|
||||
}, follow=True)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
user_a = User.objects.get(username='user_a')
|
||||
self.assertTrue(user_a.check_password('password123456'))
|
||||
self.assertTemplateUsed(response, 'audio/index.html')
|
||||
|
||||
def test_password_change_view_mismatched_passwords(self):
|
||||
self.client.login(username='user_a', password='password123456')
|
||||
response = self.client.post(reverse('accounts:password_change'), {
|
||||
'old_password': 'password123456',
|
||||
'new_password1': '123456password',
|
||||
'new_password2': '12346password'
|
||||
}, follow=True)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
user_a = User.objects.get(username='user_a')
|
||||
self.assertTrue(user_a.check_password('password123456'))
|
||||
self.assertTemplateUsed(response, 'base_form.html')
|
||||
|
||||
def test_password_change_view_bad_password(self):
|
||||
self.client.login(username='user_a', password='password123456')
|
||||
response = self.client.post(reverse('accounts:password_change'), {
|
||||
'old_password': 'password12345',
|
||||
'new_password1': '123456password',
|
||||
'new_password2': '123456password'
|
||||
}, follow=True)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
user_a = User.objects.get(username='user_a')
|
||||
self.assertTrue(user_a.check_password('password123456'))
|
||||
self.assertTemplateUsed(response, 'base_form.html')
|
||||
|
||||
def test_password_change_view(self):
|
||||
self.client.login(username='user_a', password='password123456')
|
||||
response = self.client.post(reverse('accounts:password_change'), {
|
||||
'old_password': 'password123456',
|
||||
'new_password1': '123456password',
|
||||
'new_password2': '123456password'
|
||||
}, follow=True)
|
||||
self.assertEquals(response.status_code, 200)
|
||||
user_a = User.objects.get(username='user_a')
|
||||
self.assertTrue(user_a.check_password('123456password'))
|
||||
self.assertTemplateUsed(response, 'base_form.html')
|
Loading…
Reference in New Issue
Block a user