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
0a9a39e4
Commit
0a9a39e4
authored
Jun 07, 2016
by
Omar Al-Ithawi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Translatable bulk_email from Address based on platform`s default language
parent
e2c81835
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
1 deletions
+92
-1
lms/djangoapps/bulk_email/tasks.py
+7
-1
lms/djangoapps/bulk_email/tests/test_email.py
+85
-0
No files found.
lms/djangoapps/bulk_email/tasks.py
View file @
0a9a39e4
...
@@ -35,6 +35,7 @@ from django.contrib.auth.models import User
...
@@ -35,6 +35,7 @@ from django.contrib.auth.models import User
from
django.core.mail
import
EmailMultiAlternatives
,
get_connection
from
django.core.mail
import
EmailMultiAlternatives
,
get_connection
from
django.core.mail.message
import
forbid_multi_line_headers
from
django.core.mail.message
import
forbid_multi_line_headers
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.utils.translation
import
override
as
override_language
,
ugettext
as
_
from
bulk_email.models
import
CourseEmail
,
Optout
from
bulk_email.models
import
CourseEmail
,
Optout
from
courseware.courses
import
get_course
from
courseware.courses
import
get_course
...
@@ -373,7 +374,12 @@ def _get_source_address(course_id, course_title, truncate=True):
...
@@ -373,7 +374,12 @@ def _get_source_address(course_id, course_title, truncate=True):
# character appears.
# character appears.
course_name
=
re
.
sub
(
r"[^\w.-]"
,
'_'
,
course_id
.
course
)
course_name
=
re
.
sub
(
r"[^\w.-]"
,
'_'
,
course_id
.
course
)
from_addr_format
=
u'"{course_title}" Course Staff <{course_name}-{from_email}>'
with
override_language
(
settings
.
LANGUAGE_CODE
):
from_addr_format
=
u'{name} {email}'
.
format
(
# Translators: Bulk email from address e.g. ("Physics 101" Course Staff)
name
=
_
(
'"{course_title}" Course Staff'
),
email
=
u'<{course_name}-{from_email}>'
,
)
def
format_address
(
course_title_no_quotes
):
def
format_address
(
course_title_no_quotes
):
"""
"""
...
...
lms/djangoapps/bulk_email/tests/test_email.py
View file @
0a9a39e4
...
@@ -16,6 +16,7 @@ from django.core.urlresolvers import reverse
...
@@ -16,6 +16,7 @@ from django.core.urlresolvers import reverse
from
django.core.management
import
call_command
from
django.core.management
import
call_command
from
django.test.utils
import
override_settings
from
django.test.utils
import
override_settings
from
django.utils
import
translation
from
bulk_email.models
import
Optout
,
BulkEmailFlag
from
bulk_email.models
import
Optout
,
BulkEmailFlag
from
bulk_email.tasks
import
_get_source_address
,
_get_course_email_context
from
bulk_email.tasks
import
_get_source_address
,
_get_course_email_context
from
openedx.core.djangoapps.course_groups.models
import
CourseCohort
from
openedx.core.djangoapps.course_groups.models
import
CourseCohort
...
@@ -133,6 +134,90 @@ class EmailSendFromDashboardTestCase(SharedModuleStoreTestCase):
...
@@ -133,6 +134,90 @@ class EmailSendFromDashboardTestCase(SharedModuleStoreTestCase):
@attr
(
shard
=
1
)
@attr
(
shard
=
1
)
@patch.dict
(
settings
.
FEATURES
,
{
'ENABLE_INSTRUCTOR_EMAIL'
:
True
,
'REQUIRE_COURSE_EMAIL_AUTH'
:
False
})
class
TestLocalizedFromAddress
(
EmailSendFromDashboardTestCase
):
original_ugettext
=
None
mocked_lang
=
'ar'
def
setUp
(
self
):
super
(
TestLocalizedFromAddress
,
self
)
.
setUp
()
translations
=
translation
.
trans_real
.
_translations
# pylint: disable=protected-access
with
translation
.
override
(
self
.
mocked_lang
):
# In order to undo it later
self
.
original_ugettext
=
translations
[
self
.
mocked_lang
]
.
ugettext
mocked_ugettext
=
self
.
get_mocked_ugettext
(
self
.
mocked_lang
)
translations
[
self
.
mocked_lang
]
.
ugettext
=
mocked_ugettext
def
get_mocked_ugettext
(
self
,
lang_code
):
"""
Mocks ugettext to return the lang code with the original string.
e.g.
>>> ugettext = self.mock_ugettext('ar')
>>> ugettext('Hello') == '@AR Hello@'
"""
def
mocked_ugettext
(
msg
):
"""
A mock of ugettext to isolate it from the real `.mo` files.
"""
return
u'@{} {}@'
.
format
(
lang_code
.
upper
(),
msg
)
return
mocked_ugettext
def
send_email
(
self
):
"""
Sends a dummy email to check the `from_addr` translation.
"""
test_email
=
{
'action'
:
'send'
,
'send_to'
:
'["myself"]'
,
'subject'
:
'test subject for myself'
,
'message'
:
'test message for myself'
}
self
.
client
.
post
(
self
.
send_mail_url
,
test_email
)
return
mail
.
outbox
[
0
]
@override_settings
(
LANGUAGE_CODE
=
'en'
)
def
test_english_platform
(
self
):
"""
Test if the email `from` is localized to the platform's preference.
"""
message
=
self
.
send_email
()
self
.
assertNotRegexpMatches
(
message
.
from_email
,
'@.* Course Staff@'
)
@override_settings
(
LANGUAGE_CODE
=
'ar'
)
def
test_arabic_platform
(
self
):
"""
Test if the email `from` is localized to the platform's preference.
"""
message
=
self
.
send_email
()
self
.
assertRegexpMatches
(
message
.
from_email
,
'@AR .* Course Staff@'
)
def
tearDown
(
self
):
super
(
TestLocalizedFromAddress
,
self
)
.
tearDown
()
translations
=
translation
.
trans_real
.
_translations
# pylint: disable=protected-access
translations
[
self
.
mocked_lang
]
.
ugettext
=
self
.
original_ugettext
@attr
(
shard
=
1
)
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
,
autospec
=
True
))
@patch
(
'bulk_email.models.html_to_text'
,
Mock
(
return_value
=
'Mocking CourseEmail.text_message'
,
autospec
=
True
))
class
TestEmailSendFromDashboardMockedHtmlToText
(
EmailSendFromDashboardTestCase
):
class
TestEmailSendFromDashboardMockedHtmlToText
(
EmailSendFromDashboardTestCase
):
"""
"""
...
...
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