Slug and unslug API is now available in http_routing. Indeed there is no link to any website or any reason to not support slufigied URLs when website is not installed. A new unslug_url method is added as a tool coming from an embedded method from website. Doing it allows to have all slug related methods defined at the same point. Support of slug and unslug in qweb rendering is also moved directly in http_routing version of ir_ui_view instead of website inheritance. This is done in order to keep things coherent. Some code from website about ModelConverter is also moved. Indeed both versions of ir_http uses some kind of placeholder to store the uid when converting urls to python. This commit unifies it by using the website one directly in base to simplify the override. This commit also updates all module importing slug. Enterprise modules will have to be updated, see related commit.
85 lines
2.0 KiB
Python
85 lines
2.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import unittest
|
|
from odoo.addons.http_routing.models.ir_http import slugify, unslug
|
|
|
|
from odoo.tools import pycompat
|
|
|
|
|
|
class TestUnslug(unittest.TestCase):
|
|
|
|
def test_unslug(self):
|
|
tests = {
|
|
'': (None, None),
|
|
'foo': (None, None),
|
|
'foo-': (None, None),
|
|
'-': (None, None),
|
|
'foo-1': ('foo', 1),
|
|
'foo-bar-1': ('foo-bar', 1),
|
|
'foo--1': ('foo', -1),
|
|
'1': (None, 1),
|
|
'1-1': ('1', 1),
|
|
'--1': (None, None),
|
|
'foo---1': (None, None),
|
|
'foo1': (None, None),
|
|
}
|
|
|
|
for slug, expected in pycompat.items(tests):
|
|
self.assertEqual(unslug(slug), expected)
|
|
|
|
|
|
class TestTitleToSlug(unittest.TestCase):
|
|
"""
|
|
Those tests should pass with or without python-slugify
|
|
See website/models/website.py slugify method
|
|
"""
|
|
|
|
def test_spaces(self):
|
|
self.assertEqual(
|
|
"spaces",
|
|
slugify(u" spaces ")
|
|
)
|
|
|
|
def test_unicode(self):
|
|
self.assertEqual(
|
|
"heterogeneite",
|
|
slugify(u"hétérogénéité")
|
|
)
|
|
|
|
def test_underscore(self):
|
|
self.assertEqual(
|
|
"one-two",
|
|
slugify(u"one_two")
|
|
)
|
|
|
|
def test_caps(self):
|
|
self.assertEqual(
|
|
"camelcase",
|
|
slugify(u"CamelCase")
|
|
)
|
|
|
|
def test_special_chars(self):
|
|
self.assertEqual(
|
|
"o-d-o-o",
|
|
slugify(u"o!#d{|\o/@~o&%^?")
|
|
)
|
|
|
|
def test_str_to_unicode(self):
|
|
self.assertEqual(
|
|
"espana",
|
|
slugify("España")
|
|
)
|
|
|
|
def test_numbers(self):
|
|
self.assertEqual(
|
|
"article-1",
|
|
slugify(u"Article 1")
|
|
)
|
|
|
|
def test_all(self):
|
|
self.assertEqual(
|
|
"do-you-know-martine-a-la-plage",
|
|
slugify(u"Do YOU know 'Martine à la plage' ?")
|
|
)
|