diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website/tests/test_converter.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website/tests/test_converter.py')
| -rw-r--r-- | addons/website/tests/test_converter.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/addons/website/tests/test_converter.py b/addons/website/tests/test_converter.py new file mode 100644 index 00000000..9a688c74 --- /dev/null +++ b/addons/website/tests/test_converter.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.addons.http_routing.models.ir_http import slugify, unslug +from odoo.tests.common import BaseCase + + +class TestUnslug(BaseCase): + + 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(BaseCase): + """ + 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' ?") + ) |
