Skip to content

Commit d6f50f6

Browse files
authored
Merge pull request #27 from Corvan/docs
Add developer documentation
2 parents 8ebfd5d + d4b1922 commit d6f50f6

File tree

4 files changed

+150
-14
lines changed

4 files changed

+150
-14
lines changed

.github/workflows/github_pages_static.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Deploy static content to Pages
33

44
on:
55
release:
6-
types: [published]
6+
types: [released]
77

88
# Allows you to run this workflow manually from the Actions tab
99
workflow_dispatch:

docs/development.rst

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,148 @@
11
===========
22
Development
33
===========
4+
If you want to hack on this little library clone it via git
5+
6+
.. code-block:: bash
7+
8+
git clone https://github.com/Corvan/mailpit-api-client.git
9+
10+
or
11+
12+
.. code-block:: bash
13+
14+
git clone git@github.com:Corvan/mailpit-api-client.git
15+
16+
Of course you can fork it first on GitHub.
17+
Then you are easily able to open PRs, which is the preferred way of contributing code.
418

519
--------------------
620
Install dependencies
721
--------------------
22+
It is recommended to use a virtual environment, in order to separate the dependencies
23+
for this project from dependencies of other projects.
24+
There are several tools out there to manage virtual environments, so please consult the
25+
respective documentantion if you're not using ``venv`` or ``poetry``
26+
27+
If you want to run the tests :ref:`for all possible versions of Python <invoke-tasks>`
28+
you have to install `Docker Engine <https://docs.docker.com/engine/install/>`_, and the
29+
`Docker Compose plugin <https://docs.docker.com/compose/install/linux/>`_ on Linux.
30+
Or you install `Docker Desktop <https://docs.docker.com/get-docker/>`_ on other
31+
operating system and on Linux.
32+
33+
___
34+
pip
35+
___
36+
37+
in order to install the Python dependencies enter the directory of your just cloned
38+
git repository, activate your virtual environment and type:
839

940
.. code-block:: python
1041
1142
pip install -e ".[docs,test,pytest,build]"
1243
44+
45+
Now you can start hacking.
46+
47+
______
48+
poetry
49+
______
50+
If you want to use poetry as the manager for your virtual environment, install it if
51+
necessary and run
52+
53+
.. code-block:: bash
54+
55+
poetry update
56+
57+
inside the project's directory.
58+
59+
In order to run the :ref:`invoke-tasks` you have to prefix all commands given there with
60+
61+
.. code-block:: bash
62+
63+
poetry run
64+
65+
so running the Invoke task of unittests you have to type
66+
67+
.. code-block:: bash
68+
69+
poetry run invoke tests.unit
70+
71+
-----------------
72+
Running the tests
73+
-----------------
74+
This project uses `pytest <https://pytest.org>`_ as testing framework.
75+
Even the `unittest <https://docs.python.org/3/library/unittest.html>`_ parts are tested
76+
themselves with ``pytest``.
77+
78+
There are two kinds of tests in this project:
79+
80+
================== =================================================================================================
81+
test type description
82+
================== =================================================================================================
83+
unit tests unit tests are tests that check if a functionality works isolated from everything else
84+
integration tests integration tests are tests that include dependencies, and check if functionalities work together
85+
================== =================================================================================================
86+
87+
You can run the tests locally, but then you have to provide a `running Mailpit by
88+
yourself <https://github.com/axllent/mailpit/blob/develop/README.md>`_ for running the
89+
integration tests.
90+
91+
.. _invoke-tasks:
92+
93+
____________
94+
Invoke tasks
95+
____________
96+
97+
In order to run the tests inside Docker containers, there are
98+
`Invoke <https://www.pyinvoke.org>`_ tasks that use Docker Compose to set-up all the
99+
necessary containers and run the checks and tests in them afterwards.
100+
At the end things are cleaned up again.
101+
102+
.. code-block:: bash
103+
104+
$ invoke -l
105+
106+
Available tasks:
107+
108+
tests.checks
109+
tests.integration
110+
tests.unit
111+
112+
There are some more tasks, but you can concentrate on those three.
113+
114+
================= ===============================================================================================
115+
task description
116+
================= ===============================================================================================
117+
tests.checks runs code checks, like black (code formatting), ruff (linting), and mypy (static code analysis)
118+
tests.integration runs the integration tests
119+
tests.unit runs the unit tests
120+
================= ===============================================================================================
121+
122+
To run a task, simply type
123+
124+
.. code-block:: bash
125+
126+
invoke <task>
127+
128+
It is also possible to run multiple tasks at once
129+
130+
.. code-block:: bash
131+
132+
invoke tests.checks tests.unit tests.integration
133+
134+
For running the tests all the logging outputs are set to debug.
135+
So running them will produce *a lot* of output, but you will want to know why things
136+
go wrong.
137+
If you want to reduce the amount, have a look at :file:`pyproject.toml`
138+
139+
-----------------------
140+
Build the documentation
141+
-----------------------
142+
13143
.. code-block:: bash
14144
145+
cd docs
15146
make clean
16147
sphinx-apidoc -d 4 -eM -f -o generated ../mailpit
17148
make html

