Files
odoo_source/odoo/addons/test_new_api/tests/test_attributes.py
T
xmo-odoo 2e6a589f41 [FIX] builtins removed from Python 3
* Reverse wrapper courtesy of @rco-odoo's original P3 branch
* thin compat module stripped down from werkzeug (to augment as needed)

issue 8530
2017-04-27 13:59:33 +02:00

27 lines
880 B
Python

# -*- coding: utf-8 -*-
from odoo.tests import common
from odoo.tools import pycompat
ANSWER_TO_ULTIMATE_QUESTION = 42
class TestAttributes(common.TransactionCase):
def test_we_can_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, pycompat.integer_types)
# 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)