Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
188cfd1
transfer README to rst
lal-solute Jun 8, 2023
5b66e56
dependencies: add sphinx
Corvan Jun 9, 2023
6ab32c2
project: uncomment readme
Corvan Jun 9, 2023
aaca8ce
Merge branch 'main' into docs
Corvan Jun 25, 2023
5f08ef5
docs: add skeleton from running sphinx
lal-solute Jun 25, 2023
0f9399d
project: update dependencies
Corvan Jun 25, 2023
a6a44a3
testing/unittest: fix indentation of docstring
Corvan Jun 25, 2023
d62dcf2
README: add first description for testing with unittest
Corvan Jun 25, 2023
6fad7cb
dependencies: update
Corvan Jun 25, 2023
48b64c7
docs: add sphinx doc structure
Corvan Jun 25, 2023
0e7533c
Merge branch 'main' into docs
Corvan Jun 25, 2023
6d34265
Merge remote-tracking branch 'origin/main' into docs
Corvan Jul 1, 2023
a8e94d8
docs: add other *.rst files
Corvan Jul 1, 2023
df077eb
docs: extend about page
Corvan Jul 1, 2023
0a7b387
docs: add installation
Corvan Jul 1, 2023
363c872
docs: update README
Corvan Jul 1, 2023
438b4e1
docs: extend testing
Corvan Jul 2, 2023
9dde145
docs move testing documents in own subfolder and files
Corvan Jul 2, 2023
9ede0e1
doc: fix link
Corvan Jul 2, 2023
34832d4
pytest: add default for mailpit_api fixture
Corvan Jul 8, 2023
bc279a1
Merge branch 'main' into docs
Corvan Jul 8, 2023
0e191ce
docs: add decriptions of pytest fixture mailpit_api
Corvan Jul 8, 2023
0ba5dd7
docs: add more models docstrings
Corvan Jul 8, 2023
3d94bdb
docs: remove assertion helper because the assert can be done in one line
Corvan Jul 8, 2023
44fe56f
docs: update docstrings
Corvan Jul 8, 2023
ef400b1
test_pytest: remove unused import
Corvan Jul 8, 2023
3ca47dc
docs: add example for assertMessageReceived
Corvan Jul 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,6 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.ruff_cache/
.ruff_cache/
/docs/output/
/docs/generated/
46 changes: 40 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ API-client for https://github.com/axllent/mailpit written in Python
-------------------------------------------------------------------

:Authors:
Lars Liedtke <corvan@gmx.de>
Lars Liedtke <lars@familie-liedtke.net>
:Version:
0.10.3

Expand All @@ -18,6 +18,21 @@ We are working with `Odoo <https://github.com/odoo/odoo>`_ and I wanted to test
I remembered `mailhog <https://github.com/mailhog/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``:

.. code-block:: bash

pip install mailpit-api-client

If you want to use the library with ``pytest``:

.. code-block:: bash

pip install mailpit-api-client[pytest]

-----
Usage
-----
Expand Down Expand Up @@ -50,14 +65,33 @@ The model-classes' attributes are named the same as Mailpit's responses, as docu

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

== Testing
-------
Testing
-------

To make testing easier I plan to provide testhelpers like TestCase-classes of ``unittest`` and ``pytest``-fixtures.
To make testing easier there are test-helpers inside the ``mailpit.testing`` package.

=== unittest
tbd
________
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``:

.. code-block:: python

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
______

=== pytest
tbd

.. [1] If you have it running differently, you have to adjust the URL you pass.
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = output

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Empty file added docs/__init__.py
Empty file.
32 changes: 32 additions & 0 deletions docs/about.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
=====
About
=====

:Authors:
Lars Liedtke <lars@familie-liedtke.net>
:Version:
0.10.3

For work, I thought about introducing integration testing.
We are working with `Odoo <https://github.com/odoo/odoo>`_ and I wanted to test if e-mails created by Odoo really were sent.
I remembered `mailhog <https://github.com/mailhog/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.

-------
Mailpit
-------
Mailpit is software written Go, intended to be a testing tool for E-Mail.
It acts as a receiving E-Mail server and offers a Web Frontend as well as an API.
With it you can configure the software you want to test to send its E-Mail Messages to Mailpit and check via the frontend or the API if your software sent mail, correctly sent it, and using the frontend, how mail will be rendered.
If you want to learn more about Mailpit, have a look at its `README <https://github.com/axllent/mailpit#readme>`_ and at its `Wiki <https://github.com/axllent/mailpit/wiki>`_

----------
API-Client
----------
This API-Client uses Mailpit's API in order to provide classes and methods in Python, which are providing access to the API endpoints and the information returned of messages stored in Mailpit.
More information can be found in :doc:`usage`.