mailpit/client/api.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class API:
1313
"""
14-
class representing the message-endpoint of the API
14+
class representing the different endpoints of the API
1515
"""
1616

1717
# pylint: disable=too-few-public-methods
@@ -80,9 +80,9 @@ def put_messages(self, ids: List[str], key: str, value: Any):
8080

8181
def get_message(self, message_id: str) -> _models.Message:
8282
"""
83+
Send a GET request to get a certain Message by its Message-ID
8384
84-
85-
:param message_id:
85+
:param message_id: The Message-ID to get the message by
8686
"""
8787

8888
# pylint: disable = no-member
@@ -97,12 +97,14 @@ def get_message(self, message_id: str) -> _models.Message:
9797
message = _models.Message.from_json(response.text)
9898
return message
9999

100-
def get_message_attachment(self, message_id: str, part_id: str):
100+
def get_message_attachment(self, message_id: str, part_id: str) -> str:
101101
"""
102+
Send a GET request to the message endpoint with querying for the part_id
103+
of an attachment
102104
103-
104-
:param message_id:
105-
:param part_id:
105+
:param message_id: the Message-ID the attachment belongs to
106+
:param part_id: the Part-ID of the attachment to receive
107+
:return the attachment's data
106108
"""
107109
response = _httpx.get(
108110
f"{self.mailpit_url}/{API.MESSAGE_ENDPOINT}/{message_id}/part/{part_id}",
@@ -112,11 +114,11 @@ def get_message_attachment(self, message_id: str, part_id: str):
112114
response.raise_for_status()
113115
return response.text
114116

115-
def get_message_headers(self, message_id: str):
117+
def get_message_headers(self, message_id: str) -> _models.Headers:
116118
"""
119+
Send a GET request to get a message's Headers
117120
118-
119-
:param message_id:
121+
:param message_id: The Message-ID to get the headers for
120122
"""
121123
response = _httpx.get(
122124
f"{self.mailpit_url}/{API.MESSAGE_ENDPOINT}/{message_id}/headers",

pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ test = [
3939
"mypy>=1.1.1",
4040
"pylint",
4141
"respx",
42-
"pytest>=7",
4342
]
4443
pytest = [
44+
"mailpit-api-client[test]",
4545
"pytest>=7",
4646
]
4747
build = [
@@ -50,7 +50,7 @@ build = [
5050
]
5151

5252
[project.urls]
53-
repository = "https://github.com/Corvan/mailpit-api-client"
53+
Repository = "https://github.com/Corvan/mailpit-api-client"
5454
Documentation = "https://corvan.github.io/mailpit-api-client/"
5555

5656
[tool.poetry]
@@ -77,9 +77,12 @@ black = "*"
7777
mypy = "^1.4.1"
7878
pylint = "*"
7979
respx = "*"
80-
pytest = "^7"
8180

8281
[tool.poetry.group.pytest.dependencies]
82+
black = "*"
83+
mypy = "^1.4.1"
84+
pylint = "*"
85+
respx = "*"
8386
pytest = "^7"
8487

8588
[tool.poetry.group.build.dependencies]

0 commit comments

Comments
 (0)