✨(mailboxes) cannot create mailbox with same local part as alias
should not be able to create a mailbox having the same local part as an alias
This commit is contained in:
committed by
Marie
parent
23561cd0e0
commit
0f7e312eb6
@@ -80,7 +80,7 @@ def test_api_aliases_create__duplicate_forbidden():
|
||||
assert models.Alias.objects.filter(domain=access.domain).count() == 1
|
||||
|
||||
|
||||
def test_api_aliases_create__existing_alias_bad_request():
|
||||
def test_api_aliases_create__existing_mailbox_bad_request():
|
||||
"""Cannot create alias if local_part is already used by a mailbox."""
|
||||
access = factories.MailDomainAccessFactory(
|
||||
role="owner", domain=factories.MailDomainEnabledFactory()
|
||||
@@ -95,7 +95,7 @@ def test_api_aliases_create__existing_alias_bad_request():
|
||||
)
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
assert response.json() == {
|
||||
"local_part": [f'Local part "{mailbox.local_part}" already used for a mailbox.']
|
||||
"local_part": [f'Local part "{mailbox.local_part}" already used by a mailbox.']
|
||||
}
|
||||
assert not models.Alias.objects.exists()
|
||||
|
||||
|
||||
@@ -3,7 +3,10 @@ Tests for aliases API endpoint in People's app mailbox_manager.
|
||||
Focus on "list" action.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
import pytest
|
||||
import responses
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
@@ -87,6 +90,7 @@ def test_api_aliases_delete__viewer_can_delete_self_alias():
|
||||
assert not models.Alias.objects.exists()
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_api_aliases_delete__administrators_allowed():
|
||||
"""
|
||||
Administrators of a mail domain should be allowed to delete accesses excepted owner accesses.
|
||||
@@ -97,6 +101,14 @@ def test_api_aliases_delete__administrators_allowed():
|
||||
)
|
||||
alias = factories.AliasFactory(domain=mail_domain)
|
||||
|
||||
# Mock dimail response
|
||||
responses.add(
|
||||
responses.POST,
|
||||
re.compile(r".*/aliases/"),
|
||||
status=status.HTTP_204_NO_CONTENT,
|
||||
content_type="application/json",
|
||||
)
|
||||
|
||||
client = APIClient()
|
||||
client.force_login(authenticated_user)
|
||||
response = client.delete(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
Unit tests for the mailbox API
|
||||
"""
|
||||
# pylint: disable=W0613
|
||||
# pylint: disable=W0613, C0302
|
||||
|
||||
import json
|
||||
import re
|
||||
@@ -436,6 +436,35 @@ def test_api_mailboxes__create_pending_mailboxes(domain_status, mailbox_data):
|
||||
assert mailbox.status == "pending"
|
||||
|
||||
|
||||
def test_api_mailboxes__existing_alias_bad_request(mailbox_data):
|
||||
"""
|
||||
Cannot create mailbox if local_part is already used by an alias.
|
||||
"""
|
||||
alias = factories.AliasFactory()
|
||||
access = factories.MailDomainAccessFactory(
|
||||
role=enums.MailDomainRoleChoices.ADMIN, domain=alias.domain
|
||||
)
|
||||
|
||||
client = APIClient()
|
||||
client.force_login(access.user)
|
||||
# No response because we expect no outside calls to be made
|
||||
response = client.post(
|
||||
f"/api/v1.0/mail-domains/{access.domain.slug}/mailboxes/",
|
||||
{
|
||||
"local_part": alias.local_part,
|
||||
"first_name": mailbox_data["first_name"],
|
||||
"last_name": mailbox_data["last_name"],
|
||||
"secondary_email": mailbox_data["secondary_email"],
|
||||
},
|
||||
format="json",
|
||||
)
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
assert response.json() == {
|
||||
"local_part": [f'Local part "{alias.local_part}" already used by an alias.']
|
||||
}
|
||||
assert not models.Mailbox.objects.exists()
|
||||
|
||||
|
||||
### REACTING TO DIMAIL-API
|
||||
### We mock dimail's responses to avoid testing dimail's container too
|
||||
@responses.activate
|
||||
|
||||
Reference in New Issue
Block a user