[ADD] support for a version switcher in odoo theme thing
[odoo/odoo.git] / openerp / addons / base / tests / test_ir_model.py
1 import unittest2
2
3 import openerp.tests.common as common
4
5 class test_ir_model(common.TransactionCase):
6
7     def test_00(self):
8         # Create some custom model and fields
9         cr, uid, context = self.cr, self.uid, {}
10
11         ir_model = self.registry('ir.model')
12         ir_model_fields = self.registry('ir.model.fields')
13         ir_model_access = self.registry('ir.model.access')
14         candy_model_id = ir_model.create(cr, uid, {
15                 'name': 'Candies',
16                 'model': 'x_candy',
17                 'info': 'List of candies',
18                 'state': 'manual',
19             }, context=context)
20         # security rule to avoid warning
21         ir_model_access.create(cr, uid, {
22                 'name': 'Candies are for everybody',
23                 'model_id': candy_model_id,
24                 'perm_read': True,
25                 'perm_write': True,
26                 'perm_create': True,
27                 'perm_unlink': True,
28             })
29
30         assert self.registry('x_candy'), "Custom model not present in registry"
31
32         ir_model_fields.create(cr, uid, {
33                 'name': 'x_name',
34                 'field_description': 'Name',
35                 'model_id': candy_model_id,
36                 'state': 'manual',
37                 'ttype': 'char',
38             }, context=context)
39
40         assert 'x_name' in self.registry('x_candy')._all_columns, "Custom field not present in registry"
41         assert self.registry('x_candy')._rec_name == 'x_name', "The _rec_name on custom model was not updated"
42
43 if __name__ == '__main__':
44     unittest2.main()