def test_send_mail_sets_request_on_instance(self, get_message_dict, *mocks): mock_request = test.RequestFactory().get('/') get_message_dict.return_value = {"to": ["*****@*****.**"]} form = forms.BaseEmailFormMixin() form.send_email(mock_request) self.assertEqual(mock_request, form.request)
def test_sends_mail_with_message_dict(self, get_message_dict, email_class): mock_request = test.RequestFactory().get('/') get_message_dict.return_value = {"to": ["*****@*****.**"]} form = forms.BaseEmailFormMixin() result = form.send_email(mock_request) email_class.assert_called_once_with(**get_message_dict.return_value) email_class.return_value.send.assert_called_once_with( fail_silently=False) self.assertEqual(email_class.return_value.send.return_value, result)
def test_gets_message_dict(self, get_message, get_subject): form = forms.BaseEmailFormMixin() message_dict = form.get_message_dict() self.assertEqual( { "from_email": form.from_email, "to": form.recipient_list, "body": get_message.return_value, "subject": get_subject.return_value, }, message_dict)
def test_send_mail_sets_request_on_instance(self, get_message_dict, *mocks): mock_request = test.RequestFactory().get('/') get_message_dict.return_value = { "recipient_list": ["*****@*****.**"], "from_email": '*****@*****.**', "context": {} } form = forms.BaseEmailFormMixin() form.send_email(mock_request) self.assertEqual(mock_request, form.request)
def test_get_message_dict(self): form = forms.BaseEmailFormMixin() form.is_valid = lambda: True form.cleaned_data = {'a': 'b'} form.request = mock.Mock(name='request') message_dict = form.get_message_dict() self.assertEqual( { "from_email": form.from_email, "recipient_list": form.recipient_list, "context": { 'a': 'b', 'request': form.request }, "headers": None }, message_dict)
def test_sends_mail_with_message_dict(self, get_message_dict, send_mock): mock_request = test.RequestFactory().get('/') get_message_dict.return_value = { "recipient_list": ["*****@*****.**"], "from_email": '*****@*****.**', "context": {} } form = forms.BaseEmailFormMixin() result = form.send_email(mock_request) send_mock.assert_called_once_with(fail_silently=False, template_suffix=mock.ANY, template_name=mock.ANY, template_prefix=mock.ANY, **get_message_dict.return_value) self.assertEqual(send_mock.return_value, result)