File: test_ir_model.py

package info (click to toggle)
odoo 18.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 878,716 kB
  • sloc: javascript: 927,937; python: 685,670; xml: 388,524; sh: 1,033; sql: 415; makefile: 26
file content (46 lines) | stat: -rw-r--r-- 1,975 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import odoo
from odoo.tests import HttpCase


@odoo.tests.tagged('-at_install', 'post_install')
class TestGetModelDefinitions(HttpCase):
    def test_access_cr(self):
        """ Checks that get_model_definitions does not return anything else than models """
        with self.assertRaises(KeyError):
            self.env['ir.model']._get_model_definitions(['res.users', 'cr'])

    def test_access_all_model_fields(self):
        """
            Check that get_model_definitions return all the models
            and their fields
        """
        model_definitions = self.env['ir.model']._get_model_definitions([
            'res.users', 'res.partner'
        ])
        # models are retrieved
        self.assertIn('res.users', model_definitions)
        self.assertIn('res.partner', model_definitions)
        # check that model fields are retrieved
        self.assertGreaterEqual(model_definitions['res.partner']["fields"].keys(), {'active', 'name', 'user_ids'})
        self.assertGreaterEqual(model_definitions['res.partner']["fields"].keys(), {'active', 'name', 'user_ids'})

    def test_relational_fields_with_missing_model(self):
        """
            Check that get_model_definitions only returns relational fields
            if the model is requested
        """
        model_definitions = self.env['ir.model']._get_model_definitions([
            'res.partner'
        ])
        # since res.country is not requested, country_id shouldn't be in
        # the model definition fields
        self.assertNotIn('country_id', model_definitions['res.partner']["fields"])

        model_definitions = self.env['ir.model']._get_model_definitions([
            'res.partner', 'res.country',
        ])
        # res.country is requested, country_id should be present on res.partner
        self.assertIn('country_id', model_definitions['res.partner']["fields"])