41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
import unittest
|
|
from types import SimpleNamespace
|
|
from unittest.mock import patch
|
|
|
|
|
|
class YYDSMailClientDomainTests(unittest.TestCase):
|
|
@patch('src.vmail_client.httpx.post')
|
|
def test_create_mailbox_sends_configured_domain(self, post_mock):
|
|
from src.vmail_client import YYDSMailClient, settings
|
|
|
|
captured = {}
|
|
|
|
def fake_post(url, headers=None, json=None, timeout=None):
|
|
captured['url'] = url
|
|
captured['headers'] = headers
|
|
captured['json'] = json
|
|
captured['timeout'] = timeout
|
|
return SimpleNamespace(
|
|
status_code=201,
|
|
json=lambda: {
|
|
'data': {
|
|
'id': 'box-1',
|
|
'address': 'chosen@20001028.xyz',
|
|
'token': 'temp-token',
|
|
}
|
|
},
|
|
)
|
|
|
|
post_mock.side_effect = fake_post
|
|
|
|
with patch.object(settings, 'yyds_mail_domain', '20001028.xyz', create=True):
|
|
client = YYDSMailClient()
|
|
mailbox = client.create_mailbox()
|
|
|
|
self.assertEqual(mailbox['address'], 'chosen@20001028.xyz')
|
|
self.assertEqual(captured['json'], {'domain': '20001028.xyz'})
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|