-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
""" | ||
|
||
import re | ||
from logging import Logger | ||
from unittest import mock | ||
|
||
import pytest | ||
import responses | ||
|
@@ -61,7 +63,8 @@ def test_dimail_synchronization__already_sync(): | |
assert set(models.Mailbox.objects.filter(domain=domain)) == set(pre_sync_mailboxes) | ||
|
||
|
||
def test_dimail_synchronization__synchronize_mailboxes(): | ||
@mock.patch.object(Logger, "warning") | ||
def test_dimail_synchronization__synchronize_mailboxes(mock_warning): | ||
"""A mailbox existing solely on dimail should be synchronized | ||
upon calling sync function on its domain""" | ||
domain = factories.MailDomainEnabledFactory() | ||
|
@@ -77,33 +80,50 @@ def test_dimail_synchronization__synchronize_mailboxes(): | |
status=status.HTTP_200_OK, | ||
content_type="application/json", | ||
) | ||
|
||
mailbox = { | ||
"type": "mailbox", | ||
"status": "broken", | ||
"email": f"oxadmin@{domain.name}", | ||
"givenName": "Admin", | ||
"surName": "Context", | ||
"displayName": "Context Admin", | ||
} | ||
mailbox_with_wrong_domain = { | ||
"type": "mailbox", | ||
"status": "broken", | ||
"email": f"[email protected]", | ||
"givenName": "John", | ||
"surName": "Doe", | ||
"displayName": "John Doe", | ||
} | ||
mailbox_with_wrong_local_part = ( | ||
{ | ||
"type": "mailbox", | ||
"status": "broken", | ||
"email": f"nawaké@{domain.name}", | ||
"givenName": "Joe", | ||
"surName": "Doe", | ||
"displayName": "Joe Doe", | ||
}, | ||
) | ||
|
||
rsps.add( | ||
rsps.GET, | ||
re.compile(rf".*/domains/{domain.name}/mailboxes/"), | ||
body=str( | ||
[ | ||
{ | ||
"type": "mailbox", | ||
"status": "broken", | ||
"email": f"oxadmin@{domain.name}", | ||
"givenName": "Admin", | ||
"surName": "Context", | ||
"displayName": "Context Admin", | ||
}, | ||
{ | ||
"type": "mailbox", | ||
"status": "broken", | ||
"email": f"[email protected]", | ||
"givenName": "John", | ||
"surName": "Doe", | ||
"displayName": "John Doe", | ||
}, | ||
] | ||
[mailbox, mailbox_with_wrong_domain, mailbox_with_wrong_local_part] | ||
), | ||
status=status.HTTP_200_OK, | ||
content_type="application/json", | ||
) | ||
|
||
imported_mailboxes = dimail_client.synchronize_mailboxes_from_dimail(domain) | ||
assert mock_warning.call_count == 1 | ||
assert mock_warning.call_args_list == ( | ||
"Import of email %s failed", | ||
f"nawaké@{domain.name}", | ||
) | ||
|
||
mailbox = models.Mailbox.objects.get() | ||
assert mailbox.local_part == "oxadmin" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters