File: test_attributes.py

package info (click to toggle)
oca-core 11.0.20180730-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 509,684 kB
  • sloc: xml: 258,806; python: 164,081; sql: 217; sh: 92; makefile: 16
file content (26 lines) | stat: -rw-r--r-- 880 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# -*- 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)