summaryrefslogtreecommitdiff
path: root/addons/base_setup/tests
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/base_setup/tests
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/base_setup/tests')
-rw-r--r--addons/base_setup/tests/__init__.py5
-rw-r--r--addons/base_setup/tests/test_res_config.py96
-rw-r--r--addons/base_setup/tests/test_res_config_doc_links.py57
3 files changed, 158 insertions, 0 deletions
diff --git a/addons/base_setup/tests/__init__.py b/addons/base_setup/tests/__init__.py
new file mode 100644
index 00000000..5c94e50e
--- /dev/null
+++ b/addons/base_setup/tests/__init__.py
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import test_res_config
+from . import test_res_config_doc_links
diff --git a/addons/base_setup/tests/test_res_config.py b/addons/base_setup/tests/test_res_config.py
new file mode 100644
index 00000000..67b32ed1
--- /dev/null
+++ b/addons/base_setup/tests/test_res_config.py
@@ -0,0 +1,96 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from unittest.mock import patch
+from odoo.tests.common import TransactionCase
+
+
+def just_raise(*args):
+ raise Exception("We should not be here.")
+
+
+class TestResConfig(TransactionCase):
+
+ def setUp(self):
+ super(TestResConfig, self).setUp()
+
+ self.user = self.env.ref('base.user_admin')
+ self.company = self.env['res.company'].create({'name': 'oobO'})
+ self.user.write({'company_ids': [(4, self.company.id)], 'company_id': self.company.id})
+ Settings = self.env['res.config.settings'].with_user(self.user.id)
+ self.config = Settings.create({})
+
+ def test_multi_company_res_config_group(self):
+ # Enable/Disable a group in a multi-company environment
+ # 1/ All the users should be added/removed from the group
+ # and not only the users of the allowed companies
+ # 2/ The changes should be reflected for new users (Default User Template)
+
+ company = self.env['res.company'].create({'name': 'My Last Company'})
+ partner = self.env['res.partner'].create({
+ 'name': 'My User'
+ })
+ user = self.env['res.users'].create({
+ 'login': 'My User',
+ 'company_id': company.id,
+ 'company_ids': [(4, company.id)],
+ 'partner_id': partner.id,
+ })
+
+ ResConfig = self.env['res.config.settings']
+ default_values = ResConfig.default_get(list(ResConfig.fields_get()))
+
+ # Case 1: Enable a group
+ default_values.update({'group_multi_currency': True})
+ ResConfig.create(default_values).execute()
+ self.assertTrue(user in self.env.ref('base.group_multi_currency').sudo().users)
+
+ new_partner = self.env['res.partner'].create({'name': 'New User'})
+ new_user = self.env['res.users'].create({
+ 'login': 'My First New User',
+ 'company_id': company.id,
+ 'company_ids': [(4, company.id)],
+ 'partner_id': new_partner.id,
+ })
+ self.assertTrue(new_user in self.env.ref('base.group_multi_currency').sudo().users)
+
+ # Case 2: Disable a group
+ default_values.update({'group_multi_currency': False})
+ ResConfig.create(default_values).execute()
+ self.assertTrue(user not in self.env.ref('base.group_multi_currency').sudo().users)
+
+ new_partner = self.env['res.partner'].create({'name': 'New User'})
+ new_user = self.env['res.users'].create({
+ 'login': 'My Second New User',
+ 'company_id': company.id,
+ 'company_ids': [(4, company.id)],
+ 'partner_id': new_partner.id,
+ })
+ self.assertTrue(new_user not in self.env.ref('base.group_multi_currency').sudo().users)
+
+ def test_no_install(self):
+ """Make sure that when saving settings,
+ no modules are installed if nothing was set to install.
+ """
+ # check that no module should be installed in the first place
+ config_fields = self.config._get_classified_fields()
+ for name, module in config_fields['module']:
+ if int(self.config[name]):
+ self.assertTrue(module.state != 'uninstalled',
+ "All set modules should already be installed.")
+ # if we try to install something, raise; so nothing should be installed
+ with patch('odoo.addons.base.models.ir_module.Module._button_immediate_function', new=just_raise):
+ self.config.execute()
+
+ def test_install(self):
+ """Make sure that the previous test is valid, i.e. when saving settings,
+ it starts module install if something was set to install.
+ """
+ config_fields = self.config._get_classified_fields()
+ # set the first uninstalled module to install
+ module_to_install = next(filter(lambda m: m[1].state == 'uninstalled', config_fields['module']))
+ self.config[module_to_install[0]] = True
+
+ with patch('odoo.addons.base.models.ir_module.Module._button_immediate_function', new=just_raise):
+ with self.assertRaisesRegex(Exception, "We should not be here."):
+ self.config.execute()
diff --git a/addons/base_setup/tests/test_res_config_doc_links.py b/addons/base_setup/tests/test_res_config_doc_links.py
new file mode 100644
index 00000000..2175d59b
--- /dev/null
+++ b/addons/base_setup/tests/test_res_config_doc_links.py
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo.tests.common import HttpCase, tagged
+import re
+
+
+@tagged('-standard', 'external', 'post_install', '-at_install') # nightly is not a real tag
+class TestResConfigDocLinks(HttpCase):
+ """
+ Parse the 'res_config' view to extract all documentation links and
+ check that every links are still valid.
+ """
+
+ def setUp(self):
+ """
+ Set-up the test environment
+ """
+ super(TestResConfigDocLinks, self).setUp()
+ self.re = re.compile("<a href=\"(\S+/documentation/\S+)\"")
+ self.links = set()
+
+ def test_01_links(self):
+ """
+ Firs test: check that all documentation links in 'res_config_settings'
+ views are not broken.
+ """
+ self._parse_view(self.env.ref('base.res_config_settings_view_form'))
+
+ for link in self.links:
+ self._check_link(link)
+
+ def _check_link(self, link):
+ """
+ Try to open the link and check the response status code
+ """
+ res = self.url_open(url=link)
+
+ self.assertEqual(
+ res.status_code, 200,
+ "The following link is broken: '%s'" % (link)
+ )
+
+ def _parse_view(self, view):
+ """
+ Analyse the view to extract documentation links and store them
+ in a set.
+ Then, parse its children if any.
+ """
+
+ # search the documentation links in the current view
+ for match in re.finditer(self.re, view.arch):
+ self.links.add(match.group(1))
+
+ # and then, search inside children
+ for child in view.inherit_children_ids:
+ self._parse_view(child)