Skip to content

Commit

Permalink
✅(dimail) improve fetch domain status tests
Browse files Browse the repository at this point in the history
Add missing test case and add a new fake data
for fetch domain status from dimail
  • Loading branch information
sdemagny committed Jan 16, 2025
1 parent 86451df commit ea3a45e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
23 changes: 23 additions & 0 deletions src/backend/mailbox_manager/tests/fixtures/dimail.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,26 @@
],
},
}

CHECK_DOMAIN_OK = {
"name": "example.fr",
"state": "ok",
"valid": True,
"delivery": "virtual",
"features": ["webmail", "mailbox"],
"webmail_domain": None,
"imap_domain": None,
"smtp_domain": None,
"context_name": "example.fr",
"transport": None,
"domain_exist": {"ok": True, "internal": False, "errors": []},
"mx": {"ok": True, "internal": False, "errors": []},
"cname_imap": {"ok": True, "internal": False, "errors": []},
"cname_smtp": {"ok": True, "internal": False, "errors": []},
"cname_webmail": {"ok": True, "internal": False, "errors": []},
"spf": {"ok": True, "internal": False, "errors": []},
"dkim": {"ok": True, "internal": False, "errors": []},
"postfix": {"ok": True, "internal": True, "errors": []},
"ox": {"ok": True, "internal": True, "errors": []},
"cert": {"ok": True, "internal": True, "errors": []},
}
5 changes: 3 additions & 2 deletions src/backend/mailbox_manager/tests/test_admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from mailbox_manager import enums, factories

from .fixtures.dimail import CHECK_DOMAIN_BROKEN
from .fixtures.dimail import CHECK_DOMAIN_BROKEN, CHECK_DOMAIN_OK


@pytest.mark.django_db
Expand Down Expand Up @@ -61,7 +61,8 @@ def test_admin_action__fetch_domain_status_from_dimail(client):
assert "Check domains done with success" in response.content.decode("utf-8")

# check with a valid domain info from dimail
body_content_domain1["state"] = "ok"
body_content_domain1 = CHECK_DOMAIN_OK.copy()
body_content_domain1["name"] = domain1.name
rsps.add(
rsps.GET,
re.compile(rf".*/domains/{domain1.name}/check/"),
Expand Down
22 changes: 18 additions & 4 deletions src/backend/mailbox_manager/tests/test_utils_dimail_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from mailbox_manager import enums, factories, models
from mailbox_manager.utils.dimail import DimailAPIClient

from .fixtures.dimail import CHECK_DOMAIN_BROKEN
from .fixtures.dimail import CHECK_DOMAIN_BROKEN, CHECK_DOMAIN_OK

pytestmark = pytest.mark.django_db

Expand Down Expand Up @@ -163,16 +163,30 @@ def test_dimail__fetch_domain_status_from_dimail():
"""Request to dimail health status of a domain"""
domain = factories.MailDomainEnabledFactory()
with responses.RequestsMock() as rsps:
body_content_domain = CHECK_DOMAIN_BROKEN.copy()
body_content_domain["name"] = domain.name
body_content = CHECK_DOMAIN_BROKEN.copy()
body_content["name"] = domain.name
rsps.add(
rsps.GET,
re.compile(rf".*/domains/{domain.name}/check/"),
body=json.dumps(body_content_domain),
body=json.dumps(body_content),
status=status.HTTP_200_OK,
content_type="application/json",
)
dimail_client = DimailAPIClient()
response = dimail_client.fetch_domain_status(domain)
assert response.status_code == status.HTTP_200_OK
assert domain.status == enums.MailDomainStatusChoices.FAILED

# Now domain is ok again
body_content = CHECK_DOMAIN_OK.copy()
body_content["name"] = domain.name
rsps.add(
rsps.GET,
re.compile(rf".*/domains/{domain.name}/check/"),
body=json.dumps(body_content),
status=status.HTTP_200_OK,
content_type="application/json",
)
response = dimail_client.fetch_domain_status(domain)
assert response.status_code == status.HTTP_200_OK
assert domain.status == enums.MailDomainStatusChoices.ENABLED

0 comments on commit ea3a45e

Please sign in to comment.