Babel's named / implicit formats (short, medium, long, ...) come from the CLDR, which can get tuned as debates get settled, cultures shift, etc... as a result using these formats can break tests on any babel or even CLDR release (technically nothing stops distros from updating their bundled babel with new CLDR data). b77eb98bbf6bc937efb7941802c0794ae3622094 previously did some mitigation of this issue, but even if they're not yet in distros further Babel updates (e.g. 2.12) already affect some of the patterns we're using. Proactively mitigate this issue more by only using explicit datetime patterns (and time patterns, date is fine because it retrieves the pattern from the lang rather than default to babel patterns) in the date/time formatting tests. This means only specific terms still vary, and those should be a lot more stable / reliable than e.g. futzing with separators and minor formatting issues. closes odoo/odoo#137181 X-original-commit: 3547e980428cc1dd11c8e82446e7d7f824b9f6f8 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from odoo.tests import common
|
|
|
|
|
|
class TestQwebFieldTime(common.TransactionCase):
|
|
def value_to_html(self, value, options=None):
|
|
options = options or {}
|
|
return self.env['ir.qweb.field.time'].value_to_html(value, options)
|
|
|
|
def test_time_value_to_html(self):
|
|
default_fmt = {'format': 'h:mm a'}
|
|
self.assertEqual(
|
|
self.value_to_html(0, default_fmt),
|
|
"12:00 AM"
|
|
)
|
|
|
|
self.assertEqual(
|
|
self.value_to_html(11.75, default_fmt),
|
|
"11:45 AM"
|
|
)
|
|
|
|
self.assertEqual(
|
|
self.value_to_html(12, default_fmt),
|
|
"12:00 PM"
|
|
)
|
|
|
|
self.assertEqual(
|
|
self.value_to_html(14.25, default_fmt),
|
|
"2:15 PM"
|
|
)
|
|
|
|
self.assertEqual(
|
|
self.value_to_html(15.1, {'format': 'HH:mm:SS'}),
|
|
"15:06:00"
|
|
)
|
|
|
|
# Only positive values can be used
|
|
with self.assertRaises(ValueError):
|
|
self.value_to_html(-6.5)
|
|
|
|
# Only values inferior to 24 can be used
|
|
with self.assertRaises(ValueError):
|
|
self.value_to_html(24)
|
|
|
|
|
|
class TestQwebFieldInteger(common.TransactionCase):
|
|
def value_to_html(self, value, options=None):
|
|
options = options or {}
|
|
return self.env['ir.qweb.field.integer'].value_to_html(value, options)
|
|
|
|
def test_integer_value_to_html(self):
|
|
self.assertEqual(self.value_to_html(1000), "1,000")
|
|
self.assertEqual(self.value_to_html(1000000, {'format_decimalized_number': True}), "1M")
|
|
self.assertEqual(
|
|
self.value_to_html(125125, {'format_decimalized_number': True, 'precision_digits': 3}),
|
|
"125.125k"
|
|
)
|