[ADD] tests for selection[function] and function fields export
bzr revid: xmo@openerp.com-20120730103214-t4s9g0z3sl1x05b3
This commit is contained in:
@@ -1,6 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from openerp.osv import orm, fields
|
||||
|
||||
def selection_fn(obj, cr, uid, context=None):
|
||||
return list(enumerate(["Corge", "Grault", "Wheee", "Moog"]))
|
||||
|
||||
def function_fn(model, cr, uid, ids, field_name, arg, context):
|
||||
return dict((id, 3) for id in ids)
|
||||
def function_fn_write(model, cr, uid, id, field_name, field_value, fnct_inv_arg, context):
|
||||
""" just so CreatorCase.export can be used
|
||||
"""
|
||||
pass
|
||||
|
||||
models = [
|
||||
('boolean', fields.boolean()),
|
||||
('integer', fields.integer()),
|
||||
@@ -12,13 +22,14 @@ models = [
|
||||
('datetime', fields.datetime()),
|
||||
('text', fields.text()),
|
||||
('selection', fields.selection([(1, "Foo"), (2, "Bar"), (3, "Qux")])),
|
||||
('selection.function', fields.selection(selection_fn)),
|
||||
# just relate to an integer
|
||||
('many2one', fields.many2one('export.integer')),
|
||||
('one2many', fields.one2many('export.one2many.child', 'parent_id')),
|
||||
('many2many', fields.many2many('export.many2many.other'))
|
||||
# TODO: function?
|
||||
# TODO: related?
|
||||
# TODO: reference?
|
||||
('many2many', fields.many2many('export.many2many.other')),
|
||||
('function', fields.function(function_fn, fnct_inv=function_fn_write, type="integer")),
|
||||
# related: specialization of fields.function, should work the same way
|
||||
# TODO: reference
|
||||
]
|
||||
for name, field in models:
|
||||
attrs = {
|
||||
|
||||
@@ -7,7 +7,7 @@ from . import common, export_models
|
||||
|
||||
|
||||
def setUpModule():
|
||||
openerp.tools.config['update'] = dict(base=1)
|
||||
openerp.tools.config['update'] = {'base': 1}
|
||||
openerp.modules.registry.RegistryManager.new(
|
||||
common.DB, update_module=True)
|
||||
|
||||
@@ -237,6 +237,28 @@ class test_selection(CreatorCase):
|
||||
self.export(2),
|
||||
[[u"Bar"]])
|
||||
|
||||
class test_selection_function(CreatorCase):
|
||||
model_name = 'export.selection.function'
|
||||
|
||||
def test_empty(self):
|
||||
self.assertEqual(
|
||||
self.export(False),
|
||||
[[False]])
|
||||
|
||||
def test_value(self):
|
||||
""" selection functions export the *value* itself
|
||||
"""
|
||||
self.assertEqual(
|
||||
self.export(1),
|
||||
[[u'1']])
|
||||
self.assertEqual(
|
||||
self.export(3),
|
||||
[[u'3']])
|
||||
# fucking hell
|
||||
self.assertEqual(
|
||||
self.export(0),
|
||||
[[False]])
|
||||
|
||||
class test_m2o(CreatorCase):
|
||||
model_name = 'export.many2one'
|
||||
|
||||
@@ -518,3 +540,13 @@ class test_m2m(CreatorCase):
|
||||
]])
|
||||
|
||||
# essentially same as o2m, so boring
|
||||
|
||||
class test_function(CreatorCase):
|
||||
model_name = 'export.function'
|
||||
|
||||
def test_value(self):
|
||||
""" Exports value normally returned by accessing the function field
|
||||
"""
|
||||
self.assertEqual(
|
||||
self.export(42),
|
||||
[[u'3']])
|
||||
|
||||
Reference in New Issue
Block a user