✅(tests) improve tests for mailbox api
Regroup mailbox-related tests + add test 404 when trying to retrive a domain that doesn't exist + use enabled domains on tests
This commit is contained in:
committed by
Marie
parent
b637774179
commit
402e73582c
@@ -55,7 +55,7 @@ class MailDomainAccessFactory(factory.django.DjangoModelFactory):
|
|||||||
model = models.MailDomainAccess
|
model = models.MailDomainAccess
|
||||||
|
|
||||||
user = factory.SubFactory(core_factories.UserFactory)
|
user = factory.SubFactory(core_factories.UserFactory)
|
||||||
domain = factory.SubFactory(MailDomainFactory)
|
domain = factory.SubFactory(MailDomainEnabledFactory)
|
||||||
role = factory.fuzzy.FuzzyChoice(
|
role = factory.fuzzy.FuzzyChoice(
|
||||||
[r[0] for r in enums.MailDomainRoleChoices.choices]
|
[r[0] for r in enums.MailDomainRoleChoices.choices]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pytestmark = pytest.mark.django_db
|
|||||||
def test_api_mail_domains__retrieve_anonymous():
|
def test_api_mail_domains__retrieve_anonymous():
|
||||||
"""Anonymous users should not be allowed to retrieve a domain."""
|
"""Anonymous users should not be allowed to retrieve a domain."""
|
||||||
|
|
||||||
domain = factories.MailDomainFactory()
|
domain = factories.MailDomainEnabledFactory()
|
||||||
response = APIClient().get(f"/api/v1.0/mail-domains/{domain.slug}/")
|
response = APIClient().get(f"/api/v1.0/mail-domains/{domain.slug}/")
|
||||||
|
|
||||||
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
assert response.status_code == status.HTTP_401_UNAUTHORIZED
|
||||||
@@ -25,6 +25,21 @@ def test_api_mail_domains__retrieve_anonymous():
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_domains__retrieve_non_existing():
|
||||||
|
"""
|
||||||
|
Authenticated users should have an explicit error when trying to retrive
|
||||||
|
a domain that doesn't exist.
|
||||||
|
"""
|
||||||
|
client = APIClient()
|
||||||
|
client.force_login(core_factories.UserFactory())
|
||||||
|
|
||||||
|
response = client.get(
|
||||||
|
"/api/v1.0/mail-domains/nonexistent.domain/",
|
||||||
|
)
|
||||||
|
assert response.status_code == status.HTTP_404_NOT_FOUND
|
||||||
|
assert response.json() == {"detail": "Not found."}
|
||||||
|
|
||||||
|
|
||||||
def test_api_mail_domains__retrieve_authenticated_unrelated():
|
def test_api_mail_domains__retrieve_authenticated_unrelated():
|
||||||
"""
|
"""
|
||||||
Authenticated users should not be allowed to retrieve a domain
|
Authenticated users should not be allowed to retrieve a domain
|
||||||
@@ -35,7 +50,7 @@ def test_api_mail_domains__retrieve_authenticated_unrelated():
|
|||||||
client = APIClient()
|
client = APIClient()
|
||||||
client.force_login(user)
|
client.force_login(user)
|
||||||
|
|
||||||
domain = factories.MailDomainFactory()
|
domain = factories.MailDomainEnabledFactory()
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
f"/api/v1.0/mail-domains/{domain.slug}/",
|
f"/api/v1.0/mail-domains/{domain.slug}/",
|
||||||
@@ -54,7 +69,7 @@ def test_api_mail_domains__retrieve_authenticated_related():
|
|||||||
client = APIClient()
|
client = APIClient()
|
||||||
client.force_login(user)
|
client.force_login(user)
|
||||||
|
|
||||||
domain = factories.MailDomainFactory()
|
domain = factories.MailDomainEnabledFactory()
|
||||||
factories.MailDomainAccessFactory(domain=domain, user=user)
|
factories.MailDomainAccessFactory(domain=domain, user=user)
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
|
|||||||
Reference in New Issue
Block a user