Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
sdemagny committed Sep 30, 2024
1 parent 5b0e90c commit f9c92df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to
- ✨(mailbox) send new mailbox confirmation email #397
- ✨(domains) domain accesses update API #423
- ✨(backend) domain accesses create API #428
- ✨(api) domain accesses delete API #433

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ def test_api_mail_domain__accesses_delete_viewer():
)
access = factories.MailDomainAccessFactory(domain=mail_domain)

assert models.MailDomainAccess.objects.count() == 2
assert models.MailDomainAccess.objects.filter(user=access.user).exists()

client = APIClient()
client.force_login(authenticated_user)
response = client.delete(
Expand All @@ -67,35 +64,31 @@ def test_api_mail_domain__accesses_delete_viewer():

assert response.status_code == status.HTTP_403_FORBIDDEN
assert models.MailDomainAccess.objects.count() == 2
assert models.MailDomainAccess.objects.filter(user=access.user).exists()


def test_api_mail_domain__accesses_delete_administrators():
"""
Users who are administrators in a mail_domain should be allowed to delete an access
from the mail_domain provided it is not ownership.
Administrators of a mail domain should be allowed to delete accesses excepted owner accesses.
"""
authenticated_user = core_factories.UserFactory()
mail_domain = factories.MailDomainFactory(
users=[(authenticated_user, enums.MailDomainRoleChoices.ADMIN)]
)
access = factories.MailDomainAccessFactory(
domain=mail_domain,
role=random.choice(
[enums.MailDomainRoleChoices.VIEWER, enums.MailDomainRoleChoices.ADMIN]
),
)
for role in [enums.MailDomainRoleChoices.VIEWER, enums.MailDomainRoleChoices.ADMIN]:
access = factories.MailDomainAccessFactory(domain=mail_domain, role=role)

assert models.MailDomainAccess.objects.count() == 2
assert models.MailDomainAccess.objects.filter(user=access.user).exists()
assert models.MailDomainAccess.objects.count() == 2
assert models.MailDomainAccess.objects.filter(user=access.user).exists()

client = APIClient()
client.force_login(authenticated_user)
response = client.delete(
f"/api/v1.0/mail-domains/{mail_domain.slug}/accesses/{access.id!s}/",
)
client = APIClient()
client.force_login(authenticated_user)
response = client.delete(
f"/api/v1.0/mail-domains/{mail_domain.slug}/accesses/{access.id!s}/",
)

assert response.status_code == status.HTTP_204_NO_CONTENT
assert models.MailDomainAccess.objects.count() == 1
assert response.status_code == status.HTTP_204_NO_CONTENT
assert models.MailDomainAccess.objects.count() == 1


def test_api_mail_domain__accesses_delete_owners_except_owners():
Expand Down

0 comments on commit f9c92df

Please sign in to comment.