Skip to main content

A Mailpit API Client

Project description

API-client for https://github.com/axllent/mailpit written in Python

Authors:

Lars Liedtke <lars@familie-liedtke.net>

Version:

0.11.0

Motivation

For work, I thought about introducing integration testing. We are working with Odoo and I wanted to test if e-mails created by Odoo really were sent. I remembered mailhog, which I discovered to be abandoned. Searching for an alternative, I found Mailpit - for which I decided to write an API-client in my free time.

Install

If you want to use the library with unittest:

pip install mailpit-api-client

If you want to use the library with pytest:

pip install mailpit-api-client[pytest]

Usage

this library - as is Mailpit - is mostly meant for testing. Giving the url of Mailpit to a tool to send e-mail messages to and then use this client to check on the API if the mail was sent.

Client

The client itself consists of the class API in mailpit/client/api.py, that offers methods, which query the API-Endpoints and are named respectively. To use this class, simply try something like this. You have to have Mailpit running on localhost for this [1] .

import mailpit.client.api
api = mailpit.client.api.API("localhost:8025")
messages = api.get_messages()

Additionally, there are some model-classes that wrap the API’s responses. For example with

messages = api.get_messages()

messages will be an instance of mailpit.client.models.Messages , which you can find in link:mailpit/client/models/messages.py[mailpit/client/models.py]. + The model-classes’ attributes are named the same as Mailpit’s responses, as documented in the API’s README.md, but as is convention in Python in Snakecase.

For examples have a look at the link:tests[tests]

Testing

To make testing easier there are test-helpers inside the mailpit.testing package.

unittest

In order to provide some convenience a test-case class has been created with the name EMailTestCase deriving from unittest.TestCase, which is meant to be inherited from, as you would do from TestCase:

from mailpit.testing.unittest import EMailTestCase

class MyTest(EMailTestCase):

     def test_sending_email():
        ...

The class adds a few methods and attributes, so that you are able to assert, if your message has been sent, or if two messages are equal.

pytest

tbd

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mailpit-api-client-0.11.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

mailpit_api_client-0.11.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file mailpit-api-client-0.11.0.tar.gz.

File metadata

  • Download URL: mailpit-api-client-0.11.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for mailpit-api-client-0.11.0.tar.gz
Algorithm Hash digest
SHA256 7721d78f7fca001bd53bd35866108290da00a8b8788163770f9cb17a24bf0ce0
MD5 e7cb9d8901c22c69e96f809e5df8d38d
BLAKE2b-256 9f33af8a4f4d6dd9c88fefa7314245c5cbe0483608674b1f3644ddd2eb6cd35c

See more details on using hashes here.

File details

Details for the file mailpit_api_client-0.11.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mailpit_api_client-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7d278adff8394461f44336a24a00d1957d76882fdc689cea496489781b8450a8
MD5 600dce5a7cb951c71c424427cb13a96f
BLAKE2b-256 08e8ef9cea2588f6c76dc876d71bf5022f7c5465809aa22cdced826336789512

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page