Skip to content

Commit

Permalink
[IMP] website_canonical_url: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yajo authored and pedrobaeza committed Dec 24, 2016
1 parent a81c0b4 commit 87d6579
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions website_canonical_url/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@
'data': [
'templates/layout.xml',
],
'demo': [
'demo/pages.xml',
],
}
15 changes: 15 additions & 0 deletions website_canonical_url/demo/pages.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 Jairo Llopis <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>

<template id="canonical_demo"
page="True"
name="Canonical URL and pager demo">
<t t-call="website.layout">
<!-- Add a fake pager to test the rel=prev/next links -->
<t t-set="pager" t-value="website.pager(request.httprequest.path, 5, 2, url_args=request.httprequest.args)"/>
</t>
</template>

</odoo>
5 changes: 5 additions & 0 deletions website_canonical_url/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Jairo Llopis <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_tags
29 changes: 29 additions & 0 deletions website_canonical_url/tests/test_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Jairo Llopis <[email protected]>
# 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"
with self.url_open("%s?ultimate_answer=42" % self.url) as data:
self.doc = document_fromstring(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" & self.url)

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)

0 comments on commit 87d6579

Please sign in to comment.