[IMP] website_forum: add tests for website/forum count

Add tests for website.forums_count field that should be synchronized manually
with the actual number of forum. Seems it is not working as expected, as
the manual update is not done at forum creation, and the default seems not
correctly computed.

Those tests are therefore red without the upcoming fix.

Task-3240082 (Forum: Reorganize and lint module)

Part-of: odoo/odoo#114841
This commit is contained in:
Thibault Delavallée
2023-03-22 17:03:29 +01:00
parent 86dec3b0d2
commit 64d5cc3899
3 changed files with 66 additions and 1 deletions
+1
View File
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from . import common
from . import test_forum_internals
from . import test_forum_karma_access
from . import test_forum_tours
from . import test_web_editor
+10
View File
@@ -24,6 +24,10 @@ class TestForumCommon(common.TransactionCase):
def setUpClass(cls):
super(TestForumCommon, cls).setUpClass()
# default base data
cls.base_website = cls.env.ref("website.default_website")
cls.base_forum = cls.env.ref("website_forum.forum_help")
Forum = cls.env['forum.forum']
Post = cls.env['forum.post']
@@ -94,3 +98,9 @@ class TestForumCommon(common.TransactionCase):
'forum_id': cls.forum.id,
'parent_id': cls.post.id,
})
@classmethod
def _activate_multi_website(cls):
cls.website_2 = cls.env['website'].create({
'name': 'Second Website on same company',
})
@@ -2,7 +2,61 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.website_forum.tests.common import KARMA, TestForumCommon
from odoo.tests import tagged
from odoo.tests import tagged, users
@tagged('forum_internals')
class TestForumInternals(TestForumCommon):
@classmethod
def setUpClass(cls):
super(TestForumInternals, cls).setUpClass()
cls._activate_multi_website()
@users('admin')
def test_assert_initial_values(self):
""" To ease test setup we support tests only with base data, to avoid
having to deal with custom / existing data in various asserts. """
forums = self.env['forum.forum'].search([])
self.assertEqual(forums, self.base_forum + self.forum)
self.assertFalse(forums.website_id)
@users('admin')
def test_website_forums_count(self):
""" Test synchronization of website / forum counters. """
base_website = self.base_website.with_env(self.env)
website_2 = self.website_2.with_env(self.env)
self.assertEqual(base_website.forums_count, 2,
'Should count default global forums')
self.assertEqual(website_2.forums_count, 2,
'Should count default global forums')
new_forums = self.env['forum.forum'].create([
{
'name': 'New Global',
'website_id': False,
}, {
'name': 'Base Website',
'website_id': base_website.id,
}, {
'name': 'Website 2',
'website_id': website_2.id,
}, {
'name': 'Website 2.2',
'website_id': website_2.id,
}
])
self.assertEqual(base_website.forums_count, 4,
'3 globals, 1 specific')
self.assertEqual(website_2.forums_count, 5,
'3 globals, 2 specific')
new_forums.write({'website_id': False})
self.assertEqual(base_website.forums_count, 6,
'6 global forums')
self.assertEqual(website_2.forums_count, 6,
'6 global forums')
@tagged('forum_internals')