forked from odoo/odoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_fetchmail_outlook.py
59 lines (46 loc) · 2.13 KB
/
test_fetchmail_outlook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import time
from unittest.mock import ANY, Mock, patch
from odoo.exceptions import ValidationError
from odoo.tests.common import SavepointCase
class TestFetchmailOutlook(SavepointCase):
@patch('odoo.addons.fetchmail.models.fetchmail.IMAP4_SSL')
def test_connect(self, mock_imap):
"""Test that the connect method will use the right
authentication method with the right arguments.
"""
mock_connection = Mock()
mock_imap.return_value = mock_connection
mail_server = self.env['fetchmail.server'].create({
'name': 'Test server',
'use_microsoft_outlook_service': True,
'user': 'test@example.com',
'microsoft_outlook_access_token': 'test_access_token',
'microsoft_outlook_access_token_expiration': time.time() + 1000000,
'password': '',
'type': 'imap',
'is_ssl': True,
})
mail_server.connect()
mock_connection.authenticate.assert_called_once_with('XOAUTH2', ANY)
args = mock_connection.authenticate.call_args[0]
self.assertEqual(args[1](None), 'user=test@example.com\1auth=Bearer test_access_token\1\1',
msg='Should use the right access token')
mock_connection.select.assert_called_once_with('INBOX')
def test_constraints(self):
"""Test the constraints related to the Outlook mail server."""
with self.assertRaises(ValidationError, msg='Should ensure that the password is empty'):
self.env['fetchmail.server'].create({
'name': 'Test server',
'use_microsoft_outlook_service': True,
'password': 'test',
'type': 'imap',
})
with self.assertRaises(ValidationError, msg='Should ensure that the server type is IMAP'):
self.env['fetchmail.server'].create({
'name': 'Test server',
'use_microsoft_outlook_service': True,
'password': '',
'type': 'pop',
})