✅(dimail) improve fetch domain status tests
Add missing test case and add a new fake data for fetch domain status from dimail
This commit is contained in:
@@ -80,3 +80,26 @@ CHECK_DOMAIN_BROKEN = {
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
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": []},
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ from core import factories as core_factories
|
||||
|
||||
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
|
||||
@@ -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/"),
|
||||
|
||||
@@ -15,7 +15,7 @@ from rest_framework import status
|
||||
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
|
||||
|
||||
@@ -163,12 +163,12 @@ 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",
|
||||
)
|
||||
@@ -176,3 +176,17 @@ def test_dimail__fetch_domain_status_from_dimail():
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user