summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrabhu Ramachandran2017-02-07 18:45:23 +0530
committerGitHub2017-02-07 18:45:23 +0530
commitb862008cf0022396520eb4e02b078f33ddba9695 (patch)
tree75db9240a6b78ff01abb5b822e5f0e8e58952332
parent01fefb8c7ec31bc6514438eb6b9568a3980ca3de (diff)
parent820448e70830d8248e91a19a225e43673877f0c1 (diff)
downloadonline_test-b862008cf0022396520eb4e02b078f33ddba9695.tar.gz
online_test-b862008cf0022396520eb4e02b078f33ddba9695.tar.bz2
online_test-b862008cf0022396520eb4e02b078f33ddba9695.zip
Merge pull request #212 from ankitjavalkar/view-test-pass-reset
Add view test case for password reset and password change
-rw-r--r--yaksh/test_views.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index e052441..7757f70 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -2,6 +2,7 @@ from datetime import datetime
import pytz
import os
from django.contrib.auth.models import Group
+from django.contrib.auth import authenticate
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test import Client
@@ -48,6 +49,7 @@ class TestProfile(TestCase):
self.user1.delete()
self.user2.delete()
+
def test_has_profile_for_user_without_profile(self):
"""
If no profile exists for user passed as argument return False
@@ -1573,3 +1575,70 @@ class TestGrader(TestCase):
# Then
self.assertEqual(response.status_code, 404)
+
+class TestPasswordReset(TestCase):
+ def setUp(self):
+ # Create User with profile
+ self.user1_plaintext_pass = 'demo1'
+ self.user1 = User.objects.create_user(
+ username='demo_user1',
+ password=self.user1_plaintext_pass,
+ first_name='first_name',
+ last_name='last_name',
+ email='demo1@test.com'
+ )
+
+ Profile.objects.create(
+ user=self.user1,
+ roll_number=10,
+ institute='IIT',
+ department='Chemical',
+ position='Student',
+ timezone='UTC'
+ )
+
+ def tearDown(self):
+ self.user1.delete()
+
+ def test_password_reset_post(self):
+ """
+ POST request to password_reset view should return a valid response
+ """
+ # When
+ response = self.client.post(reverse('password_reset'),
+ data={
+ 'email': self.user1.email,
+ }
+ )
+
+ # Then
+ self.assertEqual(response.context['email'], self.user1.email)
+ self.assertEqual(response.status_code, 302)
+ self.assertRedirects(response, '/exam/reset/password_reset/mail_sent/')
+
+ def test_password_change_post(self):
+ """
+ POST request to password_change view should change the user password
+ """
+ # Given
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+
+ # When
+ response = self.client.post(reverse('password_change'),
+ data={
+ 'old_password': self.user1_plaintext_pass,
+ 'new_password1': 'new_demo1_pass',
+ 'new_password2': 'new_demo1_pass'
+ }
+ )
+
+ # Then
+ self.assertIsNotNone(authenticate(username='demo_user1', password='new_demo1_pass'))
+ self.assertEqual(response.status_code, 302)
+ self.assertRedirects(response, '/exam/reset/password_change/done/')
+
+ # Finally
+ self.client.logout()