258 lines
14 KiB
Python
258 lines
14 KiB
Python
#!/usr/bin/env python2
|
|
# -*- coding: utf-8 -*-
|
|
# __coconut_hash__ = 0xdf0c086d
|
|
|
|
# Compiled with Coconut version 1.4.3 [Ernest Scribbler]
|
|
|
|
""" Odoo Helpers tests """
|
|
|
|
# Coconut Header: -------------------------------------------------------------
|
|
|
|
from __future__ import print_function, absolute_import, unicode_literals, division
|
|
import sys as _coconut_sys, os.path as _coconut_os_path
|
|
_coconut_file_path = _coconut_os_path.dirname(_coconut_os_path.abspath(__file__))
|
|
_coconut_cached_module = _coconut_sys.modules.get(b"__coconut__")
|
|
if _coconut_cached_module is not None and _coconut_os_path.dirname(_coconut_cached_module.__file__) != _coconut_file_path:
|
|
del _coconut_sys.modules[b"__coconut__"]
|
|
_coconut_sys.path.insert(0, _coconut_file_path)
|
|
from __coconut__ import *
|
|
from __coconut__ import _coconut, _coconut_MatchError, _coconut_igetitem, _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_back_pipe, _coconut_star_pipe, _coconut_back_star_pipe, _coconut_dubstar_pipe, _coconut_back_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_mark_as_match
|
|
|
|
|
|
# Compiled Coconut: -----------------------------------------------------------
|
|
|
|
# -*- 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/>.
|
|
|
|
|
|
|
|
import unittest
|
|
import xml.etree.ElementTree as ET
|
|
from xml_base import XMLDictElement
|
|
import odoo_dsl as od
|
|
|
|
class TestOdooBase(unittest.TestCase):
|
|
""" Odoo Helpers tests """
|
|
|
|
def test_odoo(self):
|
|
element = od.odoo([])
|
|
(self.assertIsInstance)(element, ET.Element)
|
|
(self.assertEquals)(element.tag, 'odoo')
|
|
|
|
def test_data(self):
|
|
element = od.data([])
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'data')
|
|
(self.assertEquals)(element.attrs, {})
|
|
|
|
element = od.data({"one": "attribute"}, [])
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'data')
|
|
(self.assertEquals)(element.attrs, {"one": "attribute"})
|
|
|
|
def test_aliases(self):
|
|
""" Test simple aliases to xmln """
|
|
element = od.record({"one": "attribute"}, 'A child')
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'record')
|
|
(self.assertEquals)(element.attrs, {"one": "attribute"})
|
|
(self.assertEquals)(element.children, ['A child'])
|
|
|
|
element = od.tree()
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'tree')
|
|
|
|
def test_act_window_model(self):
|
|
element = (od.act_window_model)(*('sample.model', {'view_type': 'form'}))
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'act_window')
|
|
(self.assertEquals)(element.attrs['view_type'], 'form')
|
|
(self.assertEquals)(element.attrs['id'], 'sample_model_view_action')
|
|
(self.assertEquals)(element.attrs['res_model'], 'sample.model')
|
|
(self.assertEquals)(element.attrs['name'], 'Sample Model Action')
|
|
|
|
def test_menunitem_model(self):
|
|
element = (od.menuitem_model)(*('sample.model', {'groups': 'base.user_employee'}))
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'menuitem')
|
|
(self.assertEquals)(element.attrs['groups'], 'base.user_employee')
|
|
(self.assertEquals)(element.attrs['id'], 'sample_model_menu')
|
|
(self.assertEquals)(element.attrs['action'], 'sample_model_view_action')
|
|
|
|
def test_attribute(self):
|
|
element = od.attribute('invisible', "1")
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'attribute')
|
|
(self.assertEquals)(element.attrs['name'], 'invisible')
|
|
(self.assertEquals)(element.children, ["1"])
|
|
|
|
def test_fields(self):
|
|
element = od.field({"one": "attribute"}, 'A child')
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'field')
|
|
|
|
element = (od.field_name)('A name')
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'field')
|
|
(self.assertEquals)(element.attrs['name'], 'name')
|
|
(self.assertEquals)(element.children, ['A name'])
|
|
|
|
element = (od.field_model)('sample.model')
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'field')
|
|
(self.assertEquals)(element.attrs['name'], 'model')
|
|
(self.assertEquals)(element.children, ['sample.model'])
|
|
|
|
element = (od.field_inherit)('module.xml_view')
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'field')
|
|
(self.assertEquals)(element.attrs['name'], 'inherit_id')
|
|
(self.assertEquals)(element.attrs['ref'], 'module.xml_view')
|
|
(self.assertFalse)(element.children)
|
|
|
|
element = od.field_arch()
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'field')
|
|
(self.assertEquals)(element.attrs['name'], 'arch')
|
|
(self.assertEquals)(element.attrs['type'], 'xml')
|
|
(self.assertFalse)(element.children)
|
|
|
|
def test_view(self):
|
|
element = od.view('view_xmlid', [])
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'record')
|
|
(self.assertEquals)(element.attrs['id'], 'view_xmlid')
|
|
(self.assertEquals)(element.attrs['model'], 'ir.ui.view')
|
|
(self.assertFalse)(element.children)
|
|
|
|
def test_view_def(self):
|
|
element = od.view_def('view_xmlid', 'View', 'sample.model', [])
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'record')
|
|
(self.assertEquals)(element.attrs['id'], 'view_xmlid')
|
|
(self.assertEquals)(element.attrs['model'], 'ir.ui.view')
|
|
(self.assertEquals)(((len)(element.children)), 3)
|
|
(self.assertIsInstance)(element.children[0], XMLDictElement)
|
|
(self.assertEquals)(element.children[0].tag, 'field')
|
|
(self.assertEquals)(element.children[0].attrs['name'], 'name')
|
|
(self.assertEquals)(element.children[0].children, ['View'])
|
|
(self.assertIsInstance)(element.children[1], XMLDictElement)
|
|
(self.assertEquals)(element.children[1].tag, 'field')
|
|
(self.assertEquals)(element.children[1].attrs['name'], 'model')
|
|
(self.assertEquals)(element.children[1].children, ['sample.model'])
|
|
(self.assertIsInstance)(element.children[2], XMLDictElement)
|
|
(self.assertEquals)(element.children[2].tag, 'field')
|
|
(self.assertEquals)(element.children[2].attrs['name'], 'arch')
|
|
(self.assertEquals)(element.children[2].attrs['type'], 'xml')
|
|
(self.assertFalse)(element.children[2].children)
|
|
|
|
def test_view_new(self):
|
|
element = od.view_new('tree', 'sample.model', [])
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'record')
|
|
(self.assertEquals)(element.attrs['id'], 'sample_model_view_tree')
|
|
(self.assertEquals)(element.attrs['model'], 'ir.ui.view')
|
|
(self.assertEquals)(((len)(element.children)), 3)
|
|
(self.assertIsInstance)(element.children[0], XMLDictElement)
|
|
(self.assertEquals)(element.children[0].tag, 'field')
|
|
(self.assertEquals)(element.children[0].attrs['name'], 'name')
|
|
(self.assertEquals)(element.children[0].children, ['Sample Model Tree'])
|
|
(self.assertIsInstance)(element.children[1], XMLDictElement)
|
|
(self.assertEquals)(element.children[1].tag, 'field')
|
|
(self.assertEquals)(element.children[1].attrs['name'], 'model')
|
|
(self.assertEquals)(element.children[1].children, ['sample.model'])
|
|
(self.assertIsInstance)(element.children[2], XMLDictElement)
|
|
(self.assertEquals)(element.children[2].tag, 'field')
|
|
(self.assertEquals)(element.children[2].attrs['name'], 'arch')
|
|
(self.assertEquals)(element.children[2].attrs['type'], 'xml')
|
|
(self.assertFalse)(element.children[2].children)
|
|
|
|
def test_view_inherit(self):
|
|
element = od.view_inherit('odoo.addons.module', 'sample.model', 'parent.view', [])
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'record')
|
|
(self.assertEquals)(element.attrs['id'], 'view_inherit_module')
|
|
(self.assertEquals)(element.attrs['model'], 'ir.ui.view')
|
|
(self.assertEquals)(((len)(element.children)), 4)
|
|
(self.assertIsInstance)(element.children[0], XMLDictElement)
|
|
(self.assertEquals)(element.children[0].tag, 'field')
|
|
(self.assertEquals)(element.children[0].attrs['name'], 'name')
|
|
(self.assertEquals)(element.children[0].children, ['Sample Model Adaptations'])
|
|
(self.assertIsInstance)(element.children[1], XMLDictElement)
|
|
(self.assertEquals)(element.children[1].tag, 'field')
|
|
(self.assertEquals)(element.children[1].attrs['name'], 'model')
|
|
(self.assertEquals)(element.children[1].children, ['sample.model'])
|
|
(self.assertIsInstance)(element.children[2], XMLDictElement)
|
|
(self.assertEquals)(element.children[2].tag, 'field')
|
|
(self.assertEquals)(element.children[2].attrs['name'], 'inherit_id')
|
|
(self.assertFalse)(element.children[2].children)
|
|
(self.assertIsInstance)(element.children[3], XMLDictElement)
|
|
(self.assertEquals)(element.children[3].tag, 'field')
|
|
(self.assertEquals)(element.children[3].attrs['name'], 'arch')
|
|
(self.assertEquals)(element.children[3].attrs['type'], 'xml')
|
|
(self.assertFalse)(element.children[3].children)
|
|
|
|
def test_action_server_code(self):
|
|
element = od.action_server_code('sample.xmlid', 'Code', 'sample.model', '''record.do_something()''')
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'record')
|
|
(self.assertEquals)(element.attrs['id'], 'sample.xmlid')
|
|
(self.assertEquals)(element.attrs['model'], 'ir.actions.server')
|
|
(self.assertEquals)(((len)(element.children)), 4)
|
|
(self.assertIsInstance)(element.children[0], XMLDictElement)
|
|
(self.assertEquals)(element.children[0].tag, 'field')
|
|
(self.assertEquals)(element.children[0].attrs['name'], 'name')
|
|
(self.assertEquals)(element.children[0].children, ['Code'])
|
|
(self.assertIsInstance)(element.children[1], XMLDictElement)
|
|
(self.assertEquals)(element.children[1].tag, 'field')
|
|
(self.assertEquals)(element.children[1].attrs['name'], 'model_id')
|
|
(self.assertEquals)(element.children[1].attrs['ref'], 'sample.model')
|
|
(self.assertFalse)(element.children[1].children)
|
|
(self.assertEquals)(element.children[2].tag, 'field')
|
|
(self.assertEquals)(element.children[2].attrs['name'], 'state')
|
|
(self.assertEquals)(element.children[2].children, ['code'])
|
|
(self.assertEquals)(element.children[3].tag, 'field')
|
|
(self.assertEquals)(element.children[3].attrs['name'], 'code')
|
|
(self.assertEquals)(element.children[3].children, ['record.do_something()'])
|
|
|
|
def test_client_action_multi(self):
|
|
element = od.client_action_multi('sample.xmlid', 'Multi', 'sample.model', 'sample.action')
|
|
(self.assertIsInstance)(element, XMLDictElement)
|
|
(self.assertEquals)(element.tag, 'record')
|
|
(self.assertEquals)(element.attrs['id'], 'sample.xmlid')
|
|
(self.assertEquals)(element.attrs['model'], 'ir.values')
|
|
(self.assertEquals)(((len)(element.children)), 4)
|
|
(self.assertIsInstance)(element.children[0], XMLDictElement)
|
|
(self.assertEquals)(element.children[0].tag, 'field')
|
|
(self.assertEquals)(element.children[0].attrs['name'], 'name')
|
|
(self.assertEquals)(element.children[0].children, ['Multi'])
|
|
(self.assertIsInstance)(element.children[1], XMLDictElement)
|
|
(self.assertEquals)(element.children[1].tag, 'field')
|
|
(self.assertEquals)(element.children[1].attrs['name'], 'key2')
|
|
(self.assertEquals)(element.children[1].attrs['eval'], "'client_action_multi'")
|
|
(self.assertFalse)(element.children[1].children)
|
|
(self.assertEquals)(element.children[2].tag, 'field')
|
|
(self.assertEquals)(element.children[2].attrs['name'], 'model')
|
|
(self.assertEquals)(element.children[2].attrs['eval'], "'sample.model'")
|
|
(self.assertEquals)(element.children[3].tag, 'field')
|
|
(self.assertEquals)(element.children[3].attrs['name'], 'value')
|
|
(self.assertEquals)(element.children[3].attrs['eval'], "'ir.actions.server,%d'%sample.action")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|