From 6e1422742cbf33e464d108517f1198d1e7127ebd Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Tue, 20 Dec 2016 12:01:51 +0100 Subject: [PATCH] Add tests. --- website_canonical_url/__openerp__.py | 3 +++ website_canonical_url/demo/pages.xml | 15 +++++++++++ website_canonical_url/tests/__init__.py | 5 ++++ website_canonical_url/tests/test_tags.py | 34 ++++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 website_canonical_url/demo/pages.xml create mode 100644 website_canonical_url/tests/__init__.py create mode 100644 website_canonical_url/tests/test_tags.py diff --git a/website_canonical_url/__openerp__.py b/website_canonical_url/__openerp__.py index 044992901d..e1dd41e5d4 100644 --- a/website_canonical_url/__openerp__.py +++ b/website_canonical_url/__openerp__.py @@ -16,4 +16,7 @@ 'data': [ 'templates/layout.xml', ], + 'demo': [ + 'demo/pages.xml', + ], } diff --git a/website_canonical_url/demo/pages.xml b/website_canonical_url/demo/pages.xml new file mode 100644 index 0000000000..c671e3acd1 --- /dev/null +++ b/website_canonical_url/demo/pages.xml @@ -0,0 +1,15 @@ + + + + + + + diff --git a/website_canonical_url/tests/__init__.py b/website_canonical_url/tests/__init__.py new file mode 100644 index 0000000000..1382db57d7 --- /dev/null +++ b/website_canonical_url/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_tags diff --git a/website_canonical_url/tests/test_tags.py b/website_canonical_url/tests/test_tags.py new file mode 100644 index 0000000000..437a3ac951 --- /dev/null +++ b/website_canonical_url/tests/test_tags.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.tests.common import HttpCase +from lxml.html import document_fromstring + + +class UICase(HttpCase): + def setUp(self): + super(UICase, self).setUp() + self.url = "/page/website_canonical_url.canonical_demo" + self.get = "?ultimate_answer=42" + self.url_get = "%s%s" % (self.url, self.get) + self.url_data = self.url_open(self.url_get) + self.doc = document_fromstring(self.url_data.read()) + + 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) + + 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.url, self.get), + ) + + 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"], self.url_get)