2022-11-17 15:49:41 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# __coconut_hash__ = 0x40e8d147
|
|
|
|
|
|
|
|
# Compiled with Coconut version 2.1.1 [The Spanish Inquisition]
|
|
|
|
|
|
|
|
""" Odoo Helpers tests """
|
|
|
|
|
|
|
|
# Coconut Header: -------------------------------------------------------------
|
|
|
|
|
|
|
|
from __future__ import generator_stop, annotations
|
|
|
|
import sys as _coconut_sys, os as _coconut_os
|
|
|
|
_coconut_file_dir = _coconut_os.path.dirname(_coconut_os.path.abspath(__file__))
|
|
|
|
_coconut_cached_module = _coconut_sys.modules.get("__coconut__")
|
|
|
|
if _coconut_cached_module is not None and _coconut_os.path.dirname(_coconut_cached_module.__file__) != _coconut_file_dir: # type: ignore
|
|
|
|
del _coconut_sys.modules["__coconut__"]
|
|
|
|
_coconut_sys.path.insert(0, _coconut_file_dir)
|
|
|
|
_coconut_module_name = _coconut_os.path.splitext(_coconut_os.path.basename(_coconut_file_dir))[0]
|
|
|
|
if _coconut_module_name and _coconut_module_name[0].isalpha() and all(c.isalpha() or c.isdigit() for c in _coconut_module_name) and "__init__.py" in _coconut_os.listdir(_coconut_file_dir):
|
|
|
|
_coconut_full_module_name = str(_coconut_module_name + ".__coconut__")
|
|
|
|
import __coconut__ as _coconut__coconut__
|
|
|
|
_coconut__coconut__.__name__ = _coconut_full_module_name
|
|
|
|
for _coconut_v in vars(_coconut__coconut__).values():
|
|
|
|
if getattr(_coconut_v, "__module__", None) == "__coconut__":
|
|
|
|
try:
|
|
|
|
_coconut_v.__module__ = _coconut_full_module_name
|
|
|
|
except AttributeError:
|
|
|
|
_coconut_v_type = type(_coconut_v)
|
|
|
|
if getattr(_coconut_v_type, "__module__", None) == "__coconut__":
|
|
|
|
_coconut_v_type.__module__ = _coconut_full_module_name
|
|
|
|
_coconut_sys.modules[_coconut_full_module_name] = _coconut__coconut__
|
|
|
|
from __coconut__ import *
|
|
|
|
from __coconut__ import _namedtuple_of, _coconut, _coconut_super, _coconut_MatchError, _coconut_iter_getitem, _coconut_base_compose, _coconut_forward_compose, _coconut_back_compose, _coconut_forward_star_compose, _coconut_back_star_compose, _coconut_forward_dubstar_compose, _coconut_back_dubstar_compose, _coconut_pipe, _coconut_star_pipe, _coconut_dubstar_pipe, _coconut_back_pipe, _coconut_back_star_pipe, _coconut_back_dubstar_pipe, _coconut_none_pipe, _coconut_none_star_pipe, _coconut_none_dubstar_pipe, _coconut_bool_and, _coconut_bool_or, _coconut_none_coalesce, _coconut_minus, _coconut_map, _coconut_partial, _coconut_get_function_match_error, _coconut_base_pattern_func, _coconut_addpattern, _coconut_sentinel, _coconut_assert, _coconut_raise, _coconut_mark_as_match, _coconut_reiterable, _coconut_self_match_types, _coconut_dict_merge, _coconut_exec, _coconut_comma_op, _coconut_multi_dim_arr, _coconut_mk_anon_namedtuple, _coconut_matmul
|
|
|
|
_coconut_sys.path.pop(0)
|
|
|
|
|
|
|
|
# Compiled Coconut: -----------------------------------------------------------
|
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Copyright 2020 Fabien Bourgeois <fabien@yaltik.com>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2022-11-17 15:49:41 +01:00
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
|
|
|
|
import unittest
|
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
from src.xml_base import XMLDictElement
|
|
|
|
import src.odoo_dsl as od
|
|
|
|
|
|
|
|
class TestOdooBase(unittest.TestCase):
|
|
|
|
""" Odoo Helpers tests """
|
|
|
|
|
|
|
|
def test_odoo(self):
|
|
|
|
""" Test odoo function """
|
|
|
|
element = od.odoo([])
|
|
|
|
self.assertIsInstance(element, ET.Element)
|
|
|
|
self.assertEqual(element.tag, 'odoo')
|
|
|
|
|
2022-11-17 15:49:41 +01:00
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
def test_data(self):
|
|
|
|
""" Test data function """
|
|
|
|
element = od.data([])
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'data')
|
|
|
|
self.assertEqual(element.attrs, {})
|
|
|
|
|
|
|
|
element = od.data({"one": "attribute"}, [])
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'data')
|
|
|
|
self.assertEqual(element.attrs, {"one": "attribute"})
|
|
|
|
|
2022-11-17 15:49:41 +01:00
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
def test_aliases(self):
|
|
|
|
""" Test simple aliases to xmln """
|
|
|
|
element = od.record({"one": "attribute"}, 'A child')
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'record')
|
|
|
|
self.assertEqual(element.attrs, {"one": "attribute"})
|
2022-11-17 15:49:41 +01:00
|
|
|
self.assertEqual(element.children, ['A child',])
|
2021-02-22 18:08:11 +01:00
|
|
|
|
|
|
|
element = od.tree()
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'tree')
|
|
|
|
|
2022-11-17 15:49:41 +01:00
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
def test_act_window_model(self):
|
|
|
|
""" Test act_window function """
|
|
|
|
element = od.act_window_model('sample.model', {'view_type': 'form'})
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'act_window')
|
|
|
|
self.assertEqual(element.attrs['view_type'], 'form')
|
|
|
|
self.assertEqual(element.attrs['id'], 'sample_model_view_action')
|
|
|
|
self.assertEqual(element.attrs['res_model'], 'sample.model')
|
|
|
|
self.assertEqual(element.attrs['name'], 'Sample Model Action')
|
|
|
|
|
2022-11-17 15:49:41 +01:00
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
def test_menunitem_model(self):
|
|
|
|
""" Test menuitem function """
|
|
|
|
element = od.menuitem_model('sample.model', {'groups': 'base.user_employee'})
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'menuitem')
|
|
|
|
self.assertEqual(element.attrs['groups'], 'base.user_employee')
|
|
|
|
self.assertEqual(element.attrs['id'], 'sample_model_menu')
|
|
|
|
self.assertEqual(element.attrs['action'], 'sample_model_view_action')
|
|
|
|
|
2022-11-17 15:49:41 +01:00
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
def test_attribute(self):
|
|
|
|
""" Test attribute function """
|
|
|
|
element = od.attribute('invisible', "1")
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'attribute')
|
|
|
|
self.assertEqual(element.attrs['name'], 'invisible')
|
2022-11-17 15:49:41 +01:00
|
|
|
self.assertEqual(element.children, ["1",])
|
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
|
|
|
|
def test_fields(self):
|
|
|
|
""" Test fields function """
|
|
|
|
element = od.field({"one": "attribute"}, 'A child')
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'field')
|
|
|
|
|
|
|
|
element = od.field_name('A name')
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'field')
|
|
|
|
self.assertEqual(element.attrs['name'], 'name')
|
2022-11-17 15:49:41 +01:00
|
|
|
self.assertEqual(element.children, ['A name',])
|
2021-02-22 18:08:11 +01:00
|
|
|
|
|
|
|
element = od.field_model('sample.model')
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'field')
|
|
|
|
self.assertEqual(element.attrs['name'], 'model')
|
2022-11-17 15:49:41 +01:00
|
|
|
self.assertEqual(element.children, ['sample.model',])
|
2021-02-22 18:08:11 +01:00
|
|
|
|
|
|
|
element = od.field_inherit('module.xml_view')
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'field')
|
|
|
|
self.assertEqual(element.attrs['name'], 'inherit_id')
|
|
|
|
self.assertEqual(element.attrs['ref'], 'module.xml_view')
|
|
|
|
self.assertFalse(element.children)
|
|
|
|
|
|
|
|
element = od.field_arch()
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'field')
|
|
|
|
self.assertEqual(element.attrs['name'], 'arch')
|
|
|
|
self.assertEqual(element.attrs['type'], 'xml')
|
|
|
|
self.assertFalse(element.children)
|
|
|
|
|
2022-11-17 15:49:41 +01:00
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
def test_view(self):
|
|
|
|
""" Test view function """
|
|
|
|
element = od.view('view_xmlid', [])
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'record')
|
|
|
|
self.assertEqual(element.attrs['id'], 'view_xmlid')
|
|
|
|
self.assertEqual(element.attrs['model'], 'ir.ui.view')
|
|
|
|
self.assertFalse(element.children)
|
|
|
|
|
2022-11-17 15:49:41 +01:00
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
def test_view_def(self):
|
|
|
|
""" Test view_def function """
|
|
|
|
element = od.view_def('view_xmlid', 'View', 'sample.model', [])
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'record')
|
|
|
|
self.assertEqual(element.attrs['id'], 'view_xmlid')
|
|
|
|
self.assertEqual(element.attrs['model'], 'ir.ui.view')
|
|
|
|
self.assertEqual((len(element.children)), 3)
|
|
|
|
self.assertIsInstance(element.children[0], XMLDictElement)
|
|
|
|
self.assertEqual(element.children[0].tag, 'field')
|
|
|
|
self.assertEqual(element.children[0].attrs['name'], 'name')
|
2022-11-17 15:49:41 +01:00
|
|
|
self.assertEqual(element.children[0].children, ['View',])
|
2021-02-22 18:08:11 +01:00
|
|
|
self.assertIsInstance(element.children[1], XMLDictElement)
|
|
|
|
self.assertEqual(element.children[1].tag, 'field')
|
|
|
|
self.assertEqual(element.children[1].attrs['name'], 'model')
|
2022-11-17 15:49:41 +01:00
|
|
|
self.assertEqual(element.children[1].children, ['sample.model',])
|
2021-02-22 18:08:11 +01:00
|
|
|
self.assertIsInstance(element.children[2], XMLDictElement)
|
|
|
|
self.assertEqual(element.children[2].tag, 'field')
|
|
|
|
self.assertEqual(element.children[2].attrs['name'], 'arch')
|
|
|
|
self.assertEqual(element.children[2].attrs['type'], 'xml')
|
|
|
|
self.assertFalse(element.children[2].children)
|
|
|
|
|
2022-11-17 15:49:41 +01:00
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
def test_view_new(self):
|
|
|
|
""" Test view_new function """
|
|
|
|
element = od.view_new('tree', 'sample.model', [])
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'record')
|
|
|
|
self.assertEqual(element.attrs['id'], 'sample_model_view_tree')
|
|
|
|
self.assertEqual(element.attrs['model'], 'ir.ui.view')
|
|
|
|
self.assertEqual((len(element.children)), 3)
|
|
|
|
self.assertIsInstance(element.children[0], XMLDictElement)
|
|
|
|
self.assertEqual(element.children[0].tag, 'field')
|
|
|
|
self.assertEqual(element.children[0].attrs['name'], 'name')
|
2022-11-17 15:49:41 +01:00
|
|
|
self.assertEqual(element.children[0].children, ['Sample Model Tree',])
|
2021-02-22 18:08:11 +01:00
|
|
|
self.assertIsInstance(element.children[1], XMLDictElement)
|
|
|
|
self.assertEqual(element.children[1].tag, 'field')
|
|
|
|
self.assertEqual(element.children[1].attrs['name'], 'model')
|
2022-11-17 15:49:41 +01:00
|
|
|
self.assertEqual(element.children[1].children, ['sample.model',])
|
2021-02-22 18:08:11 +01:00
|
|
|
self.assertIsInstance(element.children[2], XMLDictElement)
|
|
|
|
self.assertEqual(element.children[2].tag, 'field')
|
|
|
|
self.assertEqual(element.children[2].attrs['name'], 'arch')
|
|
|
|
self.assertEqual(element.children[2].attrs['type'], 'xml')
|
|
|
|
self.assertFalse(element.children[2].children)
|
|
|
|
|
2022-11-17 15:49:41 +01:00
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
def test_view_inherit(self):
|
|
|
|
""" Test view_inherit function """
|
|
|
|
element = od.view_inherit('odoo.addons.module', 'sample.model', 'parent.view', [])
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'record')
|
|
|
|
self.assertEqual(element.attrs['id'], 'view_inherit_module')
|
|
|
|
self.assertEqual(element.attrs['model'], 'ir.ui.view')
|
|
|
|
self.assertEqual((len(element.children)), 4)
|
|
|
|
self.assertIsInstance(element.children[0], XMLDictElement)
|
|
|
|
self.assertEqual(element.children[0].tag, 'field')
|
|
|
|
self.assertEqual(element.children[0].attrs['name'], 'name')
|
2022-11-17 15:49:41 +01:00
|
|
|
self.assertEqual(element.children[0].children, ['Sample Model Adaptations',])
|
2021-02-22 18:08:11 +01:00
|
|
|
self.assertIsInstance(element.children[1], XMLDictElement)
|
|
|
|
self.assertEqual(element.children[1].tag, 'field')
|
|
|
|
self.assertEqual(element.children[1].attrs['name'], 'model')
|
2022-11-17 15:49:41 +01:00
|
|
|
self.assertEqual(element.children[1].children, ['sample.model',])
|
2021-02-22 18:08:11 +01:00
|
|
|
self.assertIsInstance(element.children[2], XMLDictElement)
|
|
|
|
self.assertEqual(element.children[2].tag, 'field')
|
|
|
|
self.assertEqual(element.children[2].attrs['name'], 'inherit_id')
|
|
|
|
self.assertFalse(element.children[2].children)
|
|
|
|
self.assertIsInstance(element.children[3], XMLDictElement)
|
|
|
|
self.assertEqual(element.children[3].tag, 'field')
|
|
|
|
self.assertEqual(element.children[3].attrs['name'], 'arch')
|
|
|
|
self.assertEqual(element.children[3].attrs['type'], 'xml')
|
|
|
|
self.assertFalse(element.children[3].children)
|
|
|
|
|
2022-11-17 15:49:41 +01:00
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
def test_action_server_code(self):
|
|
|
|
""" Test action_server_code function """
|
2022-11-17 15:49:41 +01:00
|
|
|
element = od.action_server_code('sample.xmlid', 'Code', 'sample.model', '''record.do_something()''')
|
2021-02-22 18:08:11 +01:00
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'record')
|
|
|
|
self.assertEqual(element.attrs['id'], 'sample.xmlid')
|
|
|
|
self.assertEqual(element.attrs['model'], 'ir.actions.server')
|
|
|
|
self.assertEqual((len(element.children)), 4)
|
|
|
|
self.assertIsInstance(element.children[0], XMLDictElement)
|
|
|
|
self.assertEqual(element.children[0].tag, 'field')
|
|
|
|
self.assertEqual(element.children[0].attrs['name'], 'name')
|
2022-11-17 15:49:41 +01:00
|
|
|
self.assertEqual(element.children[0].children, ['Code',])
|
2021-02-22 18:08:11 +01:00
|
|
|
self.assertIsInstance(element.children[1], XMLDictElement)
|
|
|
|
self.assertEqual(element.children[1].tag, 'field')
|
|
|
|
self.assertEqual(element.children[1].attrs['name'], 'model_id')
|
|
|
|
self.assertEqual(element.children[1].attrs['ref'], 'sample.model')
|
|
|
|
self.assertFalse(element.children[1].children)
|
|
|
|
self.assertEqual(element.children[2].tag, 'field')
|
|
|
|
self.assertEqual(element.children[2].attrs['name'], 'state')
|
2022-11-17 15:49:41 +01:00
|
|
|
self.assertEqual(element.children[2].children, ['code',])
|
2021-02-22 18:08:11 +01:00
|
|
|
self.assertEqual(element.children[3].tag, 'field')
|
|
|
|
self.assertEqual(element.children[3].attrs['name'], 'code')
|
2022-11-17 15:49:41 +01:00
|
|
|
self.assertEqual(element.children[3].children, ['record.do_something()',])
|
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
|
|
|
|
def test_client_action_multi(self):
|
|
|
|
""" Test client_action_multi function """
|
|
|
|
element = od.client_action_multi('sample.xmlid', 'Multi', 'sample.model', 'sample.action')
|
|
|
|
self.assertIsInstance(element, XMLDictElement)
|
|
|
|
self.assertEqual(element.tag, 'record')
|
|
|
|
self.assertEqual(element.attrs['id'], 'sample.xmlid')
|
|
|
|
self.assertEqual(element.attrs['model'], 'ir.values')
|
|
|
|
self.assertEqual((len(element.children)), 4)
|
|
|
|
self.assertIsInstance(element.children[0], XMLDictElement)
|
|
|
|
self.assertEqual(element.children[0].tag, 'field')
|
|
|
|
self.assertEqual(element.children[0].attrs['name'], 'name')
|
2022-11-17 15:49:41 +01:00
|
|
|
self.assertEqual(element.children[0].children, ['Multi',])
|
2021-02-22 18:08:11 +01:00
|
|
|
self.assertIsInstance(element.children[1], XMLDictElement)
|
|
|
|
self.assertEqual(element.children[1].tag, 'field')
|
|
|
|
self.assertEqual(element.children[1].attrs['name'], 'key2')
|
|
|
|
self.assertEqual(element.children[1].attrs['eval'], "'client_action_multi'")
|
|
|
|
self.assertFalse(element.children[1].children)
|
|
|
|
self.assertEqual(element.children[2].tag, 'field')
|
|
|
|
self.assertEqual(element.children[2].attrs['name'], 'model')
|
|
|
|
self.assertEqual(element.children[2].attrs['eval'], "'sample.model'")
|
|
|
|
self.assertEqual(element.children[3].tag, 'field')
|
|
|
|
self.assertEqual(element.children[3].attrs['name'], 'value')
|
|
|
|
self.assertEqual(element.children[3].attrs['eval'], "'ir.actions.server,%d'%sample.action")
|
|
|
|
|
|
|
|
|
2022-11-17 15:49:41 +01:00
|
|
|
|
2021-02-22 18:08:11 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|