forked from ckan/ckan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ckan#1527] Read email subjects from templates as well
As per @wardi's suggestion. Added a new example plugin with tests
- Loading branch information
Showing
13 changed files
with
173 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Invite for {{ site_title }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Reset your password - {{ site_title }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import ckan.plugins as plugins | ||
import ckan.plugins.toolkit as toolkit | ||
|
||
|
||
class ExampleCustomEmailsPlugin(plugins.SingletonPlugin): | ||
'''An example plugin with custom emails. | ||
''' | ||
plugins.implements(plugins.IConfigurer) | ||
|
||
def update_config(self, config): | ||
|
||
# Add this plugin's templates dir to CKAN's extra_template_paths, so | ||
# that CKAN will use this plugin's custom templates. | ||
toolkit.add_template_directory(config, 'templates') |
5 changes: 5 additions & 0 deletions
5
ckanext/example_theme/custom_emails/templates/emails/invite_user.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Dear {{ user_name }}, come join {{ site_title }}! | ||
|
||
{{ reset_link }} | ||
|
||
**test** |
3 changes: 3 additions & 0 deletions
3
ckanext/example_theme/custom_emails/templates/emails/invite_user_subject.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Come join {{ site_title }} **test** | ||
|
||
# These lines should be ignored |
5 changes: 5 additions & 0 deletions
5
ckanext/example_theme/custom_emails/templates/emails/reset_password.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Reset your password! | ||
|
||
{{ reset_link }} | ||
|
||
**test** |
3 changes: 3 additions & 0 deletions
3
ckanext/example_theme/custom_emails/templates/emails/reset_password_subject.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Lost your password ? - {{ site_title }} **test** | ||
|
||
# These lines should be ignored |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import os | ||
from pylons import config | ||
from ckan import plugins | ||
import ckan.model as model | ||
import ckan.lib.mailer as mailer | ||
from ckan.tests import factories | ||
from ckan.lib.base import render_jinja2 | ||
|
||
from ckan.tests.lib.test_mailer import MailerBase | ||
|
||
from nose.tools import assert_equal, assert_in | ||
|
||
|
||
class TestExampleCustomEmailsPlugin(MailerBase): | ||
@classmethod | ||
def setup_class(cls): | ||
super(TestExampleCustomEmailsPlugin, cls).setup_class() | ||
if not plugins.plugin_loaded('example_theme_custom_emails'): | ||
plugins.load('example_theme_custom_emails') | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
super(TestExampleCustomEmailsPlugin, cls).teardown_class() | ||
plugins.unload('example_theme_custom_emails') | ||
|
||
def _get_template_content(self, name): | ||
|
||
templates_path = os.path.join( | ||
os.path.dirname(os.path.abspath(__file__)), | ||
'templates', 'emails') | ||
with open(os.path.join(templates_path, name), 'r') as f: | ||
return f.read() | ||
|
||
def test_reset_password_custom_subject(self): | ||
user = factories.User() | ||
user_obj = model.User.by_name(user['name']) | ||
|
||
mailer.send_reset_link(user_obj) | ||
|
||
# check it went to the mock smtp server | ||
msgs = self.get_smtp_messages() | ||
assert_equal(len(msgs), 1) | ||
msg = msgs[0] | ||
extra_vars = { | ||
'site_title': config.get('ckan.site_title') | ||
} | ||
expected = render_jinja2('emails/reset_password_subject.txt', | ||
extra_vars) | ||
expected = expected.split('\n')[0] | ||
|
||
subject = self.get_email_subject(msg[3]) | ||
assert_equal(expected, subject) | ||
assert_in('**test**', subject) | ||
|
||
def test_reset_password_custom_body(self): | ||
user = factories.User() | ||
user_obj = model.User.by_name(user['name']) | ||
|
||
mailer.send_reset_link(user_obj) | ||
|
||
# check it went to the mock smtp server | ||
msgs = self.get_smtp_messages() | ||
assert_equal(len(msgs), 1) | ||
msg = msgs[0] | ||
extra_vars = { | ||
'reset_link': mailer.get_reset_link(user_obj) | ||
} | ||
expected = render_jinja2('emails/reset_password.txt', | ||
extra_vars) | ||
body = self.get_email_body(msg[3]) | ||
assert_equal(expected, body) | ||
assert_in('**test**', body) | ||
|
||
def test_invite_user_custom_subject(self): | ||
user = factories.User() | ||
user_obj = model.User.by_name(user['name']) | ||
|
||
mailer.send_invite(user_obj) | ||
|
||
# check it went to the mock smtp server | ||
msgs = self.get_smtp_messages() | ||
assert_equal(len(msgs), 1) | ||
msg = msgs[0] | ||
extra_vars = { | ||
'site_title': config.get('ckan.site_title'), | ||
} | ||
expected = render_jinja2('emails/invite_user_subject.txt', | ||
extra_vars) | ||
expected = expected.split('\n')[0] | ||
|
||
subject = self.get_email_subject(msg[3]) | ||
assert_equal(expected, subject) | ||
assert_in('**test**', subject) | ||
|
||
def test_invite_user_custom_body(self): | ||
user = factories.User() | ||
user_obj = model.User.by_name(user['name']) | ||
|
||
mailer.send_invite(user_obj) | ||
|
||
# check it went to the mock smtp server | ||
msgs = self.get_smtp_messages() | ||
assert_equal(len(msgs), 1) | ||
msg = msgs[0] | ||
extra_vars = { | ||
'reset_link': mailer.get_reset_link(user_obj), | ||
'user_name': user['name'], | ||
'site_title': config.get('ckan.site_title'), | ||
} | ||
expected = render_jinja2('emails/invite_user.txt', | ||
extra_vars) | ||
body = self.get_email_body(msg[3]) | ||
assert_equal(expected, body) | ||
assert_in('**test**', body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters