[MIG] fetchmail_*: adapt tests
parent
27774d77b0
commit
61777bf31d
|
@ -1,6 +1,5 @@
|
||||||
# Copyright - 2015-2018 Therp BV <https://acme.com>.
|
# Copyright - 2015-2018 Therp BV <https://acme.com>.
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
from odoo import models
|
|
||||||
from odoo.tests.common import TransactionCase
|
from odoo.tests.common import TransactionCase
|
||||||
|
|
||||||
from ..match_algorithm import email_domain, email_exact, odoo_standard
|
from ..match_algorithm import email_domain, email_exact, odoo_standard
|
||||||
|
@ -49,16 +48,32 @@ class MockConnection:
|
||||||
|
|
||||||
|
|
||||||
class TestMatchAlgorithms(TransactionCase):
|
class TestMatchAlgorithms(TransactionCase):
|
||||||
def _get_base_folder(self):
|
@classmethod
|
||||||
server_model = self.env["fetchmail.server"]
|
def setUpClass(cls):
|
||||||
folder_model = self.env["fetchmail.server.folder"]
|
super().setUpClass()
|
||||||
folder = folder_model.browse([models.NewId()])
|
|
||||||
folder.model_id = self.env.ref("base.model_res_partner").id
|
cls.server_model = cls.env["fetchmail.server"]
|
||||||
folder.model_field = "email"
|
cls.folder_model = cls.env["fetchmail.server.folder"]
|
||||||
folder.match_algorithm = "EmailExact"
|
cls.server = cls.server_model.create(
|
||||||
folder.mail_field = "to,from"
|
{
|
||||||
folder.server_id = server_model.browse([models.NewId()])
|
"name": "Test Fetchmail Server",
|
||||||
return folder
|
"server": "imap.example.com",
|
||||||
|
"server_type": "imap",
|
||||||
|
"active": True,
|
||||||
|
"state": "done",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
cls.folder = cls.folder_model.create(
|
||||||
|
{
|
||||||
|
"server_id": cls.server.id,
|
||||||
|
"sequence": 5,
|
||||||
|
"path": "INBOX",
|
||||||
|
"model_id": cls.env.ref("base.model_res_partner").id,
|
||||||
|
"model_field": "email",
|
||||||
|
"match_algorithm": "email_exact",
|
||||||
|
"mail_field": "to,from",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def do_matching(
|
def do_matching(
|
||||||
self,
|
self,
|
||||||
|
@ -83,8 +98,7 @@ class TestMatchAlgorithms(TransactionCase):
|
||||||
"to": "demo@yourcompany.example.com",
|
"to": "demo@yourcompany.example.com",
|
||||||
"from": "someone@else.com",
|
"from": "someone@else.com",
|
||||||
}
|
}
|
||||||
folder = self._get_base_folder()
|
folder = self.folder
|
||||||
folder.match_algorithm = "EmailExact"
|
|
||||||
self.do_matching(
|
self.do_matching(
|
||||||
email_exact.EmailExact, "base.user_demo_res_partner", folder, mail_message
|
email_exact.EmailExact, "base.user_demo_res_partner", folder, mail_message
|
||||||
)
|
)
|
||||||
|
@ -100,8 +114,8 @@ class TestMatchAlgorithms(TransactionCase):
|
||||||
"from": "someone@else.com",
|
"from": "someone@else.com",
|
||||||
"attachments": [("hello.txt", "Hello World!")],
|
"attachments": [("hello.txt", "Hello World!")],
|
||||||
}
|
}
|
||||||
folder = self._get_base_folder()
|
folder = self.folder
|
||||||
folder.match_algorithm = "EmailDomain"
|
folder.match_algorithm = "email_domain"
|
||||||
folder.use_first_match = True
|
folder.use_first_match = True
|
||||||
self.do_matching(
|
self.do_matching(
|
||||||
email_domain.EmailDomain,
|
email_domain.EmailDomain,
|
||||||
|
@ -122,8 +136,8 @@ class TestMatchAlgorithms(TransactionCase):
|
||||||
"Message-Id: 42\n"
|
"Message-Id: 42\n"
|
||||||
"Hello world"
|
"Hello world"
|
||||||
)
|
)
|
||||||
folder = self._get_base_folder()
|
folder = self.folder
|
||||||
folder.match_algorithm = "OdooStandard"
|
folder.match_algorithm = "odoo_standard"
|
||||||
matcher = odoo_standard.OdooStandard()
|
matcher = odoo_standard.OdooStandard()
|
||||||
matches = matcher.search_matches(folder, None)
|
matches = matcher.search_matches(folder, None)
|
||||||
self.assertEqual(len(matches), 1)
|
self.assertEqual(len(matches), 1)
|
||||||
|
@ -134,15 +148,15 @@ class TestMatchAlgorithms(TransactionCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_apply_matching_exact(self):
|
def test_apply_matching_exact(self):
|
||||||
folder = self._get_base_folder()
|
folder = self.folder
|
||||||
folder.match_algorithm = "EmailExact"
|
folder.match_algorithm = "email_domain"
|
||||||
connection = MockConnection()
|
connection = MockConnection()
|
||||||
msgid = "<485a8041-d560-a981-5afc-d31c1f136748@acme.com>"
|
msgid = "<485a8041-d560-a981-5afc-d31c1f136748@acme.com>"
|
||||||
matcher = email_exact.EmailExact()
|
matcher = email_exact.EmailExact()
|
||||||
folder.apply_matching(connection, msgid, matcher)
|
folder.apply_matching(connection, msgid, matcher)
|
||||||
|
|
||||||
def test_retrieve_imap_folder_domain(self):
|
def test_retrieve_imap_folder_domain(self):
|
||||||
folder = self._get_base_folder()
|
folder = self.folder
|
||||||
folder.match_algorithm = "EmailDomain"
|
folder.match_algorithm = "email_domain"
|
||||||
connection = MockConnection()
|
connection = MockConnection()
|
||||||
folder.retrieve_imap_folder(connection)
|
folder.retrieve_imap_folder(connection)
|
||||||
|
|
Loading…
Reference in New Issue