[WIP][BROKEN]Yaltik DSL : no ported yet from coco

This commit is contained in:
Fabien BOURGEOIS 2020-05-03 12:32:01 +02:00
parent 143492e58b
commit 9fa300f77e
2 changed files with 232 additions and 356 deletions

View File

@ -1,26 +1,3 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# __coconut_hash__ = 0xb0af9f53
# Compiled with Coconut version 1.4.3 [Ernest Scribbler]
""" Odoo XML DSL """
# 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 -*- # -*- coding: utf-8 -*-
# #
# Copyright 2019-2020 Fabien Bourgeois <fabien@yaltik.com> # Copyright 2019-2020 Fabien Bourgeois <fabien@yaltik.com>
@ -38,192 +15,113 @@ from __coconut__ import _coconut, _coconut_MatchError, _coconut_igetitem, _cocon
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
""" Odoo XML DSL """
from typing import Text, Dict
from typing import Text from xml_base import XMLAttrs, XMLDictElement, xmlroot, xmln
from typing import Dict
from xml_base import XMLAttrs
from xml_base import XMLDictElement
from xml_base import xmlroot
from xml_base import xmln
# XML helpers functions and macros # XML helpers functions and macros
# Odoo root XML Node # Odoo root XML Node
def odoo(children # type: Dict def odoo(children: Dict) -> ET.Element = {'tag': 'odoo', 'attrs': {}, 'children': children} |> xmlroot
):
# type: (...) -> ET.Element
return (xmlroot)({'tag': 'odoo', 'attrs': {}, 'children': children})
# Special data Node # Special data Node
def data(*args): def data(*args):
""" Allow optional args on data tag """ """ Allow optional args on data tag """
if (len)(args) == 1: if args |> len == 1:
args = (list)(args) {} |> args.insert$(0) where: args = args |> list
args.insert(0, {})
return xmln('data', *args) return xmln('data', *args)
# Aliases # Aliases
def function(*args): def function(*args) -> XMLDictElement = xmln('function', *args)
# type: (...) -> XMLDictElement def record(*args) -> XMLDictElement = xmln('record', *args)
return xmln('function', *args) def form(*args) -> XMLDictElement = xmln('form', *args)
def record(*args): def tree(*args) -> XMLDictElement = xmln('tree', *args)
# type: (...) -> XMLDictElement def search(*args) -> XMLDictElement = xmln('search', *args)
return xmln('record', *args)
def form(*args):
# type: (...) -> XMLDictElement
return xmln('form', *args)
def tree(*args):
# type: (...) -> XMLDictElement
return xmln('tree', *args)
def search(*args):
# type: (...) -> XMLDictElement
return xmln('search', *args)
# Actions # Actions
def act_window(*args): def act_window(*args) -> XMLDictElement = xmln('act_window', *args)
# type: (...) -> XMLDictElement def act_window_model(model: Text, attrs: XMLAttrs) -> XMLDictElement:
return xmln('act_window', *args)
def act_window_model(model, # type: Text
attrs # type: XMLAttrs
):
# type: (...) -> XMLDictElement
""" Build new act_window from model and args """ """ Build new act_window from model and args """
xmlid = '%s_view_action' % ((model.replace)(*('.', '_'))) xmlid = '%s_view_action' % (('.', '_') |*> model.replace)
name = '%s Action' % ((' '.join)((list)(map(lambda _=None: _.capitalize(), (model.split)('.'))))) name = '%s Action' % ('.' |> model.split |> map$(-> _.capitalize()) |> list |> ' '.join)
attrs_clone = attrs.copy() # Avoid side-effect attrs_clone = attrs.copy() # Avoid side-effect
(attrs_clone.update)({'id': xmlid, 'name': name, 'res_model': model}) {'id': xmlid, 'name': name, 'res_model': model} |> attrs_clone.update
return act_window(attrs_clone) return act_window(attrs_clone)
def action_server_code(xmlid, # type: Text def action_server_code(xmlid: Text, name: Text, modelref: Text, code: Text) -> XMLDictElement:
name, # type: Text
modelref, # type: Text
code # type: Text
):
# type: (...) -> XMLDictElement
""" Server actions of type code """ """ Server actions of type code """
children = [(field_name)(name), (field)(*({'name': 'model_id', 'ref': modelref}, [])), (field)(*({'name': 'state'}, ['code'])), (field)(*({'name': 'code'}, [code]))] children = [name |> field_name,
return (record)(*({'id': xmlid, 'model': 'ir.actions.server'}, children)) ({'name': 'model_id', 'ref': modelref}, []) |*> field,
({'name': 'state'}, ['code']) |*> field,
({'name': 'code'}, [code]) |*> field]
return ({'id': xmlid, 'model': 'ir.actions.server'}, children) |*> record
def client_action_multi(xmlid, # type: Text def client_action_multi(xmlid: Text, name: Text, model: Text, action: Text) -> XMLDictElement:
name, # type: Text
model, # type: Text
action # type: Text
):
# type: (...) -> XMLDictElement
""" Client action multi (ir.values), with own xmlid, name, targeted model """ Client action multi (ir.values), with own xmlid, name, targeted model
and action """ and action """
action = ("'ir.actions.server,%d'%{}".format)(action) action = action |> "'ir.actions.server,%d'%{}".format
children = [(field_name)(name), (field)({'name': 'key2', 'eval': "'client_action_multi'"}), (field)({'name': 'model', 'eval': "'%s'" % model}), (field)({'name': 'value', 'eval': action})] children = [name |> field_name,
return (record)(*({'id': xmlid, 'model': 'ir.values'}, children)) {'name': 'key2', 'eval': "'client_action_multi'"} |> field,
{'name': 'model', 'eval': "'%s'" % model} |> field,
{'name': 'value', 'eval': action} |> field]
return ({'id': xmlid, 'model': 'ir.values'}, children) |*> record
# Menus # Menus
def menuitem(*args): def menuitem(*args) -> XMLDictElement = xmln('menuitem', *args)
# type: (...) -> XMLDictElement def menuitem_model(model: Text, attrs: XMLAttrs) -> XMLDictElement:
return xmln('menuitem', *args)
def menuitem_model(model, # type: Text
attrs # type: XMLAttrs
):
# type: (...) -> XMLDictElement
""" Build new menuitem from model and attrs """ """ Build new menuitem from model and attrs """
model_und = (model.replace)(*('.', '_')) model_und = ('.', '_') |*> model.replace
xmlid = '%s_menu' % model_und xmlid = '%s_menu' % model_und
actionid = '%s_view_action' % model_und actionid = '%s_view_action' % model_und
attrs_clone = attrs.copy() # Avoid side-effect attrs_clone = attrs.copy() # Avoid side-effect
(attrs_clone.update)({'id': xmlid, 'action': actionid}) {'id': xmlid, 'action': actionid} |> attrs_clone.update
return menuitem(attrs_clone) return menuitem(attrs_clone)
# Form aliases # Form aliases
def group(*args): def group(*args) -> XMLDictElement = xmln('group', *args)
# type: (...) -> XMLDictElement def header(*args) -> XMLDictElement = xmln('header', *args)
return xmln('group', *args) def footer(*args) -> XMLDictElement = xmln('footer', *args)
def header(*args): def sheet(*args) -> XMLDictElement = xmln('sheet', *args)
# type: (...) -> XMLDictElement def button(*args) -> XMLDictElement = xmln('button', *args)
return xmln('header', *args) def p(*args) -> XMLDictElement = xmln('p', *args)
def footer(*args): def xpath(*args) -> XMLDictElement = xmln('xpath', *args)
# type: (...) -> XMLDictElement def attribute(name: Text, value: Text) -> XMLDictElement:
return xmln('footer', *args) return ('attribute', {'name': name}, [value]) |*> xmln
def sheet(*args):
# type: (...) -> XMLDictElement
return xmln('sheet', *args)
def button(*args):
# type: (...) -> XMLDictElement
return xmln('button', *args)
def p(*args):
# type: (...) -> XMLDictElement
return xmln('p', *args)
def xpath(*args):
# type: (...) -> XMLDictElement
return xmln('xpath', *args)
def attribute(name, # type: Text
value # type: Text
):
# type: (...) -> XMLDictElement
return (xmln)(*('attribute', {'name': name}, [value]))
# Fields # Fields
def field(*args): def field(*args) -> XMLDictElement = xmln('field', *args)
# type: (...) -> XMLDictElement def field_name(name: Text) -> XMLDictElement = ({'name': 'name'}, [name]) |*> field
return xmln('field', *args) def field_model(model: Text) -> XMLDictElement = ({'name': 'model'}, [model]) |*> field
def field_name(name # type: Text def field_inherit(xmlid: Text) -> XMLDictElement:
): return ({'name': 'inherit_id', 'ref': xmlid}, []) |*> field
# type: (...) -> XMLDictElement def field_arch(*args) -> XMLDictElement = {'name': 'arch', 'type': 'xml'} |> field$ <*| args
return (field)(*({'name': 'name'}, [name]))
def field_model(model # type: Text
):
# type: (...) -> XMLDictElement
return (field)(*({'name': 'model'}, [model]))
def field_inherit(xmlid # type: Text
):
# type: (...) -> XMLDictElement
return (field)(*({'name': 'inherit_id', 'ref': xmlid}, []))
def field_arch(*args):
# type: (...) -> XMLDictElement
return ((_coconut.functools.partial(_coconut.functools.partial, field))({'name': 'arch', 'type': 'xml'}))(*args)
# Search # Search
def filter(*args): def filter(*args) -> XMLDictElement = xmln('filter', *args)
# type: (...) -> XMLDictElement
return xmln('filter', *args)
# Views # Views
def view(xmlid, # type: Text def view(xmlid: Text, children: List) -> XMLDictElement:
children # type: List return ({'id': xmlid, 'model': 'ir.ui.view'}, children) |*> record
):
# type: (...) -> XMLDictElement
return (record)(*({'id': xmlid, 'model': 'ir.ui.view'}, children))
def view_def(xmlid, # type: Text def view_def(xmlid: Text, name: Text, model: Text, arch: List) -> XMLDictElement:
name, # type: Text return (xmlid, [field_name(name), field_model(model), field_arch(arch)]) |*> view
model, # type: Text
arch # type: List
):
# type: (...) -> XMLDictElement
return (view)(*(xmlid, [field_name(name), field_model(model), field_arch(arch)]))
def view_new(view_type, # type: Text def view_new(view_type: Text, model: Text, arch: List) -> XMLDictElement:
model, # type: Text
arch # type: List
):
# type: (...) -> XMLDictElement
""" View : new view definition, based on type (form, tree, ...) and model ID """ """ View : new view definition, based on type (form, tree, ...) and model ID """
model_und = (model.replace)(*('.', '_')) model_und = ('.', '_') |*> model.replace
model_cap = ((' '.join)((list)(map(lambda _=None: _.capitalize(), (model.split)('.'))))) model_cap = ('.' |> model.split |> map$(-> _.capitalize()) |> list |> ' '.join)
xmlid = "%s_view_%s" % (model_und, view_type) xmlid = "%s_view_%s" % (model_und, view_type)
name = (' '.join)((model_cap, view_type.capitalize())) name = (model_cap, view_type.capitalize()) |> ' '.join
return (view_def)(*(xmlid, name, model, arch)) return (xmlid, name, model, arch) |*> view_def
def view_inherit(filename, # type: Text def view_inherit(filename: Text, model: Text, inherit: Text, arch: List) -> XMLDictElement:
model, # type: Text
inherit, # type: Text
arch # type: List
):
# type: (...) -> XMLDictElement
""" Inherited View simplification with name of the record, xmlid for model """ Inherited View simplification with name of the record, xmlid for model
and inherited view """ and inherited view """
module = ((filename.split)('.'))[2] module = '.' |> filename.split |> .[2]
inherited = ((inherit.split)('.'))[1] inherited = '.' |> inherit.split |> .[1]
xmlid = '%s_inherit_%s' % (inherited, module) xmlid = '%s_inherit_%s' % (inherited, module)
model_cap = ((' '.join)((list)(map(lambda _=None: _.capitalize(), (model.split)('.'))))) model_cap = ('.' |> model.split |> map$(-> _.capitalize()) |> list |> ' '.join)
name = '%s Adaptations' % model_cap name = '%s Adaptations' % model_cap
return view(xmlid, [(field_name)(name), (field_model)(model), (field_inherit)(inherit), (field_arch)(arch)]) return view(xmlid, [name |> field_name, model |> field_model,
inherit |> field_inherit, arch |> field_arch])

