3
3
"""
4
4
5
5
import re
6
+ from logging import Logger
7
+ from unittest import mock
6
8
7
9
import pytest
8
10
import responses
@@ -61,7 +63,8 @@ def test_dimail_synchronization__already_sync():
61
63
assert set (models .Mailbox .objects .filter (domain = domain )) == set (pre_sync_mailboxes )
62
64
63
65
64
- def test_dimail_synchronization__synchronize_mailboxes ():
66
+ @mock .patch .object (Logger , "warning" )
67
+ def test_dimail_synchronization__synchronize_mailboxes (mock_warning ):
65
68
"""A mailbox existing solely on dimail should be synchronized
66
69
upon calling sync function on its domain"""
67
70
domain = factories .MailDomainEnabledFactory ()
@@ -77,33 +80,50 @@ def test_dimail_synchronization__synchronize_mailboxes():
77
80
status = status .HTTP_200_OK ,
78
81
content_type = "application/json" ,
79
82
)
83
+
84
+ mailbox = {
85
+ "type" : "mailbox" ,
86
+ "status" : "broken" ,
87
+ "email" : f"oxadmin@{ domain .name } " ,
88
+ "givenName" : "Admin" ,
89
+ "surName" : "Context" ,
90
+ "displayName" : "Context Admin" ,
91
+ }
92
+ mailbox_with_wrong_domain = {
93
+ "type" : "mailbox" ,
94
+ "status" : "broken" ,
95
+
96
+ "givenName" : "John" ,
97
+ "surName" : "Doe" ,
98
+ "displayName" : "John Doe" ,
99
+ }
100
+ mailbox_with_wrong_local_part = (
101
+ {
102
+ "type" : "mailbox" ,
103
+ "status" : "broken" ,
104
+ "email" : f"nawaké@{ domain .name } " ,
105
+ "givenName" : "Joe" ,
106
+ "surName" : "Doe" ,
107
+ "displayName" : "Joe Doe" ,
108
+ },
109
+ )
110
+
80
111
rsps .add (
81
112
rsps .GET ,
82
113
re .compile (rf".*/domains/{ domain .name } /mailboxes/" ),
83
114
body = str (
84
- [
85
- {
86
- "type" : "mailbox" ,
87
- "status" : "broken" ,
88
- "email" : f"oxadmin@{ domain .name } " ,
89
- "givenName" : "Admin" ,
90
- "surName" : "Context" ,
91
- "displayName" : "Context Admin" ,
92
- },
93
- {
94
- "type" : "mailbox" ,
95
- "status" : "broken" ,
96
-
97
- "givenName" : "John" ,
98
- "surName" : "Doe" ,
99
- "displayName" : "John Doe" ,
100
- },
101
- ]
115
+ [mailbox , mailbox_with_wrong_domain , mailbox_with_wrong_local_part ]
102
116
),
103
117
status = status .HTTP_200_OK ,
104
118
content_type = "application/json" ,
105
119
)
120
+
106
121
imported_mailboxes = dimail_client .synchronize_mailboxes_from_dimail (domain )
122
+ assert mock_warning .call_count == 1
123
+ assert mock_warning .call_args_list == (
124
+ "Import of email %s failed" ,
125
+ f"nawaké@{ domain .name } " ,
126
+ )
107
127
108
128
mailbox = models .Mailbox .objects .get ()
109
129
assert mailbox .local_part == "oxadmin"
0 commit comments