[FIX] base_setup: test verifying validity of documentation links
Since c7c2959449, most documentation
links specified in the settings are written through a dedicated
documentation attribute on the setting nodes.
The test verifying the documentation links was not adapted
accordingly and therefore all the links specified with the new
API were not verified anymore.
closes odoo/odoo#110045
X-original-commit: 9abf52a666596f37a937892682815c321e0e69c4
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests.common import HttpCase, tagged
|
||||
import re
|
||||
from odoo.tests import HttpCase, tagged
|
||||
from odoo.release import url, version
|
||||
|
||||
|
||||
@tagged('-standard', 'external', 'post_install', '-at_install') # nightly is not a real tag
|
||||
@@ -12,24 +13,37 @@ class TestResConfigDocLinks(HttpCase):
|
||||
check that every links are still valid.
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
"""
|
||||
Set-up the test environment
|
||||
"""
|
||||
super(TestResConfigDocLinks, self).setUp()
|
||||
self.re = re.compile("<a href=\"(\S+/documentation/\S+)\"")
|
||||
self.links = set()
|
||||
super().setUpClass()
|
||||
cls.settings_view = cls.env.ref('base.res_config_settings_view_form')
|
||||
|
||||
def test_01_links(self):
|
||||
def test_01_href_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'))
|
||||
links_regex = re.compile(r"<a href=\"(\S+/documentation/\S+)\"")
|
||||
|
||||
for link in self.links:
|
||||
for link in self._extract_links_from_settings_view(links_regex, self.settings_view):
|
||||
self._check_link(link)
|
||||
|
||||
def test_02_setting_nodes_documentation_links(self):
|
||||
links_regex = re.compile(r"<setting .* documentation=\"(\S+)\"")
|
||||
|
||||
checked_links = set()
|
||||
for link in self._extract_links_from_settings_view(links_regex, self.settings_view):
|
||||
if not link.startswith("http"):
|
||||
# Only check links targeting odoo documentation, not external ones.
|
||||
if link in checked_links:
|
||||
continue
|
||||
self._check_link(
|
||||
f"{url}/documentation/{version if 'alpha' not in version else 'master'}{link}")
|
||||
checked_links.add(link)
|
||||
|
||||
def _check_link(self, link):
|
||||
"""
|
||||
Try to open the link and check the response status code
|
||||
@@ -41,17 +55,16 @@ class TestResConfigDocLinks(HttpCase):
|
||||
"The following link is broken: '%s'" % (link)
|
||||
)
|
||||
|
||||
def _parse_view(self, view):
|
||||
def _extract_links_from_settings_view(self, links_regex, 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))
|
||||
for match in re.finditer(links_regex, view.arch):
|
||||
yield match.group(1)
|
||||
|
||||
# and then, search inside children
|
||||
for child in view.inherit_children_ids:
|
||||
self._parse_view(child)
|
||||
yield from self._extract_links_from_settings_view(links_regex, child)
|
||||
|
||||
@@ -158,7 +158,7 @@
|
||||
<div class="mt16 text-warning"><strong>Save</strong> this page and come back here to set up the feature.</div>
|
||||
</div>
|
||||
</setting>
|
||||
<setting documentation="/websites/website/optimize/unsplash.html" help="Find free high-resolution images from Unsplash" id="unsplash">
|
||||
<setting documentation="/applications/websites/website/optimize/unsplash.html" help="Find free high-resolution images from Unsplash" id="unsplash">
|
||||
<field name="module_web_unsplash"/>
|
||||
<div class="content-group" attrs="{'invisible': [('module_web_unsplash', '=', False)]}" id="web_unsplash_warning">
|
||||
<div class="mt16 text-warning"><strong>Save</strong> this page and come back here to set up the feature.</div>
|
||||
|
||||
Reference in New Issue
Block a user