Browse Source

mail_digest: improve tests perf w/ SavepointCase

pull/255/head
Simone Orsi 7 years ago
parent
commit
f0e5c19f8c
  1. 29
      mail_digest/tests/test_digest.py
  2. 25
      mail_digest/tests/test_partner_domains.py
  3. 23
      mail_digest/tests/test_subtypes_conf.py

29
mail_digest/tests/test_digest.py

@ -2,37 +2,38 @@
# Copyright 2017 Simone Orsi <simone.orsi@camptocamp.com> # Copyright 2017 Simone Orsi <simone.orsi@camptocamp.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from odoo.tests.common import TransactionCase
from odoo.tests.common import SavepointCase
from odoo import exceptions from odoo import exceptions
class DigestCase(TransactionCase):
class DigestCase(SavepointCase):
def setUp(self):
super(DigestCase, self).setUp()
self.partner_model = self.env['res.partner']
self.message_model = self.env['mail.message']
self.subtype_model = self.env['mail.message.subtype']
self.digest_model = self.env['mail.digest']
self.conf_model = self.env['partner.notification.conf']
@classmethod
def setUpClass(cls):
super(DigestCase, cls).setUpClass()
cls.partner_model = cls.env['res.partner']
cls.message_model = cls.env['mail.message']
cls.subtype_model = cls.env['mail.message.subtype']
cls.digest_model = cls.env['mail.digest']
cls.conf_model = cls.env['partner.notification.conf']
self.partner1 = self.partner_model.with_context(
cls.partner1 = cls.partner_model.with_context(
tracking_disable=1).create({ tracking_disable=1).create({
'name': 'Partner 1', 'name': 'Partner 1',
'email': 'partner1@test.foo.com', 'email': 'partner1@test.foo.com',
}) })
self.partner2 = self.partner_model.with_context(
cls.partner2 = cls.partner_model.with_context(
tracking_disable=1).create({ tracking_disable=1).create({
'name': 'Partner 2', 'name': 'Partner 2',
'email': 'partner2@test.foo.com', 'email': 'partner2@test.foo.com',
}) })
self.partner3 = self.partner_model.with_context(
cls.partner3 = cls.partner_model.with_context(
tracking_disable=1).create({ tracking_disable=1).create({
'name': 'Partner 3', 'name': 'Partner 3',
'email': 'partner3@test.foo.com', 'email': 'partner3@test.foo.com',
}) })
self.subtype1 = self.subtype_model.create({'name': 'Type 1'})
self.subtype2 = self.subtype_model.create({'name': 'Type 2'})
cls.subtype1 = cls.subtype_model.create({'name': 'Type 1'})
cls.subtype2 = cls.subtype_model.create({'name': 'Type 2'})
def test_get_or_create_digest(self): def test_get_or_create_digest(self):
message1 = self.message_model.create({ message1 = self.message_model.create({

25
mail_digest/tests/test_partner_domains.py

@ -2,34 +2,35 @@
# Copyright 2017 Simone Orsi <simone.orsi@camptocamp.com> # Copyright 2017 Simone Orsi <simone.orsi@camptocamp.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from odoo.tests.common import TransactionCase
from odoo.tests.common import SavepointCase
class PartnerDomainCase(TransactionCase):
class PartnerDomainCase(SavepointCase):
def setUp(self):
super(PartnerDomainCase, self).setUp()
self.partner_model = self.env['res.partner']
self.message_model = self.env['mail.message']
self.subtype_model = self.env['mail.message.subtype']
@classmethod
def setUpClass(cls):
super(PartnerDomainCase, cls).setUpClass()
cls.partner_model = cls.env['res.partner']
cls.message_model = cls.env['mail.message']
cls.subtype_model = cls.env['mail.message.subtype']
self.partner1 = self.partner_model.with_context(
cls.partner1 = cls.partner_model.with_context(
tracking_disable=1).create({ tracking_disable=1).create({
'name': 'Partner 1', 'name': 'Partner 1',
'email': 'partner1@test.foo.com', 'email': 'partner1@test.foo.com',
}) })
self.partner2 = self.partner_model.with_context(
cls.partner2 = cls.partner_model.with_context(
tracking_disable=1).create({ tracking_disable=1).create({
'name': 'Partner 2', 'name': 'Partner 2',
'email': 'partner2@test.foo.com', 'email': 'partner2@test.foo.com',
}) })
self.partner3 = self.partner_model.with_context(
cls.partner3 = cls.partner_model.with_context(
tracking_disable=1).create({ tracking_disable=1).create({
'name': 'Partner 3', 'name': 'Partner 3',
'email': 'partner3@test.foo.com', 'email': 'partner3@test.foo.com',
}) })
self.subtype1 = self.subtype_model.create({'name': 'Type 1'})
self.subtype2 = self.subtype_model.create({'name': 'Type 2'})
cls.subtype1 = cls.subtype_model.create({'name': 'Type 1'})
cls.subtype2 = cls.subtype_model.create({'name': 'Type 2'})
def _assert_found(self, domain, not_found=False, partner=None): def _assert_found(self, domain, not_found=False, partner=None):
partner = partner or self.partner1 partner = partner or self.partner1

23
mail_digest/tests/test_subtypes_conf.py

@ -2,29 +2,30 @@
# Copyright 2017 Simone Orsi <simone.orsi@camptocamp.com> # Copyright 2017 Simone Orsi <simone.orsi@camptocamp.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from odoo.tests.common import TransactionCase
from odoo.tests.common import SavepointCase
class SubtypesCase(TransactionCase):
class SubtypesCase(SavepointCase):
def setUp(self):
super(SubtypesCase, self).setUp()
self.partner_model = self.env['res.partner']
self.message_model = self.env['mail.message']
self.subtype_model = self.env['mail.message.subtype']
@classmethod
def setUpClass(cls):
super(SubtypesCase, cls).setUpClass()
cls.partner_model = cls.env['res.partner']
cls.message_model = cls.env['mail.message']
cls.subtype_model = cls.env['mail.message.subtype']
self.partner1 = self.partner_model.with_context(
cls.partner1 = cls.partner_model.with_context(
tracking_disable=1).create({ tracking_disable=1).create({
'name': 'Partner 1!', 'name': 'Partner 1!',
'email': 'partner1@test.foo.com', 'email': 'partner1@test.foo.com',
}) })
self.partner2 = self.partner_model.with_context(
cls.partner2 = cls.partner_model.with_context(
tracking_disable=1).create({ tracking_disable=1).create({
'name': 'Partner 2!', 'name': 'Partner 2!',
'email': 'partner2@test.foo.com', 'email': 'partner2@test.foo.com',
}) })
self.subtype1 = self.subtype_model.create({'name': 'Type 1'})
self.subtype2 = self.subtype_model.create({'name': 'Type 2'})
cls.subtype1 = cls.subtype_model.create({'name': 'Type 1'})
cls.subtype2 = cls.subtype_model.create({'name': 'Type 2'})
def _test_subtypes_rel(self): def _test_subtypes_rel(self):
# setup: # setup:

Loading…
Cancel
Save