Skip to content

Commit

Permalink
add unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Torres committed Jul 19, 2018
1 parent c423ba8 commit 7b3dc5f
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions odoo/addons/base/tests/test_ir_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def test_bindings(self):

class TestCustomFields(common.TransactionCase):
MODEL = 'res.partner'
COMODEL = 'res.users'

def setUp(self):
# check that the registry is properly reset
Expand Down Expand Up @@ -272,6 +273,49 @@ def test_create_custom(self):
with self.assertRaises(ValidationError):
self.create_field('foo')

def test_create_custom_o2m(self):
""" try creating a custom o2m and then deleting its m2o inverse """
model = self.env['ir.model'].search([('model', '=', self.MODEL)])
comodel = self.env['ir.model'].search([('model', '=', self.COMODEL)])

m2o_field = self.env['ir.model.fields'].create({
'model_id': comodel.id,
'name': 'x_my_m2o',
'field_description': 'my_m2o',
'ttype': 'many2one',
'relation': self.MODEL,
})

o2m_field = self.env['ir.model.fields'].create({
'model_id': model.id,
'name': 'x_my_o2m',
'field_description': 'my_o2m',
'ttype': 'one2many',
'relation': self.COMODEL,
'relation_field': m2o_field.name,
})

m2o_field.unlink()
self.assertFalse(o2m_field.exists())

def test_create_custom_related(self):
""" Try creating a custom related then deleting its inverse """
# Also applies to compute fields
comodel = self.env['ir.model'].search([('model', '=', self.COMODEL)])

field = self.create_field('x_my_char')

related_field = self.env['ir.model.fields'].create({
'model_id': comodel.id,
'name': 'x_oh_boy',
'field_description': 'x_oh_boy',
'ttype': 'char',
'related': 'partner_id.x_my_char',
})

field.unlink()
self.assertFalse(related_field.exists())

def test_rename_custom(self):
""" custom field names must be start with 'x_' """
field = self.create_field('x_foo')
Expand Down

0 comments on commit 7b3dc5f

Please sign in to comment.