[TEST] localized import/export of selection fields
bzr revid: xmo@openerp.com-20120731144606-ceax7lk3rfi7zumk
This commit is contained in:
@@ -224,6 +224,11 @@ class test_datetime(CreatorCase):
|
||||
|
||||
class test_selection(CreatorCase):
|
||||
model_name = 'export.selection'
|
||||
translations_fr = [
|
||||
("Qux", "toto"),
|
||||
("Bar", "titi"),
|
||||
("Foo", "tete"),
|
||||
]
|
||||
|
||||
def test_empty(self):
|
||||
self.assertEqual(
|
||||
@@ -237,7 +242,28 @@ class test_selection(CreatorCase):
|
||||
self.export(2),
|
||||
[[u"Bar"]])
|
||||
|
||||
# TODO: localized export!
|
||||
def test_localized_export(self):
|
||||
self.registry('res.lang').create(self.cr, openerp.SUPERUSER_ID, {
|
||||
'name': u'Français',
|
||||
'code': 'fr_FR',
|
||||
'translatable': True,
|
||||
'date_format': '%d.%m.%Y',
|
||||
'decimal_point': ',',
|
||||
'thousand_sep': ' ',
|
||||
})
|
||||
Translations = self.registry('ir.translation')
|
||||
for source, value in self.translations_fr:
|
||||
Translations.create(self.cr, openerp.SUPERUSER_ID, {
|
||||
'name': 'export.selection,value',
|
||||
'lang': 'fr_FR',
|
||||
'type': 'selection',
|
||||
'src': source,
|
||||
'value': value
|
||||
})
|
||||
# FIXME: can't import an exported selection field label if lang != en_US
|
||||
self.assertEqual(
|
||||
self.export(2, context={'lang': 'fr_FR'}),
|
||||
[[u'Bar']])
|
||||
|
||||
class test_selection_function(CreatorCase):
|
||||
model_name = 'export.selection.function'
|
||||
@@ -390,7 +416,6 @@ class test_o2m(CreatorCase):
|
||||
[u'record5', '', u'13'],
|
||||
])
|
||||
|
||||
# todo: test with multiple o2m fields and exporting all
|
||||
class test_o2m_multiple(CreatorCase):
|
||||
model_name = 'export.one2many.multiple'
|
||||
|
||||
|
||||
@@ -372,6 +372,11 @@ class test_text(ImporterCase):
|
||||
|
||||
class test_selection(ImporterCase):
|
||||
model_name = 'export.selection'
|
||||
translations_fr = [
|
||||
("Qux", "toto"),
|
||||
("Bar", "titi"),
|
||||
("Foo", "tete"),
|
||||
]
|
||||
|
||||
def test_imported(self):
|
||||
self.assertEqual(
|
||||
@@ -384,6 +389,38 @@ class test_selection(ImporterCase):
|
||||
ok(4))
|
||||
self.assertEqual([3, 2, 1, 2], values(self.read()))
|
||||
|
||||
def test_imported_translated(self):
|
||||
self.registry('res.lang').create(self.cr, openerp.SUPERUSER_ID, {
|
||||
'name': u'Français',
|
||||
'code': 'fr_FR',
|
||||
'translatable': True,
|
||||
'date_format': '%d.%m.%Y',
|
||||
'decimal_point': ',',
|
||||
'thousand_sep': ' ',
|
||||
})
|
||||
Translations = self.registry('ir.translation')
|
||||
for source, value in self.translations_fr:
|
||||
Translations.create(self.cr, openerp.SUPERUSER_ID, {
|
||||
'name': 'export.selection,value',
|
||||
'lang': 'fr_FR',
|
||||
'type': 'selection',
|
||||
'src': source,
|
||||
'value': value
|
||||
})
|
||||
|
||||
self.assertEqual(
|
||||
self.import_(['value'], [
|
||||
['toto'],
|
||||
['tete'],
|
||||
['titi'],
|
||||
], context={'lang': 'fr_FR'}),
|
||||
ok(3))
|
||||
self.assertEqual([3, 1, 2], values(self.read()))
|
||||
self.assertEqual(
|
||||
self.import_(['value'], [['Foo']], context={'lang': 'fr_FR'}),
|
||||
error(1, "Key/value 'Foo' not found in selection field 'value'",
|
||||
value=False))
|
||||
|
||||
def test_invalid(self):
|
||||
self.assertEqual(
|
||||
self.import_(['value'], [['Baz']]),
|
||||
@@ -398,6 +435,12 @@ class test_selection(ImporterCase):
|
||||
|
||||
class test_selection_function(ImporterCase):
|
||||
model_name = 'export.selection.function'
|
||||
translations_fr = [
|
||||
("Corge", "toto"),
|
||||
("Grault", "titi"),
|
||||
("Whee", "tete"),
|
||||
("Moog", "tutu"),
|
||||
]
|
||||
|
||||
def test_imported(self):
|
||||
""" By what bloody magic does that thing work?
|
||||
@@ -407,7 +450,6 @@ class test_selection_function(ImporterCase):
|
||||
it: import does not actually know that the selection field uses a
|
||||
function
|
||||
"""
|
||||
# TODO: localized import
|
||||
self.assertEqual(
|
||||
self.import_(['value'], [
|
||||
[3],
|
||||
@@ -418,6 +460,36 @@ class test_selection_function(ImporterCase):
|
||||
['3', '1'],
|
||||
values(self.read()))
|
||||
|
||||
def test_translated(self):
|
||||
self.registry('res.lang').create(self.cr, openerp.SUPERUSER_ID, {
|
||||
'name': u'Français',
|
||||
'code': 'fr_FR',
|
||||
'translatable': True,
|
||||
'date_format': '%d.%m.%Y',
|
||||
'decimal_point': ',',
|
||||
'thousand_sep': ' ',
|
||||
})
|
||||
Translations = self.registry('ir.translation')
|
||||
for source, value in self.translations_fr:
|
||||
Translations.create(self.cr, openerp.SUPERUSER_ID, {
|
||||
'name': 'export.selection,value',
|
||||
'lang': 'fr_FR',
|
||||
'type': 'selection',
|
||||
'src': source,
|
||||
'value': value
|
||||
})
|
||||
# FIXME: Fucking hell
|
||||
self.assertEqual(
|
||||
self.import_(['value'], [
|
||||
['toto'],
|
||||
['tete'],
|
||||
], context={'lang': 'fr_FR'}),
|
||||
error(1, "Key/value 'toto' not found in selection field 'value'",
|
||||
value=False))
|
||||
self.assertEqual(
|
||||
self.import_(['value'], [['Wheee']], context={'lang': 'fr_FR'}),
|
||||
ok(1))
|
||||
|
||||
class test_m2o(ImporterCase):
|
||||
model_name = 'export.many2one'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user