summaryrefslogtreecommitdiff
path: root/addons/website_forum/tests
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2015-06-23 13:14:07 +0200
committerXavier Morel <xmo@odoo.com>2015-06-23 16:38:14 +0200
commit11ba4689b1d9d602cc27270239fd96f2af840106 (patch)
treef5d4938616f1fcc4f5afc9c2f4ac44751971306e /addons/website_forum/tests
parent386f76eb46deee167234edfb1f9b1d3bb6b86e5f (diff)
[IMP] running speed of some tests & new testcase type
Some tests (e.g. mail) have expensive and significant DB setup for a number of small and cheap tests. Using a TransactionCase, the DB setup far dominates the tests themselves, by up to 10x (mail unit tests take ~130s on my machine, the tests themselves take ~15s). The SavepointCase introduced here is an hybrid of SingleTransactionCase and TransactionCase: it uses a single transaction for all tests in a class, but each test case is isolated by a rollbacked savepoint. This allows a common DB setup (via setUpClass) while keeping independent tests. TransactionCase should remain the primary test case superclass, but SavepointCase can be a fair optimisation when setup costs far dominate.
Diffstat (limited to 'addons/website_forum/tests')
-rw-r--r--addons/website_forum/tests/common.py39
-rw-r--r--addons/website_forum/tests/test_forum.py4
2 files changed, 22 insertions, 21 deletions
diff --git a/addons/website_forum/tests/common.py b/addons/website_forum/tests/common.py
index 324d676fcb3..c92d72fae96 100644
--- a/addons/website_forum/tests/common.py
+++ b/addons/website_forum/tests/common.py
@@ -15,20 +15,21 @@ KARMA = {
}
-class TestForumCommon(common.TransactionCase):
+class TestForumCommon(common.SavepointCase):
- def setUp(self):
- super(TestForumCommon, self).setUp()
+ @classmethod
+ def setUpClass(cls):
+ super(TestForumCommon, cls).setUpClass()
- Forum = self.env['forum.forum']
- Post = self.env['forum.post']
+ Forum = cls.env['forum.forum']
+ Post = cls.env['forum.post']
# Test users
- TestUsersEnv = self.env['res.users'].with_context({'no_reset_password': True})
- group_employee_id = self.ref('base.group_user')
- group_portal_id = self.ref('base.group_portal')
- group_public_id = self.ref('base.group_public')
- self.user_employee = TestUsersEnv.create({
+ TestUsersEnv = cls.env['res.users'].with_context({'no_reset_password': True})
+ group_employee_id = cls.env.ref('base.group_user').id
+ group_portal_id = cls.env.ref('base.group_portal').id
+ group_public_id = cls.env.ref('base.group_public').id
+ cls.user_employee = TestUsersEnv.create({
'name': 'Armande Employee',
'login': 'Armande',
'alias_name': 'armande',
@@ -36,7 +37,7 @@ class TestForumCommon(common.TransactionCase):
'karma': 0,
'groups_id': [(6, 0, [group_employee_id])]
})
- self.user_portal = TestUsersEnv.create({
+ cls.user_portal = TestUsersEnv.create({
'name': 'Beatrice Portal',
'login': 'Beatrice',
'alias_name': 'beatrice',
@@ -44,7 +45,7 @@ class TestForumCommon(common.TransactionCase):
'karma': 0,
'groups_id': [(6, 0, [group_portal_id])]
})
- self.user_public = TestUsersEnv.create({
+ cls.user_public = TestUsersEnv.create({
'name': 'Cedric Public',
'login': 'Cedric',
'alias_name': 'cedric',
@@ -54,7 +55,7 @@ class TestForumCommon(common.TransactionCase):
})
# Test forum
- self.forum = Forum.create({
+ cls.forum = Forum.create({
'name': 'TestForum',
'karma_ask': KARMA['ask'],
'karma_answer': KARMA['ans'],
@@ -79,15 +80,15 @@ class TestForumCommon(common.TransactionCase):
'karma_gen_answer_accept': 9999,
'karma_gen_answer_accepted': 9999,
})
- self.post = Post.create({
+ cls.post = Post.create({
'name': 'TestQuestion',
'content': 'I am not a bird.',
- 'forum_id': self.forum.id,
- 'tag_ids': [(0, 0, {'name': 'Tag0', 'forum_id': self.forum.id})]
+ 'forum_id': cls.forum.id,
+ 'tag_ids': [(0, 0, {'name': 'Tag0', 'forum_id': cls.forum.id})]
})
- self.answer = Post.create({
+ cls.answer = Post.create({
'name': 'TestAnswer',
'content': 'I am an anteater.',
- 'forum_id': self.forum.id,
- 'parent_id': self.post.id,
+ 'forum_id': cls.forum.id,
+ 'parent_id': cls.post.id,
})
diff --git a/addons/website_forum/tests/test_forum.py b/addons/website_forum/tests/test_forum.py
index 7ca4c2a69ab..3f97dd7d916 100644
--- a/addons/website_forum/tests/test_forum.py
+++ b/addons/website_forum/tests/test_forum.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
-from openerp.addons.website_forum.tests.common import KARMA, TestForumCommon
-from openerp.addons.website_forum.models.forum import KarmaError
+from .common import KARMA, TestForumCommon
+from ..models.forum import KarmaError
from openerp.exceptions import Warning, AccessError
from openerp.tools import mute_logger