Add test for custom compute methods
This commit is contained in:
parent
ea30313c43
commit
3dae9eeb7f
|
|
@ -23,6 +23,11 @@ class ServerEnvTest(models.Model):
|
|||
password = fields.Char()
|
||||
ssl = fields.Boolean()
|
||||
|
||||
# we'll use these ones to stress the custom
|
||||
# compute/inverse for the default value
|
||||
alias = fields.Char()
|
||||
alias_default = fields.Char()
|
||||
|
||||
|
||||
# Intentionally re-declares a class to stress the inclusion of the mixin
|
||||
class ServerEnvTestWithMixin(models.Model):
|
||||
|
|
@ -40,6 +45,19 @@ class ServerEnvTestWithMixin(models.Model):
|
|||
"user": {},
|
||||
"password": {},
|
||||
"ssl": {},
|
||||
"alias": {
|
||||
"no_default_field": True,
|
||||
"compute_default": "_compute_alias_default",
|
||||
"inverse_default": "_inverse_alias_default",
|
||||
}
|
||||
}
|
||||
sftp_fields.update(base_fields)
|
||||
return sftp_fields
|
||||
|
||||
def _compute_alias_default(self):
|
||||
for record in self:
|
||||
record.alias = record.alias_default
|
||||
|
||||
def _inverse_alias_default(self):
|
||||
for record in self:
|
||||
record.alias_default = record.alias
|
||||
|
|
|
|||
|
|
@ -131,3 +131,24 @@ class TestServerEnvMixin(ServerEnvironmentCase):
|
|||
self.assertEqual(foo.user, 'foo')
|
||||
self.assertEqual(foo.password, 'bar')
|
||||
self.assertTrue(foo.ssl)
|
||||
|
||||
def test_env_custom_compute_method(self):
|
||||
"""Can customize compute/inverse methods"""
|
||||
foo = self.env['server.env.test'].create({
|
||||
'name': 'foo',
|
||||
})
|
||||
self.assertNotIn('alias_env_default', foo._fields)
|
||||
with self.load_config():
|
||||
self.assertTrue(foo.alias_env_is_editable)
|
||||
|
||||
foo.alias = 'test'
|
||||
self.assertEqual(foo.alias_default, 'test')
|
||||
|
||||
foo = self.env['server.env.test'].create({
|
||||
'name': 'foo_with_default',
|
||||
})
|
||||
with self.load_config():
|
||||
self.assertTrue(foo.alias_env_is_editable)
|
||||
|
||||
foo.alias_default = 'new_value'
|
||||
self.assertEqual(foo.alias, 'new_value')
|
||||
|
|
|
|||
Loading…
Reference in New Issue