-
-
Notifications
You must be signed in to change notification settings - Fork 687
/
test_tags.py
56 lines (47 loc) · 2.03 KB
/
test_tags.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Copyright 2018 Simone Orsi <simone.orsi@camptocamp.com>
# Copyright 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import HttpCase
from odoo.modules.module import get_resource_path
from odoo import tools
from lxml.html import document_fromstring
def load_xml(cr, module, filepath, kind='demo'):
tools.convert_file(
cr, module,
get_resource_path(module, filepath),
{}, mode='init', noupdate=False, kind=kind)
class UICase(HttpCase):
def setUp(self):
super(UICase, self).setUp()
self._reload_page()
self.website = self.env['website'].browse(1)
self.domain = self.website._get_canonical_domain()
self.path = "/canonical-demo"
self.url_absolute = self.domain + self.path
self.qstring = "?ultimate_answer=42"
self.url_full = "%s%s" % (self.url_absolute, self.qstring)
self.url_data = self.url_open(self.url_full)
self.doc = document_fromstring(self.url_data.content)
def _reload_page(self):
# if you run tests more than once (locally for instance)
# if you update the page we make sure is reloaded.
self.env.ref('website_canonical_url.canonical_demo_view').unlink()
load_xml(self.cr, 'website_canonical_url', 'demo/pages.xml')
def test_canonical(self):
"""Canonical URL is built OK."""
node = self.doc.xpath("/html/head/link[@rel='canonical']")[0]
self.assertEqual(node.attrib["href"], self.url_absolute)
def test_pager_next(self):
"""Next pager link is OK."""
node = self.doc.xpath("/html/head/link[@rel='next']")[0]
self.assertEqual(
node.attrib["href"],
"%s/page/3%s" % (self.path, self.qstring),
)
def test_pager_prev(self):
"""Prev pager link is OK."""
node = self.doc.xpath("/html/head/link[@rel='prev']")[0]
self.assertEqual(
node.attrib["href"],
"%s%s" % (self.path, self.qstring),
)