From eff546b51b7b0d025b48472b4238325f406f06db Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 15 May 2017 15:06:11 +0530 Subject: Add tests to check bulk email sending --- yaksh/test_views.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'yaksh/test_views.py') diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 37e5ce4..7018bd2 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -8,6 +8,7 @@ from django.test import TestCase from django.test import Client from django.utils import timezone from django.core import mail +from django.core.files.uploadedfile import SimpleUploadedFile from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\ QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\ @@ -1072,6 +1073,57 @@ class TestCourseDetail(TestCase): self.assertTemplateUsed(response, 'yaksh/course_detail.html') + def test_send_mail_to_course_students(self): + """ Check if bulk mail is sent to multiple students enrolled in a course + """ + self.client.login( + username=self.user1.username, + password=self.user1_plaintext_pass + ) + self.student2 = User.objects.create_user( + username='demo_student2', + password=self.student_plaintext_pass, + first_name='student_first_name', + last_name='student_last_name', + email='demo_student2@test.com' + ) + self.student3 = User.objects.create_user( + username='demo_student3', + password=self.student_plaintext_pass, + first_name='student_first_name', + last_name='student_last_name', + email='demo_student3@test.com' + ) + self.student4 = User.objects.create_user( + username='demo_student4', + password=self.student_plaintext_pass, + first_name='student_first_name', + last_name='student_last_name', + email='demo_student4@test.com' + ) + user_ids = [self.student.id, self.student2.id, self.student3.id, + self.student4.id] + user_emails = [self.student.email, self.student2.email, + self.student3.email, self.student4.email] + + self.user1_course.students.add(*user_ids) + attachment = SimpleUploadedFile("file.txt", b"Test") + response = self.client.post(reverse('yaksh:reject_users', + kwargs={'course_id': self.user1_course.id}), + data={'send_mail': 'send_mail', 'email_attach': [attachment], + 'subject': 'test_bulk_mail', 'body': 'Test_Mail', + 'check': user_ids} + ) + attachment_file = mail.outbox[0].attachments[0][0] + subject = mail.outbox[0].subject + body = mail.outbox[0].alternatives[0][0] + recipients = mail.outbox[0].recipients() + self.assertEqual(attachment_file, "file.txt") + self.assertEqual(subject, "test_bulk_mail") + self.assertEqual(body, "Test_Mail") + self.assertSequenceEqual(recipients, user_emails) + + class TestEnrollRequest(TestCase): def setUp(self): self.client = Client() -- cgit From a002ab59dbff856ee3838078cbe4f8fa439fd894 Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 12 Jun 2017 18:23:17 +0530 Subject: Change views tests to check send email --- yaksh/test_views.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'yaksh/test_views.py') diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 7018bd2..caec9d4 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -1108,7 +1108,7 @@ class TestCourseDetail(TestCase): self.user1_course.students.add(*user_ids) attachment = SimpleUploadedFile("file.txt", b"Test") - response = self.client.post(reverse('yaksh:reject_users', + response = self.client.post(reverse('yaksh:send_mail', kwargs={'course_id': self.user1_course.id}), data={'send_mail': 'send_mail', 'email_attach': [attachment], 'subject': 'test_bulk_mail', 'body': 'Test_Mail', @@ -1123,6 +1123,20 @@ class TestCourseDetail(TestCase): self.assertEqual(body, "Test_Mail") self.assertSequenceEqual(recipients, user_emails) + # Test for get request in send mail + get_response = self.client.get(reverse('yaksh:send_mail', + kwargs={'course_id': self.user1_course.id} + )) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.context['course'], self.user1_course) + + # Test if no users are selected + post_response = self.client.post(reverse('yaksh:send_mail', + kwargs={'course_id': self.user1_course.id}), + data={'check': []} + ) + self.assertIn('select', post_response.context['message']) + class TestEnrollRequest(TestCase): def setUp(self): -- cgit From 30bd1c36a4abea6c6afea3a52d3a84d335c5673a Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 17 Aug 2017 10:50:52 +0530 Subject: Change test_views.py - Remove validation test case for send mail - Pep8 changes --- yaksh/test_views.py | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'yaksh/test_views.py') diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 3c5b0dd..763f5ff 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -1869,16 +1869,19 @@ class TestCourseDetail(TestCase): user_ids = [self.student.id, self.student2.id, self.student3.id, self.student4.id] user_emails = [self.student.email, self.student2.email, - self.student3.email, self.student4.email] + self.student3.email, self.student4.email] self.user1_course.students.add(*user_ids) attachment = SimpleUploadedFile("file.txt", b"Test") - response = self.client.post(reverse('yaksh:send_mail', - kwargs={'course_id': self.user1_course.id}), - data={'send_mail': 'send_mail', 'email_attach': [attachment], - 'subject': 'test_bulk_mail', 'body': 'Test_Mail', - 'check': user_ids} - ) + email_data = { + 'send_mail': 'send_mail', 'email_attach': [attachment], + 'subject': 'test_bulk_mail', 'body': 'Test_Mail', + 'check': user_ids + } + self.client.post(reverse( + 'yaksh:send_mail', kwargs={'course_id': self.user1_course.id}), + data=email_data + ) attachment_file = mail.outbox[0].attachments[0][0] subject = mail.outbox[0].subject body = mail.outbox[0].alternatives[0][0] @@ -1889,18 +1892,12 @@ class TestCourseDetail(TestCase): self.assertSequenceEqual(recipients, user_emails) # Test for get request in send mail - get_response = self.client.get(reverse('yaksh:send_mail', - kwargs={'course_id': self.user1_course.id} - )) - self.assertEqual(response.status_code, 200) - self.assertEqual(response.context['course'], self.user1_course) - - # Test if no users are selected - post_response = self.client.post(reverse('yaksh:send_mail', - kwargs={'course_id': self.user1_course.id}), - data={'check': []} - ) - self.assertIn('select', post_response.context['message']) + get_response = self.client.get(reverse( + 'yaksh:send_mail', kwargs={'course_id': self.user1_course.id}) + ) + self.assertEqual(get_response.status_code, 200) + self.assertEqual(get_response.context['course'], self.user1_course) + self.assertEqual(get_response.context['status'], 'mail') class TestEnrollRequest(TestCase): -- cgit From d6c4d44dca8520926fd781b87e35ecd7843e515c Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 22 Aug 2017 12:25:47 +0530 Subject: Change test_views for send mail test --- yaksh/test_views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh/test_views.py') diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 763f5ff..f8a7c87 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -1897,7 +1897,7 @@ class TestCourseDetail(TestCase): ) self.assertEqual(get_response.status_code, 200) self.assertEqual(get_response.context['course'], self.user1_course) - self.assertEqual(get_response.context['status'], 'mail') + self.assertEqual(get_response.context['state'], 'mail') class TestEnrollRequest(TestCase): -- cgit