yaltik_odoo_custom/yaltik_dsl/test_odoo.coco

143 lines
6.2 KiB
Plaintext
Raw Normal View History

# -*- 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_views(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
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_actions(self): pass
if __name__ == '__main__':
unittest.main()