def test_subject_can_be_a_promise(self): """Subject can be a promise object (lazy translation)""" builder = EmailBuilder( subject=translation.ugettext_lazy("test subject")) kwargs = builder.get_message_kwargs() assert not isinstance(kwargs['subject'], functional.Promise) assert kwargs['subject'] == "test subject"
def test_send_shortcut(self): EmailBuilder.send(to=['*****@*****.**'], subject="Test subject", body="Test body") assert len(mail.outbox) == 1 assert mail.outbox[0].to == ['*****@*****.**'] assert mail.outbox[0].subject == "Test subject" assert mail.outbox[0].body == "Test body"
def test_default_kwargs(self): """Check default message keyword arguments""" builder = EmailBuilder() kwargs = builder.get_message_kwargs() expected = {'to': None, 'cc': None, 'bcc': None, 'subject': '', 'connection': None, 'from_email': None, 'headers': None, 'attachments': None, 'body': ''} assert kwargs == expected
def test_message_building(self): """ Checks if e-mail class can be customized using mail_class and if it will receive all arguments it should """ class Dummy(object): def __init__(self, **kwargs): self.kwargs = kwargs kwargs = copy.deepcopy(self.default_kwargs) builder = EmailBuilder(mail_class=Dummy, **kwargs) msg = builder.build() assert isinstance(msg, Dummy) assert msg.kwargs == kwargs
def test_default_kwargs(self): """Check default message keyword arguments""" builder = EmailBuilder() kwargs = builder.get_message_kwargs() expected = { 'to': None, 'cc': None, 'bcc': None, 'subject': '', 'connection': None, 'from_email': None, 'headers': None, 'attachments': None, 'body': '' } assert kwargs == expected
def test_invalid_keyword_argument(self): with pytest.raises(TypeError): EmailBuilder(invalid_keyword_argument=1)
def test_get_message_kwargs_method(self): """Checks if all kwargs can be changed using attributes""" kwargs = copy.deepcopy(self.default_kwargs) builder = EmailBuilder(**kwargs) assert builder.get_message_kwargs() == kwargs
def test_subject_can_be_a_promise(self): """Subject can be a promise object (lazy translation)""" builder = EmailBuilder(subject=translation.ugettext_lazy("test subject")) kwargs = builder.get_message_kwargs() assert not isinstance(kwargs['subject'], functional.Promise) assert kwargs['subject'] == "test subject"