Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
yajo committed Dec 28, 2016
1 parent 9dea954 commit a7a5dd2
Show file tree
Hide file tree
Showing 4 changed files with 57 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, 100, 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
34 changes: 34 additions & 0 deletions website_canonical_url/tests/test_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- 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"
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)

0 comments on commit a7a5dd2

Please sign in to comment.