Exemplo n.º 1
0
    def test_send_failure(self):
        """
            Test sending an email to a recipient given in a wrong type.

            Expected result: The email is not sent.
        """

        subject = 'Test Subject'
        body_path = 'email/test'
        sender = '*****@*****.**'
        recipients = None
        body_plain = 'Plain Body'
        body_html = 'HTML Body'

        email = Email(subject, body_path, sender)
        email._body_plain = body_plain
        email._body_html = body_html

        with self.assertRaises(TypeError) as message:
            with mail.record_messages() as outgoing:
                # noinspection PyTypeChecker
                email.send(recipients)

                self.assertEqual(0, len(outgoing))
                self.assertEqual(
                    'Argument "recipients" must be a string or a list of strings.',
                    message)
Exemplo n.º 2
0
    def test_send_failure(self):
        """
            Test sending an email to a recipient given in a wrong type.

            Expected result: The email is not sent.
        """

        subject = 'Test Subject'
        body_path = 'email/test'
        sender = '*****@*****.**'
        recipients = None
        body_plain = 'Plain Body'
        body_html = 'HTML Body'

        email = Email(subject, body_path, sender)
        email._body_plain = body_plain
        email._body_html = body_html

        with self.assertRaises(TypeError) as message:
            with mail.record_messages() as outgoing:
                # noinspection PyTypeChecker
                email.send(recipients)

                self.assertEqual(0, len(outgoing))
                self.assertEqual('Argument "recipients" must be a string or a list of strings.', message)
Exemplo n.º 3
0
    def test_send_success_multiple_recipients(self):
        """
            Test sending an email to multiple recipients.

            Expected result: The email is sent successfully.
        """

        subject = 'Test Subject'
        body_path = 'email/test'
        sender = '*****@*****.**'
        recipients = ['*****@*****.**', '*****@*****.**']
        body_plain = 'Plain Body'
        body_html = 'HTML Body'

        email = Email(subject, body_path, sender)
        email._body_plain = body_plain
        email._body_html = body_html

        with mail.record_messages() as outgoing:
            email.send(recipients)

            self.assertEqual(1, len(outgoing))
            self.assertIn(subject, outgoing[0].subject)
            self.assertEqual(sender, outgoing[0].sender)
            self.assertListEqual(recipients, outgoing[0].recipients)
            self.assertEqual(body_plain, outgoing[0].body)
            self.assertEqual(body_html, outgoing[0].html)
Exemplo n.º 4
0
    def test_send_success_multiple_recipients(self):
        """
            Test sending an email to multiple recipients.

            Expected result: The email is sent successfully.
        """

        subject = 'Test Subject'
        body_path = 'email/test'
        sender = '*****@*****.**'
        recipients = ['*****@*****.**', '*****@*****.**']
        body_plain = 'Plain Body'
        body_html = 'HTML Body'

        email = Email(subject, body_path, sender)
        email._body_plain = body_plain
        email._body_html = body_html

        with mail.record_messages() as outgoing:
            email.send(recipients)

            self.assertEqual(1, len(outgoing))
            self.assertIn(subject, outgoing[0].subject)
            self.assertEqual(sender, outgoing[0].sender)
            self.assertListEqual(recipients, outgoing[0].recipients)
            self.assertEqual(body_plain, outgoing[0].body)
            self.assertEqual(body_html, outgoing[0].html)