summaryrefslogtreecommitdiff
path: root/odoo/addons/test_new_api/tests/test_attributes.py
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2020-04-07 13:51:30 +0000
committerRaphael Collet <rco@odoo.com>2020-05-18 09:51:43 +0000
commitea3e39506a2b360545ec0cd1d3235e69ad16ea6c (patch)
tree9d103c7a40911c988e1a3cbecfd8d6a76a3a9a85 /odoo/addons/test_new_api/tests/test_attributes.py
parent2e56191c8b86d05bbce17790de8a4732c0478013 (diff)
[IMP] models: use slots for BaseModel
This restricts the attributes of a BaseModel instance to `env`, `_ids` and `_prefetch_ids`. This way, one can only assign fields on a record; other assignments are programming errors. This also reduces the memory footprint of records from 168 to 64 bytes (-62%), and makes their instanciation faster. closes odoo/odoo#51075 Related: odoo/enterprise#10529 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo/addons/test_new_api/tests/test_attributes.py')
-rw-r--r--odoo/addons/test_new_api/tests/test_attributes.py19
1 files changed, 3 insertions, 16 deletions
diff --git a/odoo/addons/test_new_api/tests/test_attributes.py b/odoo/addons/test_new_api/tests/test_attributes.py
index 94a048f2554..27853d9a16e 100644
--- a/odoo/addons/test_new_api/tests/test_attributes.py
+++ b/odoo/addons/test_new_api/tests/test_attributes.py
@@ -1,25 +1,12 @@
# -*- coding: utf-8 -*-
from odoo.tests import common
-ANSWER_TO_ULTIMATE_QUESTION = 42
class TestAttributes(common.TransactionCase):
- def test_we_can_add_attributes(self):
+ def test_we_cannot_add_attributes(self):
Model = self.env['test_new_api.category']
instance = Model.create({'name': 'Foo'})
- # assign an unknown attribute
- instance.unknown = ANSWER_TO_ULTIMATE_QUESTION
-
- # Does the attribute exist in the instance of the model ?
- self.assertTrue(hasattr(instance, 'unknown'))
-
- # Is it the right type ?
- self.assertIsInstance(instance.unknown, int)
-
- # Is it the right value, in case of, we don't know ;-)
- self.assertEqual(instance.unknown, ANSWER_TO_ULTIMATE_QUESTION)
-
- # We are paranoiac !
- self.assertEqual(getattr(instance, 'unknown'), ANSWER_TO_ULTIMATE_QUESTION)
+ with self.assertRaises(AttributeError):
+ instance.unknown = 42