diff options
author | adityacp | 2017-05-03 16:12:09 +0530 |
---|---|---|
committer | adityacp | 2017-05-03 16:12:09 +0530 |
commit | 7e8f9ce4e2a04d813f022cf3677dfcd78a7f94c5 (patch) | |
tree | f031d5a3bb578da31e73c5c6d8d0e3b9a151de59 | |
parent | a76be3052276945d688ab8746679f25cd40cad3f (diff) | |
download | online_test-7e8f9ce4e2a04d813f022cf3677dfcd78a7f94c5.tar.gz online_test-7e8f9ce4e2a04d813f022cf3677dfcd78a7f94c5.tar.bz2 online_test-7e8f9ce4e2a04d813f022cf3677dfcd78a7f94c5.zip |
Add views tests for email verification and activation
-rw-r--r-- | yaksh/test_views.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 3fcdde2..37e5ce4 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -7,6 +7,7 @@ from django.core.urlresolvers import reverse from django.test import TestCase from django.test import Client from django.utils import timezone +from django.core import mail from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\ QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\ @@ -97,6 +98,31 @@ class TestProfile(TestCase): self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'yaksh/view_profile.html') + def test_email_verification_for_user_post(self): + """ + POST request to verify email + """ + self.client.login( + username=self.user2.username, + password=self.user2_plaintext_pass + ) + post_response = self.client.post(reverse('yaksh:new_activation'), + data={'email':self.user2.email} + ) + subject = mail.outbox[0].subject.replace(" ", "_") + activation_key = mail.outbox[0].body.split("\n")[2].split("/")[-1] + get_response = self.client.get(reverse('yaksh:activate', + kwargs={'key': activation_key}), + follow=True + ) + updated_profile_user = User.objects.get(id=self.user2.id) + updated_profile = Profile.objects.get(user=updated_profile_user) + self.assertEqual(post_response.status_code, 200) + self.assertEqual(subject, "Yaksh_Email_Verification") + self.assertEqual(get_response.status_code, 200) + self.assertEqual(updated_profile.is_email_verified, True) + self.assertTemplateUsed(get_response, 'yaksh/activation_status.html') + def test_edit_profile_post(self): """ POST request to edit_profile view should update the user's profile @@ -141,6 +167,25 @@ class TestProfile(TestCase): self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'yaksh/editprofile.html') + def test_update_email_for_user_post(self): + """ POST request to update email if multiple users with same email are + found + """ + self.client.login( + username=self.user2.username, + password=self.user2_plaintext_pass + ) + response = self.client.post(reverse('yaksh:update_email'), + data={ + 'username': self.user2.username, + 'email':"demo_user2@mail.com" + } + ) + updated_user = User.objects.get(id=self.user2.id) + self.assertEqual(updated_user.email, "demo_user2@mail.com") + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'yaksh/activation_status.html') + class TestAddQuiz(TestCase): def setUp(self): |