summaryrefslogtreecommitdiff
path: root/addons/test_mail/tests
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2019-09-10 10:16:08 +0000
committerThibault Delavallée <tde@odoo.com>2019-11-20 16:00:36 +0000
commit9b710e4ab6de7f3db60b97862354c91427792598 (patch)
treebd59c3b8f037243d439d53de8a563cbe709056a1 /addons/test_mail/tests
parentc3be4c3bc6f7ca320da06bf71bfdfb3aebc3cbd5 (diff)
[IMP] test_mail: add a new main TestMailCommon test class
PURPOSE Currently tools and asserts for mail tests are located inside test_mail module. It makes difficult to re-use them in application tests or force them to write custom quick and dirty tools and asserts. Purpose of this merge is therefore to move tools classes and mocks to mail directly and use them in various sub modules. SPECIFICATIONS In this commit we add ``TestMailCommon`` that will be the class for all test_* modules linked to mail features. It is build upon tools made available in mail tests (mocks, tools, asserts) and give the functional basis for mail tests. This commit also introduces ``TestMailMultiCompanyCommon`` that is a small multi company testing class build on ``TestMailCommon``. ``TestRecipients`` class is kept as it creates some testing partners, used notably for notifications and recipients. Future commits will gradually make tests use this class instead of the ``BaseFunctionalTest`` that will be set to retirement. LINKS Task ID 2068986 PR #38070
Diffstat (limited to 'addons/test_mail/tests')
-rw-r--r--addons/test_mail/tests/common.py64
1 files changed, 60 insertions, 4 deletions
diff --git a/addons/test_mail/tests/common.py b/addons/test_mail/tests/common.py
index bda876d61ef..717677cf643 100644
--- a/addons/test_mail/tests/common.py
+++ b/addons/test_mail/tests/common.py
@@ -1,21 +1,77 @@
# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
import json
import time
from contextlib import contextmanager
-from functools import partial
from odoo import api
from odoo.addons.bus.models.bus import json_dump
-from odoo.tests import common, tagged, new_test_user
+from odoo.addons.mail.tests import common as mail_common
+from odoo.tests import common, tagged
from odoo.tools import formataddr
-mail_new_test_user = partial(new_test_user, context={'mail_create_nolog': True, 'mail_create_nosubscribe': True, 'mail_notrack': True, 'no_reset_password': True})
+mail_new_test_user = mail_common.mail_new_test_user
-class BaseFunctionalTest(common.SavepointCase):
+class TestMailCommon(common.SavepointCase, mail_common.MailCase):
+
+ @classmethod
+ def setUpClass(cls):
+ super(TestMailCommon, cls).setUpClass()
+ # give default values for all email aliases and domain
+ cls._init_mail_gateway()
+ # ensure admin configuration
+ cls.user_admin = cls.env.ref('base.user_admin')
+ cls.user_admin.write({'notification_type': 'inbox'})
+ cls.partner_admin = cls.env.ref('base.partner_admin')
+ cls.company_admin = cls.user_admin.company_id
+ cls.company_admin.write({'email': 'company@example.com'})
+ # test standard employee
+ cls.user_employee = mail_new_test_user(
+ cls.env, login='employee', groups='base.group_user', company_id=cls.company_admin.id,
+ name='Ernest Employee', notification_type='inbox', signature='--\nErnest')
+ cls.partner_employee = cls.user_employee.partner_id
+ @classmethod
+ def _create_channel_listener(cls):
+ cls.channel_listen = cls.env['mail.channel'].with_context(cls._test_context).create({'name': 'Listener'})
+
+ @classmethod
+ def _create_portal_user(cls):
+ cls.user_portal = mail_new_test_user(
+ cls.env, login='portal_test', groups='base.group_portal', company_id=cls.company_admin.id,
+ name='Chell Gladys', notification_type='email')
+ cls.partner_portal = cls.user_portal.partner_id
+ return cls.user_portal
+
+ @classmethod
+ def _create_template(cls, model, template_values=None):
+ create_values = {
+ 'name': 'TestTemplate',
+ 'subject': 'About ${object.name}',
+ 'body_html': '<p>Hello ${object.name}</p>',
+ 'model_id': cls.env['ir.model']._get(model).id,
+ 'user_signature': False,
+ }
+ if template_values:
+ create_values.update(template_values)
+ cls.email_template = cls.env['mail.template'].create(create_values)
+ return cls.email_template
+
+
+class TestMailMultiCompanyCommon(TestMailCommon):
+
+ @classmethod
+ def setUpClass(cls):
+ super(TestMailMultiCompanyCommon, cls).setUpClass()
+ cls.company_2 = cls.env['res.company'].create({
+ 'name': 'Second Test Company',
+ })
+
+
+class BaseFunctionalTest(common.SavepointCase):
_test_context = {
'mail_create_nolog': True,
'mail_create_nosubscribe': True,