mailpit.testing.unittest module¶
Provides helpers for unittest
kind of testing against the
Mailpit-API
- class mailpit.testing.unittest.EMailTestCase(*args, **kwargs)¶
Bases:
TestCase
unittest.TestCase
-derived class with added test-helper methods and attributes, in order to test against the Mailpit-API. Simply derive from this class, as you would fromunittest.TestCase
and write your tests as you are used to.e.g.:
class ExampleTestCase(EMailTestCase): def testapi_object(self): messages: mailpit.client.models.Messages = self.api.get_messages() self.assertEqual(0, len(messages.messages))
- api_url: str = 'http://localhost:8025'¶
URL pointing to the Mailpit-API to test, if you need to use another url, override this attribute in your derived class
- assertMessageEqual(first: Message, second: Message, msg: str | None = None)¶
Fail if two instances of
Message
are not equal as determined by the ‘==’ operatore.g.:
import mailpit.client.models class ExampleTestCase(EMailTestCase): def test_example(self): message1 = mailpit.client.models.Message(...) message2 = mailpit.client.models.Message(...) self.assertMessageEqual(message1, message2)
- assertMessageReceived(message_id: str, msg: str | None = None)¶
Fail if the passed message has not been sent to Mailpit