From 57fd15100ef04c991919599d9c5d9ad9a822e7eb Mon Sep 17 00:00:00 2001 From: Laurent Bossavit Date: Tue, 21 Jan 2025 15:45:21 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(plugin)=20add=20CommuneCreation=20plu?= =?UTF-8?q?gin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add test for domain spec from Dimail --- src/backend/plugins/organizations.py | 11 +++++++++-- .../organizations/test_commune_creation.py | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/backend/plugins/organizations.py b/src/backend/plugins/organizations.py index 634b5b5..c8ca8a2 100644 --- a/src/backend/plugins/organizations.py +++ b/src/backend/plugins/organizations.py @@ -139,14 +139,21 @@ class CommuneCreation(BaseOrganizationPlugin): create_domain.params = { "name": inputs["name"], "delivery": "virtual", - "features": ["webmail"], + "features": ["webmail","mailbox"], "context_name": inputs["name"], } create_domain.headers = { "Authorization": f"Basic: {settings.MAIL_PROVISIONING_API_CREDENTIALS}" } - return [create_zone, create_domain] + spec_domain = ApiCall() + spec_domain.base = settings.MAIL_PROVISIONING_API_URL + spec_domain.url = f"/domains/{inputs["name"]}.collectivite.fr/spec" + spec_domain.headers = { + "Authorization": f"Basic: {settings.MAIL_PROVISIONING_API_CREDENTIALS}" + } + + return [create_zone, create_domain, spec_domain] def run_after_create(self, organization): """After creating an organization, update the organization name.""" diff --git a/src/backend/plugins/tests/organizations/test_commune_creation.py b/src/backend/plugins/tests/organizations/test_commune_creation.py index e0fd65f..8662043 100644 --- a/src/backend/plugins/tests/organizations/test_commune_creation.py +++ b/src/backend/plugins/tests/organizations/test_commune_creation.py @@ -90,10 +90,25 @@ def test_tasks_on_commune_creation_include_dimail_domain_creation(): assert tasks[1].params == { "name": "merlaut", "delivery": "virtual", - "features": ["webmail"], + "features": ["webmail", "mailbox"], "context_name": "merlaut", } assert ( tasks[1].headers["Authorization"] == f"Basic: {settings.MAIL_PROVISIONING_API_CREDENTIALS}" ) + +def test_tasks_on_commune_creation_include_fetching_spec(): + """Test the third task in commune creation: asking Dimail for the spec""" + plugin = CommuneCreation() + name = "Loc-Eguiner" + + tasks = plugin.complete_commune_creation(name) + + assert tasks[2].base == settings.MAIL_PROVISIONING_API_URL + assert tasks[2].url == "/domains/loc-eguiner.collectivite.fr/spec" + assert tasks[2].method == "GET" + assert ( + tasks[2].headers["Authorization"] + == f"Basic: {settings.MAIL_PROVISIONING_API_CREDENTIALS}" + )