From 86c98cc426119603cf5162b7224525203e11334b Mon Sep 17 00:00:00 2001 From: Marie PUPO JEAMMET Date: Fri, 6 Jun 2025 18:06:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB(dimail)=20mod?= =?UTF-8?q?ify=20makefile=20to=20setup=20dimail=20container=20upon=20runni?= =?UTF-8?q?ng=20demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Setup dimail container upon running demo so that it's always in sync. --- Makefile | 7 +- docs/interoperability/dimail.md | 5 +- env.d/development/common.dist | 3 + .../tests/commands/test_dimail_setup_db.py | 69 +++---------------- 4 files changed, 18 insertions(+), 66 deletions(-) diff --git a/Makefile b/Makefile index ba1c0cd..16f6435 100644 --- a/Makefile +++ b/Makefile @@ -132,6 +132,7 @@ stop: ## stop the development server using Docker demo: ## flush db then create a demo for load testing purpose @$(MAKE) resetdb @$(MANAGE) create_demo + @$(MAKE) dimail-setup-db .PHONY: demo @@ -293,12 +294,8 @@ i18n-generate-and-upload: \ # -- INTEROPERABILTY # -- Dimail configuration - -dimail-recreate-container: - @$(COMPOSE) up --force-recreate -d dimail -.PHONY: dimail-recreate-container - dimail-setup-db: + @$(COMPOSE) up --force-recreate -d dimail @echo "$(BOLD)Populating database of local dimail API container$(RESET)" @$(MANAGE) setup_dimail_db --populate-from-people .PHONY: dimail-setup-db diff --git a/docs/interoperability/dimail.md b/docs/interoperability/dimail.md index 8f2e2e6..e7bf94f 100644 --- a/docs/interoperability/dimail.md +++ b/docs/interoperability/dimail.md @@ -13,8 +13,7 @@ To ease local development, dimail provides a container that we embark in our doc Bootstraping with command `make bootstrap` creates a container and initializes its database. Additional commands : -- Reset the database by recreating the container with `dimail-recreate-container`. -- Populate the database with all the content of your People database with `dimail-setup-db` +- Reset and populate the database with all the content of your People database with `dimail-setup-db` ## Architecture @@ -47,5 +46,5 @@ People users can have 3 levels of permissions on a domain: Mailboxes can be created by a domain owners or administrators in People's domain tab. On enabled domains, mailboxes are created at the same time on dimail (and a confirmation email is sent to the secondary email). -On pending/failed domains, mailboxes are only created locally with "pending" status and are sent to dimail upon domain's activation. +On pending/failed domains, mailboxes are only created locally with "pending" status and are sent to dimail upon domain's (re)activation. On disabled domains, mailboxes creation is not allowed. diff --git a/env.d/development/common.dist b/env.d/development/common.dist index 8e9ff71..dbaeb91 100644 --- a/env.d/development/common.dist +++ b/env.d/development/common.dist @@ -65,3 +65,6 @@ IH5em4M/pHIcsqCi1qggBMbdvzHBUtC3R4sK0CpEFHlN+Y59aGazidcN2FPupNJv MbyqKyC6DAzv4jEEhHaN7oY= -----END PRIVATE KEY----- " + +# INTEROP +MAIL_PROVISIONING_API_CREDENTIALS="bGFfcmVnaWU6cGFzc3dvcmQ=" # Dev and test key for dimail interop diff --git a/src/backend/mailbox_manager/tests/commands/test_dimail_setup_db.py b/src/backend/mailbox_manager/tests/commands/test_dimail_setup_db.py index adf32db..7ed82e4 100644 --- a/src/backend/mailbox_manager/tests/commands/test_dimail_setup_db.py +++ b/src/backend/mailbox_manager/tests/commands/test_dimail_setup_db.py @@ -6,8 +6,6 @@ from django.core.management import call_command import pytest import responses -from core import factories - from mailbox_manager import factories as mailbox_factories from mailbox_manager.management.commands.setup_dimail_db import DIMAIL_URL, admin @@ -22,23 +20,12 @@ def test_commands_setup_dimail_db(settings): """The create_demo management command should create objects as expected.""" settings.DEBUG = True # required to run the command - john_doe = factories.UserFactory( - name="John Doe", email="people@people.world", sub="sub.john.doe" - ) - # mock dimail API - responses.add(responses.POST, f"{DIMAIL_URL}/users/", status=201) - responses.add(responses.POST, f"{DIMAIL_URL}/domains/", status=201) - responses.add(responses.POST, f"{DIMAIL_URL}/allows/", status=201) - responses.add( - responses.GET, + responses.post(f"{DIMAIL_URL}/users/", status=201) + responses.post(f"{DIMAIL_URL}/domains/", status=201) + responses.get( f"{DIMAIL_URL}/users/", json=[ - { - "is_admin": False, - "name": john_doe.sub, - "perms": [], - }, { "is_admin": True, "name": "admin", @@ -59,7 +46,7 @@ def test_commands_setup_dimail_db(settings): call_command("setup_dimail_db") # check dimail API received the expected requests - assert len(responses.calls) == 5 + assert len(responses.calls) == 2 assert responses.calls[0].request.url == f"{DIMAIL_URL}/users/" assert ( responses.calls[0].request.body @@ -72,25 +59,6 @@ def test_commands_setup_dimail_db(settings): b'"perms": ["new_domain", "create_users", "manage_users"]}' ) - assert responses.calls[2].request.url == f"{DIMAIL_URL}/domains/" - assert responses.calls[2].request.body == ( - b'{"name": "test.domain.com", "context_name": "test.domain.com", ' - b'"features": ["webmail", "mailbox", "alias"], ' - b'"delivery": "virtual"}' - ) - - assert responses.calls[3].request.url == f"{DIMAIL_URL}/users/" - assert ( - responses.calls[3].request.body - == b'{"name": "sub.john.doe", "password": "no", "is_admin": false, "perms": []}' - ) - - assert responses.calls[4].request.url == f"{DIMAIL_URL}/allows/" - assert ( - responses.calls[4].request.body - == b'{"user": "sub.john.doe", "domain": "test.domain.com"}' - ) - # reset the responses counter responses.calls.reset() # pylint: disable=no-member @@ -102,29 +70,14 @@ def test_commands_setup_dimail_db(settings): call_command("setup_dimail_db", "--populate-from-people") # check dimail API received the expected requests - assert ( - len(responses.calls) == 5 + 3 + 3 - ) # calls for some.domain.com and test.domain.com + assert len(responses.calls) == 3 # calls for some.domain.com and test.domain.com dimail_calls = [] - for call in responses.calls[5:]: + for call in responses.calls[3:]: dimail_calls.append((call.request.url, call.request.body)) - assert ( - f"{DIMAIL_URL}/domains/", - ( - b'{"name": "some.domain.com", "context_name": "some.domain.com", ' - b'"features": ["webmail", "mailbox", "alias"], ' - b'"delivery": "virtual"}' - ), - ) in dimail_calls - - assert ( - f"{DIMAIL_URL}/users/", - (b'{"name": "sub.toto.123", "password": "no", "is_admin": false, "perms": []}'), - ) in dimail_calls - - assert ( - f"{DIMAIL_URL}/allows/", - b'{"user": "sub.toto.123", "domain": "some.domain.com"}', - ) in dimail_calls + assert responses.calls[2].request.body == ( + b'{"name": "some.domain.com", "context_name": "some.domain.com", ' + b'"features": ["webmail", "mailbox", "alias"], ' + b'"delivery": "virtual"}' + )