yaltik_odoo_custom/yaltik_dsl/test_odoo.coco

236 lines
12 KiB
Plaintext

# -*- 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/>.
""" Odoo Helpers tests """
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([])
element `self.assertIsInstance` ET.Element
element.tag `self.assertEquals` 'odoo'
def test_data(self):
element = od.data([])
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'data'
element.attrs `self.assertEquals` {}
element = od.data({"one": "attribute"}, [])
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'data'
element.attrs `self.assertEquals` {"one": "attribute"}
def test_aliases(self):
""" Test simple aliases to xmln """
element = od.record({"one": "attribute"}, 'A child')
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'record'
element.attrs `self.assertEquals` {"one": "attribute"}
element.children `self.assertEquals` ['A child']
element = od.tree()
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'tree'
def test_act_window_model(self):
element = ('sample.model', {'view_type': 'form'}) |*> od.act_window_model
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'act_window'
element.attrs['view_type'] `self.assertEquals` 'form'
element.attrs['id'] `self.assertEquals` 'sample_model_view_action'
element.attrs['res_model'] `self.assertEquals` 'sample.model'
element.attrs['name'] `self.assertEquals` 'Sample Model Action'
def test_menunitem_model(self):
element = ('sample.model', {'groups': 'base.user_employee'}) |*> od.menuitem_model
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'menuitem'
element.attrs['groups'] `self.assertEquals` 'base.user_employee'
element.attrs['id'] `self.assertEquals` 'sample_model_menu'
element.attrs['action'] `self.assertEquals` 'sample_model_view_action'
def test_attribute(self):
element = od.attribute('invisible', "1")
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'attribute'
element.attrs['name'] `self.assertEquals` 'invisible'
element.children `self.assertEquals` ["1"]
def test_fields(self):
element = od.field({"one": "attribute"}, 'A child')
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'field'
element = 'A name' |> od.field_name
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'field'
element.attrs['name'] `self.assertEquals` 'name'
element.children `self.assertEquals` ['A name']
element = 'sample.model' |> od.field_model
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'field'
element.attrs['name'] `self.assertEquals` 'model'
element.children `self.assertEquals` ['sample.model']
element = 'module.xml_view' |> od.field_inherit
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'field'
element.attrs['name'] `self.assertEquals` 'inherit_id'
element.attrs['ref'] `self.assertEquals` 'module.xml_view'
element.children |> self.assertFalse
element = od.field_arch()
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'field'
element.attrs['name'] `self.assertEquals` 'arch'
element.attrs['type'] `self.assertEquals` 'xml'
element.children |> self.assertFalse
def test_view(self):
element = od.view('view_xmlid', [])
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'record'
element.attrs['id'] `self.assertEquals` 'view_xmlid'
element.attrs['model'] `self.assertEquals` 'ir.ui.view'
element.children |> self.assertFalse
def test_view_def(self):
element = od.view_def('view_xmlid', 'View', 'sample.model', [])
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'record'
element.attrs['id'] `self.assertEquals` 'view_xmlid'
element.attrs['model'] `self.assertEquals` 'ir.ui.view'
(element.children |> len) `self.assertEquals` 3
element.children[0] `self.assertIsInstance` XMLDictElement
element.children[0].tag `self.assertEquals` 'field'
element.children[0].attrs['name'] `self.assertEquals` 'name'
element.children[0].children `self.assertEquals` ['View']
element.children[1] `self.assertIsInstance` XMLDictElement
element.children[1].tag `self.assertEquals` 'field'
element.children[1].attrs['name'] `self.assertEquals` 'model'
element.children[1].children `self.assertEquals` ['sample.model']
element.children[2] `self.assertIsInstance` XMLDictElement
element.children[2].tag `self.assertEquals` 'field'
element.children[2].attrs['name'] `self.assertEquals` 'arch'
element.children[2].attrs['type'] `self.assertEquals` 'xml'
element.children[2].children |> self.assertFalse
def test_view_new(self):
element = od.view_new('tree', 'sample.model', [])
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'record'
element.attrs['id'] `self.assertEquals` 'sample_model_view_tree'
element.attrs['model'] `self.assertEquals` 'ir.ui.view'
(element.children |> len) `self.assertEquals` 3
element.children[0] `self.assertIsInstance` XMLDictElement
element.children[0].tag `self.assertEquals` 'field'
element.children[0].attrs['name'] `self.assertEquals` 'name'
element.children[0].children `self.assertEquals` ['Sample Model Tree']
element.children[1] `self.assertIsInstance` XMLDictElement
element.children[1].tag `self.assertEquals` 'field'
element.children[1].attrs['name'] `self.assertEquals` 'model'
element.children[1].children `self.assertEquals` ['sample.model']
element.children[2] `self.assertIsInstance` XMLDictElement
element.children[2].tag `self.assertEquals` 'field'
element.children[2].attrs['name'] `self.assertEquals` 'arch'
element.children[2].attrs['type'] `self.assertEquals` 'xml'
element.children[2].children |> self.assertFalse
def test_view_inherit(self):
element = od.view_inherit('odoo.addons.module', 'sample.model', 'parent.view', [])
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'record'
element.attrs['id'] `self.assertEquals` 'view_inherit_module'
element.attrs['model'] `self.assertEquals` 'ir.ui.view'
(element.children |> len) `self.assertEquals` 4
element.children[0] `self.assertIsInstance` XMLDictElement
element.children[0].tag `self.assertEquals` 'field'
element.children[0].attrs['name'] `self.assertEquals` 'name'
element.children[0].children `self.assertEquals` ['Sample Model Adaptations']
element.children[1] `self.assertIsInstance` XMLDictElement
element.children[1].tag `self.assertEquals` 'field'
element.children[1].attrs['name'] `self.assertEquals` 'model'
element.children[1].children `self.assertEquals` ['sample.model']
element.children[2] `self.assertIsInstance` XMLDictElement
element.children[2].tag `self.assertEquals` 'field'
element.children[2].attrs['name'] `self.assertEquals` 'inherit_id'
element.children[2].children |> self.assertFalse
element.children[3] `self.assertIsInstance` XMLDictElement
element.children[3].tag `self.assertEquals` 'field'
element.children[3].attrs['name'] `self.assertEquals` 'arch'
element.children[3].attrs['type'] `self.assertEquals` 'xml'
element.children[3].children |> self.assertFalse
def test_action_server_code(self):
element = od.action_server_code('sample.xmlid', 'Code', 'sample.model',
'''record.do_something()''')
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'record'
element.attrs['id'] `self.assertEquals` 'sample.xmlid'
element.attrs['model'] `self.assertEquals` 'ir.actions.server'
(element.children |> len) `self.assertEquals` 4
element.children[0] `self.assertIsInstance` XMLDictElement
element.children[0].tag `self.assertEquals` 'field'
element.children[0].attrs['name'] `self.assertEquals` 'name'
element.children[0].children `self.assertEquals` ['Code']
element.children[1] `self.assertIsInstance` XMLDictElement
element.children[1].tag `self.assertEquals` 'field'
element.children[1].attrs['name'] `self.assertEquals` 'model_id'
element.children[1].attrs['ref'] `self.assertEquals` 'sample.model'
element.children[1].children |> self.assertFalse
element.children[2].tag `self.assertEquals` 'field'
element.children[2].attrs['name'] `self.assertEquals` 'state'
element.children[2].children `self.assertEquals` ['code']
element.children[3].tag `self.assertEquals` 'field'
element.children[3].attrs['name'] `self.assertEquals` 'code'
element.children[3].children `self.assertEquals` ['record.do_something()']
def test_client_action_multi(self):
element = od.client_action_multi('sample.xmlid', 'Multi', 'sample.model', 'sample.action')
element `self.assertIsInstance` XMLDictElement
element.tag `self.assertEquals` 'record'
element.attrs['id'] `self.assertEquals` 'sample.xmlid'
element.attrs['model'] `self.assertEquals` 'ir.values'
(element.children |> len) `self.assertEquals` 4
element.children[0] `self.assertIsInstance` XMLDictElement
element.children[0].tag `self.assertEquals` 'field'
element.children[0].attrs['name'] `self.assertEquals` 'name'
element.children[0].children `self.assertEquals` ['Multi']
element.children[1] `self.assertIsInstance` XMLDictElement
element.children[1].tag `self.assertEquals` 'field'
element.children[1].attrs['name'] `self.assertEquals` 'key2'
element.children[1].attrs['eval'] `self.assertEquals` "'client_action_multi'"
element.children[1].children |> self.assertFalse
element.children[2].tag `self.assertEquals` 'field'
element.children[2].attrs['name'] `self.assertEquals` 'model'
element.children[2].attrs['eval'] `self.assertEquals` "'sample.model'"
element.children[3].tag `self.assertEquals` 'field'
element.children[3].attrs['name'] `self.assertEquals` 'value'
element.children[3].attrs['eval'] `self.assertEquals` "'ir.actions.server,%d'%sample.action"
if __name__ == '__main__':
unittest.main()