##// END OF EJS Templates
pull-requests: use proper diff calculation for versioning of PRs.
pull-requests: use proper diff calculation for versioning of PRs.

File last commit:

r4306:09801de9 default
r4426:f4c1c6eb default
Show More
test_mako_emails.py
194 lines | 6.9 KiB | text/x-python | PythonLexer
/ rhodecode / tests / lib / test_mako_emails.py
core: dropped deprecated PartialRenderer that depends on pylons.
r2310 # -*- coding: utf-8 -*-
code: update copyrights to 2020
r4306 # Copyright (C) 2010-2020 RhodeCode GmbH
core: dropped deprecated PartialRenderer that depends on pylons.
r2310 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
project: added all source files and assets
r1
import pytest
dan
emails: updated emails design and data structure they provide....
r4038 import collections
project: added all source files and assets
r1
core: dropped deprecated PartialRenderer that depends on pylons.
r2310 from rhodecode.lib.partial_renderer import PyramidPartialRenderer
emails: fixed newlines in email templates that can break email sending code.
r1728 from rhodecode.lib.utils2 import AttributeDict
dan
emails: updated emails design and data structure they provide....
r4038 from rhodecode.model.db import User
project: added all source files and assets
r1 from rhodecode.model.notification import EmailNotificationModel
core: dropped deprecated PartialRenderer that depends on pylons.
r2310 def test_get_template_obj(app, request_stub):
project: added all source files and assets
r1 template = EmailNotificationModel().get_renderer(
core: dropped deprecated PartialRenderer that depends on pylons.
r2310 EmailNotificationModel.TYPE_TEST, request_stub)
assert isinstance(template, PyramidPartialRenderer)
project: added all source files and assets
r1
home: moved home and repo group views into pyramid....
r1774 def test_render_email(app, http_host_only_stub):
project: added all source files and assets
r1 kwargs = {}
subject, headers, body, body_plaintext = EmailNotificationModel().render_email(
EmailNotificationModel.TYPE_TEST, **kwargs)
# subject
assert subject == 'Test "Subject" hello "world"'
# headers
assert headers == 'X=Y'
# body plaintext
assert body_plaintext == 'Email Plaintext Body'
# body
dan
emails: updated emails design and data structure they provide....
r4038 notification_footer1 = 'This is a notification from RhodeCode.'
notification_footer2 = 'http://{}/'.format(http_host_only_stub)
assert notification_footer1 in body
assert notification_footer2 in body
notifications: adjusting how instance name is passed and fixing tests
r512 assert 'Email Body' in body
project: added all source files and assets
r1
home: moved home and repo group views into pyramid....
r1774 def test_render_pr_email(app, user_admin):
dan
emails: updated emails design and data structure they provide....
r4038 ref = collections.namedtuple(
'Ref', 'name, type')('fxies123', 'book')
project: added all source files and assets
r1
pr = collections.namedtuple('PullRequest',
'pull_request_id, title, description, source_ref_parts, source_ref_name, target_ref_parts, target_ref_name')(
200, 'Example Pull Request', 'Desc of PR', ref, 'bookmark', ref, 'Branch')
dan
emails: updated emails design and data structure they provide....
r4038 source_repo = target_repo = collections.namedtuple(
'Repo', 'type, repo_name')('hg', 'pull_request_1')
project: added all source files and assets
r1
kwargs = {
dan
emails: updated emails design and data structure they provide....
r4038 'user': User.get_first_super_admin(),
project: added all source files and assets
r1 'pull_request': pr,
'pull_request_commits': [],
'pull_request_target_repo': target_repo,
'pull_request_target_repo_url': 'x',
'pull_request_source_repo': source_repo,
'pull_request_source_repo_url': 'x',
'pull_request_url': 'http://localhost/pr1',
}
subject, headers, body, body_plaintext = EmailNotificationModel().render_email(
EmailNotificationModel.TYPE_PULL_REQUEST, **kwargs)
# subject
dan
emails: updated emails design and data structure they provide....
r4038 assert subject == '@test_admin (RhodeCode Admin) requested a pull request review. !200: "Example Pull Request"'
emails: fixed newlines in email templates that can break email sending code.
r1728
pull-requests: added update pull-requests email+notifications...
r4120 def test_render_pr_update_email(app, user_admin):
ref = collections.namedtuple(
'Ref', 'name, type')('fxies123', 'book')
pr = collections.namedtuple('PullRequest',
'pull_request_id, title, description, source_ref_parts, source_ref_name, target_ref_parts, target_ref_name')(
200, 'Example Pull Request', 'Desc of PR', ref, 'bookmark', ref, 'Branch')
source_repo = target_repo = collections.namedtuple(
'Repo', 'type, repo_name')('hg', 'pull_request_1')
commit_changes = AttributeDict({
'added': ['aaaaaaabbbbb', 'cccccccddddddd'],
'removed': ['eeeeeeeeeee'],
})
file_changes = AttributeDict({
'added': ['a/file1.md', 'file2.py'],
'modified': ['b/modified_file.rst'],
'removed': ['.idea'],
})
kwargs = {
'updating_user': User.get_first_super_admin(),
'pull_request': pr,
'pull_request_commits': [],
'pull_request_target_repo': target_repo,
'pull_request_target_repo_url': 'x',
'pull_request_source_repo': source_repo,
'pull_request_source_repo_url': 'x',
'pull_request_url': 'http://localhost/pr1',
'pr_comment_url': 'http://comment-url',
'pr_comment_reply_url': 'http://comment-url#reply',
'ancestor_commit_id': 'f39bd443',
'added_commits': commit_changes.added,
'removed_commits': commit_changes.removed,
'changed_files': (file_changes.added + file_changes.modified + file_changes.removed),
'added_files': file_changes.added,
'modified_files': file_changes.modified,
'removed_files': file_changes.removed,
}
subject, headers, body, body_plaintext = EmailNotificationModel().render_email(
EmailNotificationModel.TYPE_PULL_REQUEST_UPDATE, **kwargs)
# subject
assert subject == '@test_admin (RhodeCode Admin) updated pull request. !200: "Example Pull Request"'
emails: fixed newlines in email templates that can break email sending code.
r1728 @pytest.mark.parametrize('mention', [
True,
False
])
@pytest.mark.parametrize('email_type', [
EmailNotificationModel.TYPE_COMMIT_COMMENT,
EmailNotificationModel.TYPE_PULL_REQUEST_COMMENT
])
home: moved home and repo group views into pyramid....
r1774 def test_render_comment_subject_no_newlines(app, mention, email_type):
dan
emails: updated emails design and data structure they provide....
r4038 ref = collections.namedtuple(
'Ref', 'name, type')('fxies123', 'book')
emails: fixed newlines in email templates that can break email sending code.
r1728
pr = collections.namedtuple('PullRequest',
'pull_request_id, title, description, source_ref_parts, source_ref_name, target_ref_parts, target_ref_name')(
200, 'Example Pull Request', 'Desc of PR', ref, 'bookmark', ref, 'Branch')
dan
emails: updated emails design and data structure they provide....
r4038 source_repo = target_repo = collections.namedtuple(
'Repo', 'type, repo_name')('hg', 'pull_request_1')
emails: fixed newlines in email templates that can break email sending code.
r1728
kwargs = {
dan
emails: updated emails design and data structure they provide....
r4038 'user': User.get_first_super_admin(),
emails: fixed newlines in email templates that can break email sending code.
r1728 'commit': AttributeDict(raw_id='a'*40, message='Commit message'),
'status_change': 'approved',
dan
emails: updated emails design and data structure they provide....
r4038 'commit_target_repo_url': 'http://foo.example.com/#comment1',
emails: fixed newlines in email templates that can break email sending code.
r1728 'repo_name': 'test-repo',
'comment_file': 'test-file.py',
'comment_line': 'n100',
'comment_type': 'note',
dan
emails: added reply link to comment type emails...
r4050 'comment_id': 2048,
emails: fixed newlines in email templates that can break email sending code.
r1728 'commit_comment_url': 'http://comment-url',
dan
emails: added reply link to comment type emails...
r4050 'commit_comment_reply_url': 'http://comment-url/#Reply',
emails: fixed newlines in email templates that can break email sending code.
r1728 'instance_url': 'http://rc-instance',
'comment_body': 'hello world',
'mention': mention,
'pr_comment_url': 'http://comment-url',
dan
emails: added reply link to comment type emails...
r4050 'pr_comment_reply_url': 'http://comment-url/#Reply',
emails: fixed newlines in email templates that can break email sending code.
r1728 'pull_request': pr,
'pull_request_commits': [],
'pull_request_target_repo': target_repo,
'pull_request_target_repo_url': 'x',
'pull_request_source_repo': source_repo,
'pull_request_source_repo_url': 'x',
dan
emails: updated emails design and data structure they provide....
r4038
'pull_request_url': 'http://code.rc.com/_pr/123'
emails: fixed newlines in email templates that can break email sending code.
r1728 }
subject, headers, body, body_plaintext = EmailNotificationModel().render_email(
email_type, **kwargs)
assert '\n' not in subject