Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
3127ac2b
Commit
3127ac2b
authored
Jan 05, 2015
by
Christine Lytwynec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mock html_to_text for tests
parent
20220dc3
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
27 additions
and
6 deletions
+27
-6
lms/djangoapps/bulk_email/tests/test_course_optout.py
+2
-1
lms/djangoapps/bulk_email/tests/test_email.py
+16
-1
lms/djangoapps/bulk_email/tests/test_err_handling.py
+2
-2
lms/djangoapps/bulk_email/tests/test_models.py
+2
-2
lms/djangoapps/bulk_email/tests/test_tasks.py
+1
-0
lms/djangoapps/instructor/tests/test_api.py
+2
-0
lms/djangoapps/instructor_task/tests/test_api.py
+2
-0
No files found.
lms/djangoapps/bulk_email/tests/test_course_optout.py
View file @
3127ac2b
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
Unit tests for student optouts from course email
Unit tests for student optouts from course email
"""
"""
import
json
import
json
from
mock
import
patch
from
mock
import
patch
,
Mock
from
django.core
import
mail
from
django.core
import
mail
from
django.core.management
import
call_command
from
django.core.management
import
call_command
...
@@ -18,6 +18,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
...
@@ -18,6 +18,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
xmodule.modulestore.tests.factories
import
CourseFactory
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
@override_settings
(
MODULESTORE
=
TEST_DATA_MOCK_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MOCK_MODULESTORE
)
class
TestOptoutCourseEmails
(
ModuleStoreTestCase
):
class
TestOptoutCourseEmails
(
ModuleStoreTestCase
):
...
...
lms/djangoapps/bulk_email/tests/test_email.py
View file @
3127ac2b
...
@@ -3,7 +3,9 @@
...
@@ -3,7 +3,9 @@
Unit tests for sending course email
Unit tests for sending course email
"""
"""
import
json
import
json
from
mock
import
patch
from
mock
import
patch
,
Mock
import
os
from
unittest
import
skipIf
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core
import
mail
from
django.core
import
mail
...
@@ -90,6 +92,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
...
@@ -90,6 +92,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
"""
"""
patch
.
stopall
()
patch
.
stopall
()
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_INSTRUCTOR_EMAIL'
:
True
,
'REQUIRE_COURSE_EMAIL_AUTH'
:
True
})
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_INSTRUCTOR_EMAIL'
:
True
,
'REQUIRE_COURSE_EMAIL_AUTH'
:
True
})
def
test_email_disabled
(
self
):
def
test_email_disabled
(
self
):
"""
"""
...
@@ -105,6 +108,8 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
...
@@ -105,6 +108,8 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
# We should get back a HttpResponseForbidden (status code 403)
# We should get back a HttpResponseForbidden (status code 403)
self
.
assertContains
(
response
,
"Email is not enabled for this course."
,
status_code
=
403
)
self
.
assertContains
(
response
,
"Email is not enabled for this course."
,
status_code
=
403
)
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
def
test_send_to_self
(
self
):
def
test_send_to_self
(
self
):
"""
"""
Make sure email send to myself goes to myself.
Make sure email send to myself goes to myself.
...
@@ -130,6 +135,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
...
@@ -130,6 +135,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
'['
+
self
.
course
.
display_name
+
']'
+
' test subject for myself'
'['
+
self
.
course
.
display_name
+
']'
+
' test subject for myself'
)
)
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
def
test_send_to_staff
(
self
):
def
test_send_to_staff
(
self
):
"""
"""
Make sure email send to staff and instructors goes there.
Make sure email send to staff and instructors goes there.
...
@@ -153,6 +159,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
...
@@ -153,6 +159,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
[
self
.
instructor
.
email
]
+
[
s
.
email
for
s
in
self
.
staff
]
[
self
.
instructor
.
email
]
+
[
s
.
email
for
s
in
self
.
staff
]
)
)
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
def
test_send_to_all
(
self
):
def
test_send_to_all
(
self
):
"""
"""
Make sure email send to all goes there.
Make sure email send to all goes there.
...
@@ -176,6 +183,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
...
@@ -176,6 +183,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
[
self
.
instructor
.
email
]
+
[
s
.
email
for
s
in
self
.
staff
]
+
[
s
.
email
for
s
in
self
.
students
]
[
self
.
instructor
.
email
]
+
[
s
.
email
for
s
in
self
.
staff
]
+
[
s
.
email
for
s
in
self
.
students
]
)
)
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
def
test_no_duplicate_emails_staff_instructor
(
self
):
def
test_no_duplicate_emails_staff_instructor
(
self
):
"""
"""
Test that no duplicate emails are sent to a course instructor that is
Test that no duplicate emails are sent to a course instructor that is
...
@@ -184,6 +192,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
...
@@ -184,6 +192,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
CourseStaffRole
(
self
.
course
.
id
)
.
add_users
(
self
.
instructor
)
CourseStaffRole
(
self
.
course
.
id
)
.
add_users
(
self
.
instructor
)
self
.
test_send_to_all
()
self
.
test_send_to_all
()
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
def
test_no_duplicate_emails_enrolled_staff
(
self
):
def
test_no_duplicate_emails_enrolled_staff
(
self
):
"""
"""
Test that no duplicate emials are sent to a course instructor that is
Test that no duplicate emials are sent to a course instructor that is
...
@@ -192,6 +201,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
...
@@ -192,6 +201,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
CourseEnrollment
.
enroll
(
self
.
instructor
,
self
.
course
.
id
)
CourseEnrollment
.
enroll
(
self
.
instructor
,
self
.
course
.
id
)
self
.
test_send_to_all
()
self
.
test_send_to_all
()
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
def
test_unicode_subject_send_to_all
(
self
):
def
test_unicode_subject_send_to_all
(
self
):
"""
"""
Make sure email (with Unicode characters) send to all goes there.
Make sure email (with Unicode characters) send to all goes there.
...
@@ -220,9 +230,12 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
...
@@ -220,9 +230,12 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
'['
+
self
.
course
.
display_name
+
'] '
+
uni_subject
'['
+
self
.
course
.
display_name
+
'] '
+
uni_subject
)
)
@skipIf
(
os
.
environ
.
get
(
"Travis"
)
==
'true'
,
"Skip this test in Travis CI."
)
def
test_unicode_message_send_to_all
(
self
):
def
test_unicode_message_send_to_all
(
self
):
"""
"""
Make sure email (with Unicode characters) send to all goes there.
Make sure email (with Unicode characters) send to all goes there.
Note that this test is skipped on Travis because we can't use the
function `html_to_text` as it is currently implemented on Travis.
"""
"""
# Now we know we have pulled up the instructor dash's email view
# Now we know we have pulled up the instructor dash's email view
# (in the setUp method), we can test sending an email.
# (in the setUp method), we can test sending an email.
...
@@ -247,6 +260,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
...
@@ -247,6 +260,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
message_body
=
mail
.
outbox
[
0
]
.
body
message_body
=
mail
.
outbox
[
0
]
.
body
self
.
assertIn
(
uni_message
,
message_body
)
self
.
assertIn
(
uni_message
,
message_body
)
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
def
test_unicode_students_send_to_all
(
self
):
def
test_unicode_students_send_to_all
(
self
):
"""
"""
Make sure email (with Unicode characters) send to all goes there.
Make sure email (with Unicode characters) send to all goes there.
...
@@ -278,6 +292,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
...
@@ -278,6 +292,7 @@ class TestEmailSendFromDashboard(ModuleStoreTestCase):
@override_settings
(
BULK_EMAIL_EMAILS_PER_TASK
=
3
)
@override_settings
(
BULK_EMAIL_EMAILS_PER_TASK
=
3
)
@patch
(
'bulk_email.tasks.update_subtask_status'
)
@patch
(
'bulk_email.tasks.update_subtask_status'
)
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
def
test_chunked_queries_send_numerous_emails
(
self
,
email_mock
):
def
test_chunked_queries_send_numerous_emails
(
self
,
email_mock
):
"""
"""
Test sending a large number of emails, to test the chunked querying
Test sending a large number of emails, to test the chunked querying
...
...
lms/djangoapps/bulk_email/tests/test_err_handling.py
View file @
3127ac2b
...
@@ -11,7 +11,7 @@ from django.core.management import call_command
...
@@ -11,7 +11,7 @@ from django.core.management import call_command
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.db
import
DatabaseError
from
django.db
import
DatabaseError
import
json
import
json
from
mock
import
patch
from
mock
import
patch
,
Mock
from
smtplib
import
SMTPDataError
,
SMTPServerDisconnected
,
SMTPConnectError
from
smtplib
import
SMTPDataError
,
SMTPServerDisconnected
,
SMTPConnectError
from
bulk_email.models
import
CourseEmail
,
SEND_TO_ALL
from
bulk_email.models
import
CourseEmail
,
SEND_TO_ALL
...
@@ -36,7 +36,7 @@ class EmailTestException(Exception):
...
@@ -36,7 +36,7 @@ class EmailTestException(Exception):
"""Mock exception for email testing."""
"""Mock exception for email testing."""
pass
pass
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
@override_settings
(
MODULESTORE
=
TEST_DATA_MOCK_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MOCK_MODULESTORE
)
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_INSTRUCTOR_EMAIL'
:
True
,
'REQUIRE_COURSE_EMAIL_AUTH'
:
False
})
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_INSTRUCTOR_EMAIL'
:
True
,
'REQUIRE_COURSE_EMAIL_AUTH'
:
False
})
class
TestEmailErrors
(
ModuleStoreTestCase
):
class
TestEmailErrors
(
ModuleStoreTestCase
):
...
...
lms/djangoapps/bulk_email/tests/test_models.py
View file @
3127ac2b
...
@@ -7,12 +7,12 @@ from django.conf import settings
...
@@ -7,12 +7,12 @@ from django.conf import settings
from
student.tests.factories
import
UserFactory
from
student.tests.factories
import
UserFactory
from
mock
import
patch
from
mock
import
patch
,
Mock
from
bulk_email.models
import
CourseEmail
,
SEND_TO_STAFF
,
CourseEmailTemplate
,
CourseAuthorization
from
bulk_email.models
import
CourseEmail
,
SEND_TO_STAFF
,
CourseEmailTemplate
,
CourseAuthorization
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
from
opaque_keys.edx.locations
import
SlashSeparatedCourseKey
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
class
CourseEmailTest
(
TestCase
):
class
CourseEmailTest
(
TestCase
):
"""Test the CourseEmail model."""
"""Test the CourseEmail model."""
...
...
lms/djangoapps/bulk_email/tests/test_tasks.py
View file @
3127ac2b
...
@@ -71,6 +71,7 @@ def my_update_subtask_status(entry_id, current_task_id, new_subtask_status):
...
@@ -71,6 +71,7 @@ def my_update_subtask_status(entry_id, current_task_id, new_subtask_status):
update_subtask_status
(
entry_id
,
current_task_id
,
new_subtask_status
)
update_subtask_status
(
entry_id
,
current_task_id
,
new_subtask_status
)
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
class
TestBulkEmailInstructorTask
(
InstructorTaskCourseTestCase
):
class
TestBulkEmailInstructorTask
(
InstructorTaskCourseTestCase
):
"""Tests instructor task that send bulk email."""
"""Tests instructor task that send bulk email."""
...
...
lms/djangoapps/instructor/tests/test_api.py
View file @
3127ac2b
...
@@ -139,6 +139,7 @@ class TestCommonExceptions400(TestCase):
...
@@ -139,6 +139,7 @@ class TestCommonExceptions400(TestCase):
@override_settings
(
MODULESTORE
=
TEST_DATA_MOCK_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MOCK_MODULESTORE
)
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_INSTRUCTOR_EMAIL'
:
True
,
'REQUIRE_COURSE_EMAIL_AUTH'
:
False
})
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_INSTRUCTOR_EMAIL'
:
True
,
'REQUIRE_COURSE_EMAIL_AUTH'
:
False
})
class
TestInstructorAPIDenyLevels
(
ModuleStoreTestCase
,
LoginEnrollmentTestCase
):
class
TestInstructorAPIDenyLevels
(
ModuleStoreTestCase
,
LoginEnrollmentTestCase
):
"""
"""
...
@@ -2228,6 +2229,7 @@ class TestInstructorAPIRegradeTask(ModuleStoreTestCase, LoginEnrollmentTestCase)
...
@@ -2228,6 +2229,7 @@ class TestInstructorAPIRegradeTask(ModuleStoreTestCase, LoginEnrollmentTestCase)
@override_settings
(
MODULESTORE
=
TEST_DATA_MOCK_MODULESTORE
)
@override_settings
(
MODULESTORE
=
TEST_DATA_MOCK_MODULESTORE
)
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_INSTRUCTOR_EMAIL'
:
True
,
'REQUIRE_COURSE_EMAIL_AUTH'
:
False
})
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_INSTRUCTOR_EMAIL'
:
True
,
'REQUIRE_COURSE_EMAIL_AUTH'
:
False
})
class
TestInstructorSendEmail
(
ModuleStoreTestCase
,
LoginEnrollmentTestCase
):
class
TestInstructorSendEmail
(
ModuleStoreTestCase
,
LoginEnrollmentTestCase
):
"""
"""
...
...
lms/djangoapps/instructor_task/tests/test_api.py
View file @
3127ac2b
"""
"""
Test for LMS instructor background task queue management
Test for LMS instructor background task queue management
"""
"""
from
mock
import
patch
,
Mock
from
bulk_email.models
import
CourseEmail
,
SEND_TO_ALL
from
bulk_email.models
import
CourseEmail
,
SEND_TO_ALL
from
courseware.tests.factories
import
UserFactory
from
courseware.tests.factories
import
UserFactory
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
...
@@ -158,6 +159,7 @@ class InstructorTaskModuleSubmitTest(InstructorTaskModuleTestCase):
...
@@ -158,6 +159,7 @@ class InstructorTaskModuleSubmitTest(InstructorTaskModuleTestCase):
self
.
_test_submit_task
(
submit_delete_problem_state_for_all_students
)
self
.
_test_submit_task
(
submit_delete_problem_state_for_all_students
)
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
))
class
InstructorTaskCourseSubmitTest
(
TestReportMixin
,
InstructorTaskCourseTestCase
):
class
InstructorTaskCourseSubmitTest
(
TestReportMixin
,
InstructorTaskCourseTestCase
):
"""Tests API methods that involve the submission of course-based background tasks."""
"""Tests API methods that involve the submission of course-based background tasks."""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment