5 This is a short guide to help you get started with Postorius development.
11 The source code is hosted on GitLab_, which means that we are using
12 Git for version control.
14 .. _GitLab: https://gitlab.com/mailman/postorius
16 Changes are not made directly in the project's master branch, but in
17 feature-related personal branches, which get reviewed and then merged into
18 the master branch. There is a contribution guide here_, that mentions the basics
19 about contributing to any mailman project.
21 .. _here: http://wiki.list.org/DEV/HowToContributeGit
23 An ideal workflow would be like this:
25 1. File a bug to suggest a new feature or report a bug (or just pick one of
27 2. Create a new branch with your code changes.
28 3. Make a "merge request" to get your code reviewed and merged.
31 First Contributions / Coverage Reports
32 ======================================
34 If you don't know how you can contribute,
35 writing tests is a good way to get you started.
37 You can start by exploring the existing `test coverage`_
38 and finding code that's not covered ie. not tested.
40 .. _`test coverage`: https://mailman.gitlab.io/postorius/index.html
43 Installing and running the tests
44 ================================
46 After checkout you can run the tests using ``tox``:
52 By default this will test against a couple of different environments.
53 If you want to only run the tests in a specific environment or a single
54 module, you can specify this using the ``-e`` option and/or a double
59 # List all currently configured envs:
72 # Test Django 2.1 on Python3.7 only:
73 $ tox -e py37-django21
75 # Run only tests in ``test_address_activation``:
76 $ tox -- postorius.tests.test_address_activation
79 $ tox -e py37-django21 -- postorius.tests.test_address_activation
82 All test modules reside in the ``postorius/src/postorius/tests``
83 directory. Please have a look at the existing examples.
86 Calling Mailman's REST API
87 ==========================
89 A lot of Postorius' code involves calls to Mailman's REST API (through the
90 ``mailmanclient`` library). Postorius' test uses `pytest`_ along with
91 `pytest-django`_ to run tests.
93 Postorius uses `pytest fixtures`_ to setup Mailman Core's REST API and is
94 defined at ``postorius.tests.mailman_api_tests.conftest.mailman_rest_layer``. It
95 is set to ``autouse=True`` so, all the tests inside the module
96 ``mailman_api_tests`` automatically use it.
98 ``mailman_rest_layer`` starts up ``incoming`` runner and ``rest`` runner using
99 ``mailman.testing.helpersTestableMaster``. It also removes all the data after
100 every ``TestCase`` class.
103 .. _pytest fixtures: https://docs.pytest.org/en/latest/fixture.html
104 .. _pytest: https://docs.pytest.org/en/latest/contents.html
105 .. _pytest-django: https://pytest-django.readthedocs.io/en/latest/
111 Three of Django's default User roles are relevant for Postorius:
113 - Superuser: Can do everything.
114 - AnonymousUser: Can view list index and info pages.
115 - Authenticated users: Can view list index and info pages. Can (un)subscribe
118 Apart from these default roles, there are two others relevant in Postorius:
120 - List owners: Can change list settings, moderate messages and delete their
122 - List moderators: Can moderate messages.
124 There are a number of decorators to protect views from unauthorized users.
126 - ``@user_passes_test(lambda u: u.is_superuser)`` (redirects to login form)
127 - ``@login_required`` (redirects to login form)
128 - ``@list_owner_required`` (returns 403 if logged-in user isn't the
130 - ``@list_moderator_required`` (returns 403 if logged-in user isn't the
134 Accessing the Mailman API
135 =========================
137 Postorius uses mailmanclient to connect to Mailman's REST API. In order to
138 directly use the client, ``cd`` to the ``example_project`` folder and execute
139 ``python manage.py mmclient``. This will open a python shell (IPython, if
140 that's available) and provide you with a client object connected to your
141 local Mailman API server (it uses the credentials from your settings.py).
147 $ python manage.py mmclient
150 <Client (user:pwd) http://localhost:8001/3.1/>
152 >>> print(client.system['mailman_version'])
153 GNU Mailman 3.0.0b2+ (Here Again)
155 >>> mailman_dev = client.get_list('mailman-developers@python.org')
156 >>> print(mailman_dev.settings)
157 {u'description': u'Mailman development',
158 u'default_nonmember_action': u'hold', ...}
160 For detailed information how to use mailmanclient, check out its documentation_.
162 .. _documentation: http://docs.mailman3.org/projects/mailmanclient/en/latest/using.html