Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✅(dimail) improve fetch domain status tests #643

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading