def send_invite_email(profile, template_name, extra_context=None, token_generator=default_token_generator): """Generates a one-use invite link and sends to the user.""" c = { 'uidb36': int_to_base36(profile.user.id), 'profile': profile, 'token': token_generator.make_token(profile.user), 'base_url': settings.PORTFOLIYO_BASE_URL, } c.update(extra_context or {}) email.send_templated_multipart(template_name, c, [profile.user.email])
def test_send_templated_multipart(): with mock.patch('portfoliyo.email.render_to_string') as mock_render: mock_render.side_effect = ['first', 'second', 'third\nhere'] email.send_templated_multipart( 'some/template', {'a': 1}, ['*****@*****.**']) mock_render.assert_any_call('some/template.txt', {'a': 1}) mock_render.assert_any_call('some/template.html', {'a': 1}) mock_render.assert_any_call('some/template.subject.txt', {'a': 1}) assert len(mail.outbox) == 1 msg = mail.outbox[0] assert msg.to == ['*****@*****.**'] assert msg.subject == 'third here' assert msg.body == 'first' assert msg.alternatives == [('second', 'text/html')]
def test_send_templated_multipart(): with mock.patch('portfoliyo.email.render_to_string') as mock_render: mock_render.side_effect = ['first', 'second', 'third\nhere'] email.send_templated_multipart('some/template', {'a': 1}, ['*****@*****.**']) mock_render.assert_any_call('some/template.txt', {'a': 1}) mock_render.assert_any_call('some/template.html', {'a': 1}) mock_render.assert_any_call('some/template.subject.txt', {'a': 1}) assert len(mail.outbox) == 1 msg = mail.outbox[0] assert msg.to == ['*****@*****.**'] assert msg.subject == 'third here' assert msg.body == 'first' assert msg.alternatives == [('second', 'text/html')]