Additionally there are ``unittest`` Test-Cases and ``pytest`` Fixtures, which can be used to write (integration-) tests.
These helpers can be used to e.g. trigger sending an E-Mail message in a test and then
to check, if the message has been received by Mailpit. If it has not been received by mailpit your test will fail.
More information can be found in :doc:`testing/testing`.
43 changes: 43 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import sys
import os

sys.path.insert(0, os.path.abspath(".."))

import mailpit

project = "mailpit-api-client"
copyright = "2023, Lars Liedtke"
author = "Lars Liedtke"
release = "0.10.1"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
]

templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
source_path = "mailpit"


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "alabaster"
html_static_path = ["_static"]

intersphinx_mapping = {
"pytest": ("https://docs.pytest.org/en/stable", None),
"python": ("https://docs.python.org/3/", None),
}
17 changes: 17 additions & 0 deletions docs/development.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
===========
Development
===========

--------------------
Install dependencies
--------------------

.. code-block:: python

pip install -e ".[docs,test,pytest,build]"

.. code-block:: bash

make clean
sphinx-apidoc -d 4 -eM -f -o generated ../mailpit
make html
26 changes: 26 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.. mailpit-api-client documentation master file, created by
sphinx-quickstart on Thu Jun 8 19:55:21 2023.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to mailpit-api-client's documentation!
==============================================

.. toctree::
:maxdepth: 4
:caption: Contents:

about
installation
usage
testing/testing
development
generated/modules


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
66 changes: 66 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
============
Installation
============

This documentation assumes you are familiar with `pip <https://pip.pypa.io/en/stable/getting-started/>`_ and how to use it on your operating system.

Additionally consider using virtual environments, be it with `venv <https://docs.python.org/3/library/venv.html>`_, `virtualenvwrapper <https://virtualenvwrapper.readthedocs.io/en/latest/>`_, `pipx <https://pypa.github.io/pipx/>`_, `poetry <https://python-poetry.org>`_ or whatever else you'd like to use.

----
PyPI
----
You can find the Project on `PyPI <https://pypi.org>`_ under `<https://pypi.org/project/mailpit-api-client/>`_

It can simply be installed:

________
unittest
________

If you want to use it with `unittest <https://docs.python.org/3/library/unittest.html>`_
simply type

.. code-block:: bash

pip install maiilpit-api-client

______
pytest
______

If you want to install it with `pytest <https://pytest.org>`_, type

.. code-block:: bash

pip install mailpit-api-client[pytest]

This will have pytest as additional dependency.

------
GitHub
------
You can install it from `GitHub <https://github.com/Corvan/mailpit-api-client.git>`_ directly as well

________
unittest
________
.. code-block:: bash

pip install https://github.com/Corvan/mailpit-api-client.git

______
pytest
______
.. code-block:: bash

pip install https://github.com/Corvan/mailpit-api-client.git[pytest]

______________________
Cloning git repository
______________________

Or if you want to clone the repository

.. code-block:: bash

git clone https://github.com/Corvan/mailpit-api-client.git
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
43 changes: 43 additions & 0 deletions docs/testing/pytest.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
======
pytest
======
In order to provide some convenience a :py:func:`pytest.fixtures <pytest.fixture>` has
been created.

-------------------
Mailpit-API fixture
-------------------
:py:func:`~mailpit.testing.pytest.mailpit_api` is a :py:mod:`pytest` :py:func:`fixture <pytest.fixture>`, that sets up an API connection and returns it as :py:class:`~mailpit.client.api.API` object.

The fixture has got a scope of ``session`` and it will call :py:meth:`API.delete_messages() <mailpit.client.api.API.delete_messages>` with an empty list to delete all messages, when it goes out of scope.

As with other pytest plugins you have to enable this library in your ``conftest.py``:

.. code-block:: python

pytest_plugins = ["mailpit.testing.pytest"]


Now it is possible to use the fixture:

.. code-block:: python

def test_example(mailpit_api):
mailpit_api.get_messages([])


The fixture has got a default of ``http://localhost:8025``.
In order to pass the api url to this fixture, you have to parametrize your test function with the ``indirect`` parameter set to ``True``.

.. code-block:: python

import pytest

api_url = "localhost:8025"

@pytest.mark.parametrize("mailpit_api", [api_url], indirect=True)
def test_example(mailpit_api):
mailpit_api.get_messages([])



11 changes: 11 additions & 0 deletions docs/testing/testing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
=======
Testing
=======
To make testing easier there are test-helpers inside the :py:mod:`mailpit.testing` package.

.. toctree::
:maxdepth: 2
:caption: Contents:

unittest
pytest
Loading