Now that we're closer to switching to P3 for good, these helpers have outlived their usefulness, and mostly add noise. All remaining dict.iter*() or dict.view*() must be converted to the normal keys(), values() or items() calls. Whenever the result is likely to be used for more than the scope of a loop, or when the dict needs to be modified during iteration, the calls must be wrapped in a ``list()``, to protect the new P3 semantics. Those cases are very exceptional. Also removed some dead code or improved the API to remove unnecessary conversions.
83 lines
1.9 KiB
Python
83 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import unittest
|
|
from odoo.addons.website.models.website import slugify, unslug
|
|
|
|
|
|
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 tests.items():
|
|
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' ?")
|
|
)
|