View File

@ -1,26 +1,3 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# __coconut_hash__ = 0xb59e6156
# 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 -*- # -*- coding: utf-8 -*-
# #
# Copyright 2020 Fabien Bourgeois <fabien@yaltik.com> # Copyright 2020 Fabien Bourgeois <fabien@yaltik.com>
@ -38,7 +15,7 @@ from __coconut__ import _coconut, _coconut_MatchError, _coconut_igetitem, _cocon
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
""" Odoo Helpers tests """
import unittest import unittest
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
@ -50,207 +27,208 @@ class TestOdooBase(unittest.TestCase):
def test_odoo(self): def test_odoo(self):
element = od.odoo([]) element = od.odoo([])
(self.assertIsInstance)(element, ET.Element) element `self.assertIsInstance` ET.Element
(self.assertEquals)(element.tag, 'odoo') element.tag `self.assertEquals` 'odoo'
def test_data(self): def test_data(self):
element = od.data([]) element = od.data([])
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'data') element.tag `self.assertEquals` 'data'
(self.assertEquals)(element.attrs, {}) element.attrs `self.assertEquals` {}
element = od.data({"one": "attribute"}, []) element = od.data({"one": "attribute"}, [])
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'data') element.tag `self.assertEquals` 'data'
(self.assertEquals)(element.attrs, {"one": "attribute"}) element.attrs `self.assertEquals` {"one": "attribute"}
def test_aliases(self): def test_aliases(self):
""" Test simple aliases to xmln """ """ Test simple aliases to xmln """
element = od.record({"one": "attribute"}, 'A child') element = od.record({"one": "attribute"}, 'A child')
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'record') element.tag `self.assertEquals` 'record'
(self.assertEquals)(element.attrs, {"one": "attribute"}) element.attrs `self.assertEquals` {"one": "attribute"}
(self.assertEquals)(element.children, ['A child']) element.children `self.assertEquals` ['A child']
element = od.tree() element = od.tree()
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'tree') element.tag `self.assertEquals` 'tree'
def test_act_window_model(self): def test_act_window_model(self):
element = (od.act_window_model)(*('sample.model', {'view_type': 'form'})) element = ('sample.model', {'view_type': 'form'}) |*> od.act_window_model
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'act_window') element.tag `self.assertEquals` 'act_window'
(self.assertEquals)(element.attrs['view_type'], 'form') element.attrs['view_type'] `self.assertEquals` 'form'
(self.assertEquals)(element.attrs['id'], 'sample_model_view_action') element.attrs['id'] `self.assertEquals` 'sample_model_view_action'
(self.assertEquals)(element.attrs['res_model'], 'sample.model') element.attrs['res_model'] `self.assertEquals` 'sample.model'
(self.assertEquals)(element.attrs['name'], 'Sample Model Action') element.attrs['name'] `self.assertEquals` 'Sample Model Action'
def test_menunitem_model(self): def test_menunitem_model(self):
element = (od.menuitem_model)(*('sample.model', {'groups': 'base.user_employee'})) element = ('sample.model', {'groups': 'base.user_employee'}) |*> od.menuitem_model
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'menuitem') element.tag `self.assertEquals` 'menuitem'
(self.assertEquals)(element.attrs['groups'], 'base.user_employee') element.attrs['groups'] `self.assertEquals` 'base.user_employee'
(self.assertEquals)(element.attrs['id'], 'sample_model_menu') element.attrs['id'] `self.assertEquals` 'sample_model_menu'
(self.assertEquals)(element.attrs['action'], 'sample_model_view_action') element.attrs['action'] `self.assertEquals` 'sample_model_view_action'
def test_attribute(self): def test_attribute(self):
element = od.attribute('invisible', "1") element = od.attribute('invisible', "1")
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'attribute') element.tag `self.assertEquals` 'attribute'
(self.assertEquals)(element.attrs['name'], 'invisible') element.attrs['name'] `self.assertEquals` 'invisible'
(self.assertEquals)(element.children, ["1"]) element.children `self.assertEquals` ["1"]
def test_fields(self): def test_fields(self):
element = od.field({"one": "attribute"}, 'A child') element = od.field({"one": "attribute"}, 'A child')
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'field') element.tag `self.assertEquals` 'field'
element = (od.field_name)('A name') element = 'A name' |> od.field_name
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'field') element.tag `self.assertEquals` 'field'
(self.assertEquals)(element.attrs['name'], 'name') element.attrs['name'] `self.assertEquals` 'name'
(self.assertEquals)(element.children, ['A name']) element.children `self.assertEquals` ['A name']
element = (od.field_model)('sample.model') element = 'sample.model' |> od.field_model
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'field') element.tag `self.assertEquals` 'field'
(self.assertEquals)(element.attrs['name'], 'model') element.attrs['name'] `self.assertEquals` 'model'
(self.assertEquals)(element.children, ['sample.model']) element.children `self.assertEquals` ['sample.model']
element = (od.field_inherit)('module.xml_view') element = 'module.xml_view' |> od.field_inherit
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'field') element.tag `self.assertEquals` 'field'
(self.assertEquals)(element.attrs['name'], 'inherit_id') element.attrs['name'] `self.assertEquals` 'inherit_id'
(self.assertEquals)(element.attrs['ref'], 'module.xml_view') element.attrs['ref'] `self.assertEquals` 'module.xml_view'
(self.assertFalse)(element.children) element.children |> self.assertFalse
element = od.field_arch() element = od.field_arch()
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'field') element.tag `self.assertEquals` 'field'
(self.assertEquals)(element.attrs['name'], 'arch') element.attrs['name'] `self.assertEquals` 'arch'
(self.assertEquals)(element.attrs['type'], 'xml') element.attrs['type'] `self.assertEquals` 'xml'
(self.assertFalse)(element.children) element.children |> self.assertFalse
def test_view(self): def test_view(self):
element = od.view('view_xmlid', []) element = od.view('view_xmlid', [])
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'record') element.tag `self.assertEquals` 'record'
(self.assertEquals)(element.attrs['id'], 'view_xmlid') element.attrs['id'] `self.assertEquals` 'view_xmlid'
(self.assertEquals)(element.attrs['model'], 'ir.ui.view') element.attrs['model'] `self.assertEquals` 'ir.ui.view'
(self.assertFalse)(element.children) element.children |> self.assertFalse
def test_view_def(self): def test_view_def(self):
element = od.view_def('view_xmlid', 'View', 'sample.model', []) element = od.view_def('view_xmlid', 'View', 'sample.model', [])
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'record') element.tag `self.assertEquals` 'record'
(self.assertEquals)(element.attrs['id'], 'view_xmlid') element.attrs['id'] `self.assertEquals` 'view_xmlid'
(self.assertEquals)(element.attrs['model'], 'ir.ui.view') element.attrs['model'] `self.assertEquals` 'ir.ui.view'
(self.assertEquals)(((len)(element.children)), 3) (element.children |> len) `self.assertEquals` 3
(self.assertIsInstance)(element.children[0], XMLDictElement) element.children[0] `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.children[0].tag, 'field') element.children[0].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[0].attrs['name'], 'name') element.children[0].attrs['name'] `self.assertEquals` 'name'
(self.assertEquals)(element.children[0].children, ['View']) element.children[0].children `self.assertEquals` ['View']
(self.assertIsInstance)(element.children[1], XMLDictElement) element.children[1] `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.children[1].tag, 'field') element.children[1].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[1].attrs['name'], 'model') element.children[1].attrs['name'] `self.assertEquals` 'model'
(self.assertEquals)(element.children[1].children, ['sample.model']) element.children[1].children `self.assertEquals` ['sample.model']
(self.assertIsInstance)(element.children[2], XMLDictElement) element.children[2] `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.children[2].tag, 'field') element.children[2].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[2].attrs['name'], 'arch') element.children[2].attrs['name'] `self.assertEquals` 'arch'
(self.assertEquals)(element.children[2].attrs['type'], 'xml') element.children[2].attrs['type'] `self.assertEquals` 'xml'
(self.assertFalse)(element.children[2].children) element.children[2].children |> self.assertFalse
def test_view_new(self): def test_view_new(self):
element = od.view_new('tree', 'sample.model', []) element = od.view_new('tree', 'sample.model', [])
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'record') element.tag `self.assertEquals` 'record'
(self.assertEquals)(element.attrs['id'], 'sample_model_view_tree') element.attrs['id'] `self.assertEquals` 'sample_model_view_tree'
(self.assertEquals)(element.attrs['model'], 'ir.ui.view') element.attrs['model'] `self.assertEquals` 'ir.ui.view'
(self.assertEquals)(((len)(element.children)), 3) (element.children |> len) `self.assertEquals` 3
(self.assertIsInstance)(element.children[0], XMLDictElement) element.children[0] `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.children[0].tag, 'field') element.children[0].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[0].attrs['name'], 'name') element.children[0].attrs['name'] `self.assertEquals` 'name'
(self.assertEquals)(element.children[0].children, ['Sample Model Tree']) element.children[0].children `self.assertEquals` ['Sample Model Tree']
(self.assertIsInstance)(element.children[1], XMLDictElement) element.children[1] `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.children[1].tag, 'field') element.children[1].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[1].attrs['name'], 'model') element.children[1].attrs['name'] `self.assertEquals` 'model'
(self.assertEquals)(element.children[1].children, ['sample.model']) element.children[1].children `self.assertEquals` ['sample.model']
(self.assertIsInstance)(element.children[2], XMLDictElement) element.children[2] `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.children[2].tag, 'field') element.children[2].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[2].attrs['name'], 'arch') element.children[2].attrs['name'] `self.assertEquals` 'arch'
(self.assertEquals)(element.children[2].attrs['type'], 'xml') element.children[2].attrs['type'] `self.assertEquals` 'xml'
(self.assertFalse)(element.children[2].children) element.children[2].children |> self.assertFalse
def test_view_inherit(self): def test_view_inherit(self):
element = od.view_inherit('odoo.addons.module', 'sample.model', 'parent.view', []) element = od.view_inherit('odoo.addons.module', 'sample.model', 'parent.view', [])
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'record') element.tag `self.assertEquals` 'record'
(self.assertEquals)(element.attrs['id'], 'view_inherit_module') element.attrs['id'] `self.assertEquals` 'view_inherit_module'
(self.assertEquals)(element.attrs['model'], 'ir.ui.view') element.attrs['model'] `self.assertEquals` 'ir.ui.view'
(self.assertEquals)(((len)(element.children)), 4) (element.children |> len) `self.assertEquals` 4
(self.assertIsInstance)(element.children[0], XMLDictElement) element.children[0] `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.children[0].tag, 'field') element.children[0].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[0].attrs['name'], 'name') element.children[0].attrs['name'] `self.assertEquals` 'name'
(self.assertEquals)(element.children[0].children, ['Sample Model Adaptations']) element.children[0].children `self.assertEquals` ['Sample Model Adaptations']
(self.assertIsInstance)(element.children[1], XMLDictElement) element.children[1] `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.children[1].tag, 'field') element.children[1].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[1].attrs['name'], 'model') element.children[1].attrs['name'] `self.assertEquals` 'model'
(self.assertEquals)(element.children[1].children, ['sample.model']) element.children[1].children `self.assertEquals` ['sample.model']
(self.assertIsInstance)(element.children[2], XMLDictElement) element.children[2] `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.children[2].tag, 'field') element.children[2].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[2].attrs['name'], 'inherit_id') element.children[2].attrs['name'] `self.assertEquals` 'inherit_id'
(self.assertFalse)(element.children[2].children) element.children[2].children |> self.assertFalse
(self.assertIsInstance)(element.children[3], XMLDictElement) element.children[3] `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.children[3].tag, 'field') element.children[3].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[3].attrs['name'], 'arch') element.children[3].attrs['name'] `self.assertEquals` 'arch'
(self.assertEquals)(element.children[3].attrs['type'], 'xml') element.children[3].attrs['type'] `self.assertEquals` 'xml'
(self.assertFalse)(element.children[3].children) element.children[3].children |> self.assertFalse
def test_action_server_code(self): def test_action_server_code(self):
element = od.action_server_code('sample.xmlid', 'Code', 'sample.model', '''record.do_something()''') element = od.action_server_code('sample.xmlid', 'Code', 'sample.model',
(self.assertIsInstance)(element, XMLDictElement) '''record.do_something()''')
(self.assertEquals)(element.tag, 'record') element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.attrs['id'], 'sample.xmlid') element.tag `self.assertEquals` 'record'
(self.assertEquals)(element.attrs['model'], 'ir.actions.server') element.attrs['id'] `self.assertEquals` 'sample.xmlid'
(self.assertEquals)(((len)(element.children)), 4) element.attrs['model'] `self.assertEquals` 'ir.actions.server'
(self.assertIsInstance)(element.children[0], XMLDictElement) (element.children |> len) `self.assertEquals` 4
(self.assertEquals)(element.children[0].tag, 'field') element.children[0] `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.children[0].attrs['name'], 'name') element.children[0].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[0].children, ['Code']) element.children[0].attrs['name'] `self.assertEquals` 'name'
(self.assertIsInstance)(element.children[1], XMLDictElement) element.children[0].children `self.assertEquals` ['Code']
(self.assertEquals)(element.children[1].tag, 'field') element.children[1] `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.children[1].attrs['name'], 'model_id') element.children[1].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[1].attrs['ref'], 'sample.model') element.children[1].attrs['name'] `self.assertEquals` 'model_id'
(self.assertFalse)(element.children[1].children) element.children[1].attrs['ref'] `self.assertEquals` 'sample.model'
(self.assertEquals)(element.children[2].tag, 'field') element.children[1].children |> self.assertFalse
(self.assertEquals)(element.children[2].attrs['name'], 'state') element.children[2].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[2].children, ['code']) element.children[2].attrs['name'] `self.assertEquals` 'state'
(self.assertEquals)(element.children[3].tag, 'field') element.children[2].children `self.assertEquals` ['code']
(self.assertEquals)(element.children[3].attrs['name'], 'code') element.children[3].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[3].children, ['record.do_something()']) element.children[3].attrs['name'] `self.assertEquals` 'code'
element.children[3].children `self.assertEquals` ['record.do_something()']
def test_client_action_multi(self): def test_client_action_multi(self):
element = od.client_action_multi('sample.xmlid', 'Multi', 'sample.model', 'sample.action') element = od.client_action_multi('sample.xmlid', 'Multi', 'sample.model', 'sample.action')
(self.assertIsInstance)(element, XMLDictElement) element `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.tag, 'record') element.tag `self.assertEquals` 'record'
(self.assertEquals)(element.attrs['id'], 'sample.xmlid') element.attrs['id'] `self.assertEquals` 'sample.xmlid'
(self.assertEquals)(element.attrs['model'], 'ir.values') element.attrs['model'] `self.assertEquals` 'ir.values'
(self.assertEquals)(((len)(element.children)), 4) (element.children |> len) `self.assertEquals` 4
(self.assertIsInstance)(element.children[0], XMLDictElement) element.children[0] `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.children[0].tag, 'field') element.children[0].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[0].attrs['name'], 'name') element.children[0].attrs['name'] `self.assertEquals` 'name'
(self.assertEquals)(element.children[0].children, ['Multi']) element.children[0].children `self.assertEquals` ['Multi']
(self.assertIsInstance)(element.children[1], XMLDictElement) element.children[1] `self.assertIsInstance` XMLDictElement
(self.assertEquals)(element.children[1].tag, 'field') element.children[1].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[1].attrs['name'], 'key2') element.children[1].attrs['name'] `self.assertEquals` 'key2'
(self.assertEquals)(element.children[1].attrs['eval'], "'client_action_multi'") element.children[1].attrs['eval'] `self.assertEquals` "'client_action_multi'"
(self.assertFalse)(element.children[1].children) element.children[1].children |> self.assertFalse
(self.assertEquals)(element.children[2].tag, 'field') element.children[2].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[2].attrs['name'], 'model') element.children[2].attrs['name'] `self.assertEquals` 'model'
(self.assertEquals)(element.children[2].attrs['eval'], "'sample.model'") element.children[2].attrs['eval'] `self.assertEquals` "'sample.model'"
(self.assertEquals)(element.children[3].tag, 'field') element.children[3].tag `self.assertEquals` 'field'
(self.assertEquals)(element.children[3].attrs['name'], 'value') element.children[3].attrs['name'] `self.assertEquals` 'value'
(self.assertEquals)(element.children[3].attrs['eval'], "'ir.actions.server,%d'%sample.action") element.children[3].attrs['eval'] `self.assertEquals` "'ir.actions.server,%d'%sample.action"
if __name__ == '__main__': if __name__ == '__main__':