♻️(tests) refacto dimail tests with fixtures

test_api_mailboxes_create exceeded 1000 lines. By using fixtures, we can
at least factorize dimail response when token is ok or mailbox_data sent
to our API when creating a mailbox.
This commit is contained in:
Marie PUPO JEAMMET
2025-09-12 12:09:23 +02:00
committed by Marie
parent b24cb23a83
commit 4262f469d6
5 changed files with 337 additions and 473 deletions

View File

@@ -0,0 +1,37 @@
"""
Fixtures for mailbox manager tests
"""
import re
import pytest
import responses
from rest_framework import status
from mailbox_manager import factories
from mailbox_manager.tests.fixtures.dimail import TOKEN_OK
## DIMAIL RESPONSES
@pytest.fixture(name="dimail_token_ok")
def fixture_dimail_token_ok():
"""Mock dimail response when /token/ endpoit is given valid credentials."""
responses.add(
responses.GET,
re.compile(r".*/token/"),
body=TOKEN_OK,
status=status.HTTP_200_OK,
content_type="application/json",
)
@pytest.fixture(name="mailbox_data")
def fixture_mailbox_data():
"""Provides valid mailbox data for tests."""
example = factories.MailboxFactory.build()
return {
"first_name": example.first_name,
"last_name": example.last_name,
"local_part": example.local_part,
"secondary_email": example.secondary_email,
}

View File

@@ -3,9 +3,8 @@
import json
## USERS
def response_user_created(user_sub):
"""mimic dimail response upon successful user creation."""
return json.dumps(
@@ -19,7 +18,6 @@ def response_user_created(user_sub):
## DOMAINS
CHECK_DOMAIN_BROKEN = {
"name": "example.fr",
"state": "broken",
@@ -290,12 +288,10 @@ DOMAIN_SPEC = [
## TOKEN
TOKEN_OK = json.dumps({"access_token": "token", "token_type": "bearer"})
## ALLOWS
def response_allows_created(user_name, domain_name):
"""mimic dimail response upon successful allows creation.
Dimail expects a name but our names are ProConnect's uuids."""
@@ -303,8 +299,6 @@ def response_allows_created(user_name, domain_name):
## MAILBOXES
def response_mailbox_created(email_address):
"""mimic dimail response upon successful mailbox creation."""
return json.dumps({"email": email_address, "password": "password"})