From 72bc56b028bb9a2ae37bedfe348ab2d3bdce79a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 19 Apr 2021 10:22:36 +0000 Subject: [FIX] link_tracker: allow mock to parse HTML to find shortened links Some incoming tests crash if parser is not the HTML parser when trying to find a node given its ID. We also remove an unnecessary encapsulation, allowing to avoid issues like embedding a body or head tag within a div. Task ID-2508643 Prepares Task ID-27033 (support QWeb in templates) Prepares Task ID-2377974 (clean trace and status management in mass mailing) COM PR odoo/odoo#69461 ENT PR odoo/enterprise#17780 --- addons/link_tracker/tests/common.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'addons/link_tracker') diff --git a/addons/link_tracker/tests/common.py b/addons/link_tracker/tests/common.py index 943f06ec385..6daa1489465 100644 --- a/addons/link_tracker/tests/common.py +++ b/addons/link_tracker/tests/common.py @@ -22,7 +22,8 @@ class MockLinkTracker(common.BaseCase): self.addCleanup(link_tracker_title_patch.stop) def _get_href_from_anchor_id(self, body, anchor_id): - html = etree.fromstring(body) + """ Parse en html body to find the href of an element given its ID. """ + html = etree.fromstring(body, parser=etree.HTMLParser()) return html.xpath("//*[@id='%s']" % anchor_id)[0].attrib.get('href') def _get_tracker_from_short_url(self, short_url): @@ -41,7 +42,7 @@ class MockLinkTracker(common.BaseCase): ) """ (anchor_id, url, is_shortened) = link_info - anchor_href = self._get_href_from_anchor_id("
%s
" % body, anchor_id) + anchor_href = self._get_href_from_anchor_id(body, anchor_id) if is_shortened: self.assertTrue('/r/' in anchor_href, '%s should be shortened: %s' % (anchor_id, anchor_href)) link_tracker = self._get_tracker_from_short_url(anchor_href) -- cgit v1.2.3