def test_send_invite_email_with_group(self): user = factories.User() user_obj = model.User.by_name(user['name']) group = factories.Group() role = 'member' # send email mailer.send_invite(user_obj, group_dict=group, role=role) # check it went to the mock smtp server msgs = self.get_smtp_messages() msg = msgs[0] body = self.get_email_body(msg[3]) assert_in(group['title'], body) assert_in(h.roles_translated()[role], body)
def test_send_invite_email_with_org(self): user = factories.User() user_obj = model.User.by_name(user['name']) org = factories.Organization() role = 'admin' # send email mailer.send_invite(user_obj, group_dict=org, role=role) # check it went to the mock smtp server msgs = self.get_smtp_messages() msg = msgs[0] body = self.get_email_body(msg[3]) assert_in(org['title'], body) assert_in(h.roles_translated()[role], body)
def test_send_invite_email_with_org(self, mail_server): user = factories.User() user_obj = model.User.by_name(user["name"]) org = factories.Organization() role = "admin" # send email mailer.send_invite(user_obj, group_dict=org, role=role) # check it went to the mock smtp server msgs = mail_server.get_smtp_messages() msg = msgs[0] body = self.get_email_body(msg[3]) assert org["title"] in six.ensure_text(body) assert h.roles_translated()[role] in six.ensure_text(body)
def test_send_invite_email_with_group(self, mail_server): user = factories.User() user_obj = model.User.by_name(user["name"]) group = factories.Group() role = "member" # send email mailer.send_invite(user_obj, group_dict=group, role=role) # check it went to the mock smtp server msgs = mail_server.get_smtp_messages() msg = msgs[0] body = self.get_email_body(msg[3]) assert group["title"] in six.ensure_text(body) assert h.roles_translated()[role] in six.ensure_text(body)
def test_send_invite_email_with_org(self): user = factories.User() user_obj = model.User.by_name(user['name']) org = factories.Organization() role = 'admin' # We need to provide a context as url_for is used internally with self.app.flask_app.test_request_context(): # send email mailer.send_invite(user_obj, group_dict=org, role=role) # check it went to the mock smtp server msgs = self.get_smtp_messages() msg = msgs[0] body = self.get_email_body(msg[3]) assert_in(org['title'], body) assert_in(h.roles_translated()[role], body)
def get_invite_body(user, group_dict=None, role=None): if group_dict: group_type = (_('organization') if group_dict['is_organization'] else _('group')) extra_vars = { 'reset_link': get_reset_link(user), 'site_title': config.get('ckan.site_title'), 'site_url': config.get('ckan.site_url'), 'user_name': user.name, } if role: extra_vars['role_name'] = h.roles_translated().get(role, _(role)) if group_dict: extra_vars['group_type'] = group_type extra_vars['group_title'] = group_dict.get('title') # NOTE: This template is translated return render_jinja2('emails/invite_user.txt', extra_vars)