Esempio n. 1
0
    def test_all(self):
        Tag1 = xmltuple('Tag1', 'tag1', ['a'], types={'a': int})
        Tag2 = xmltuple('Tag2', 'tag2', ['b'])
        Tag3 = xmltuple('Tag3', 'tag3', ['c'])

        All = xmlall('All', 'all', tags1=Tag1, tags2=Tag2, tags3=Tag3)

        all_ = All(tags1=[Tag1(1), Tag1(2), Tag1(3)],
                   tags2=[Tag2('a'), Tag2('b'),
                          Tag2('c')],
                   tags3=[Tag3('x'), Tag3('y'),
                          Tag3('z')])
        self.assertEqual(all_.to_xml(), All.from_xml(all_.to_xml()).to_xml())

        all2 = All(
            [Tag1(1),
             Tag2('a'),
             Tag3('x'),
             Tag1(2),
             Tag2('b'),
             Tag3('c')])
        self.assertEqual(all2.to_xml(), All.from_xml(all2.to_xml()).to_xml())
        self.assertListEqual(all2.to_object(),
                             All.from_xml(all2.to_xml()).to_object())

        self.assertGreater(len(list(all_)), len(list(all2)))
Esempio n. 2
0
    def test_nested_tuple(self):
        Tag1 = xmltuple('Tag1', 'tag1', ['foo', 'bar'])
        Tag2 = xmltuple('Tag2', 'tag2', ['boo'])
        Tag = xmltuple('Tag', 'tag', ['tag1', 'tag2'], {
            'tag1': Tag1,
            'tag2': Tag2
        })
        tag = Tag(tag1=Tag1(foo='a', bar='b'), tag2=Tag2(boo='c'))
        self.assertEqual(tag.to_xml(), Tag.from_xml(tag.to_xml()).to_xml())

        TagL = xmltuple('Tag', 'tag', ['tag1', 'tag2'], (Tag1, Tag2))
        tagL = TagL.from_xml(tag.to_xml())
        self.assertEqual(tag.to_xml(), tagL.to_xml())

        self.assertDictEqual(tag.to_object(), tagL.to_object())
Esempio n. 3
0
    def test_list(self):
        Tag = xmltuple('Tag',
                       'tag', ['foo', 'bar'],
                       types={
                           'foo': int,
                           'bar': int
                       })
        List = xmllist('List', 'list', Tag)
        list_ = List([Tag(1, 2), Tag(3, 4), Tag(5, 6)])
        self.assertEqual(list_.to_xml(),
                         List.from_xml(list_.to_xml()).to_xml())

        self.assertListEqual(list_.to_object(),
                             List.from_xml(list_.to_xml()).to_object())

        List2 = xmllist('List2', 'list2', 'tag')
        list2 = List2([1, 2, 3, 4])
        self.assertEqual(list2.to_xml(),
                         List2.from_xml(list2.to_xml()).to_xml())

        List3 = xmllist('List3', 'list3', 'tag', ['id', 'foo'])
        list3 = List3([6, 66], 4, 'bar')
        self.assertEqual(list3.to_xml(),
                         List3.from_xml(list3.to_xml()).to_xml())

        self.assertGreater(len(list(list2)), len(list(list_)))
Esempio n. 4
0
    def test_tuple(self):
        Tag = xmltuple('Tag', 'tag', ['a', 'b'])
        tag = Tag(1, 2)

        a, b = tag
        self.assertEqual(a, tag.a)
        self.assertEqual(b, tag.b)

        tag2 = Tag(a=1, b=2)
        self.assertEqual(tag.a, 1)
        self.assertEqual(tag2.b, 2)
        self.assertEqual(tag.to_xml(), tag2.to_xml())

        self.assertEqual(tag.to_xml(), Tag.from_xml(tag.to_xml()).to_xml())

        Tag2 = xmltuple('Tag2', 'tag2', ['id', 'boo', 'far'], kws=['id'])
        tag2 = Tag2(1, 2, 3)
        self.assertEqual(tag2.to_xml(), Tag2.from_xml(tag2.to_xml()).to_xml())

        TagA = xmltuple('TagA', 'tagA', ['a'], kws=['id'])
        tagA = TagA(a=1, id=2)
        self.assertEqual(tagA.to_xml(), TagA.from_xml(tagA.to_xml()).to_xml())
Esempio n. 5
0
    def test_default(self):
        Tag = xmltuple('Tag', 'tag', ['a', 'b'])
        tag = Tag()
        self.assertIsNone(tag.a)
        self.assertIsNone(tag.b)

        TagD = defaultify_init(Tag, 'Tagd', a=1, b=2)
        tagD = TagD()
        self.assertEqual(tagD.a, 1)
        self.assertEqual(tagD.b, 2)

        tagD2 = TagD(b=4)
        self.assertEqual(tagD2.a, 1)
        self.assertEqual(tagD2.b, 4)

        tagD3 = TagD(a=4)
        self.assertEqual(tagD3.a, 4)
        self.assertEqual(tagD3.b, 2)

        tagD4 = TagD(a=5, b=6)
        self.assertEqual(tagD4.a, 5)
        self.assertEqual(tagD4.b, 6)
Esempio n. 6
0
    LinkType.DROPDOWN,
    LinkType.LINKEDTABLE,
]

_form_link_type_multiple = [
    LinkType.DROPDOWN, LinkType.LINKEDTABLE, LinkType.LINKEDFORM
]

_field_attrs = ['rowName', 'text', 'isEditable', 'isVisible', 'hint', 'help']

_field_types = {'isEditable': caster.bool_cast, 'isVisible': caster.bool_cast}

_field_defaults = {'isVisible': True}

_SimpleField = xmltuple('SimpleField',
                        'simpleField',
                        _field_attrs,
                        types=_field_types)

SimpleField = defaultify_init(_SimpleField, 'SimpleField', **_field_defaults)

_LinkedField = xmltuple('LinkedField',
                        'linkedField', [*_field_attrs, 'linkType'], [LinkType],
                        types=_field_types)

LinkedField = defaultify_init(_LinkedField, 'LinkedField', **_field_defaults)

FormFields = xmlall('FormFields',
                    'fields',
                    simple=SimpleField,
                    linked=LinkedField)
Esempio n. 7
0
]

_table_column_types = {
    'isPk': caster.bool_cast,
    'isSort': caster.bool_cast,
    'isFilter': caster.bool_cast,
    'isEditable': caster.bool_cast,
    'isRequired': caster.bool_cast,
    'isVisible': caster.bool_cast,
    'isUnique': caster.bool_cast,
    'isAuto': caster.bool_cast
}

_TableColumn = xmltuple(
    '_TableColumn',
    'column',
    _table_column_attrs,
    types=_table_column_types,
)

TableColumn = defaultify_init(
    _TableColumn,
    'TableColumn',
    text=lambda s: stringcase.sentencecase(s.rowName),
    isPk=False,
    isRequired=False,
    isSort=True,
    isFilter=True,
    isEditable=True,
    isUnique=False,
    isVisible=True,
    isAuto=False)
Esempio n. 8
0
from .access import AccessRights
from .scripts import Buttons, Triggers

__all__ = ['Page', 'PrebuiltPageType', 'PrebuiltPage']

# Abstract hierarchy element params
_element_attrs = [
    'accessRights', 'buttonList', 'triggerList', 'name', 'overrideIcon'
]
_element_children_classes = [AccessRights, Buttons, Triggers]
_element_kws = ['id']
_element_types = {'id': int}

# User page entry
_Page = xmltuple('Page', 'pageEntry', [*_element_attrs, 'pageName', 'addCard'],
                 _element_children_classes, _element_kws, {
                     **_element_types, 'addCard': bool
                 })

Page = defaultify_init(_Page, 'Page', addCard=True)

# Prebuilt pages
PrebuiltPageType = xmlenum('PrebuiltPageType',
                           'type',
                           SQL='sql',
                           USERS='users',
                           STATUS='status')

PrebuiltPage = xmltuple('PrebuiltPage', 'prebuiltPageEntry',
                        [*_element_attrs, 'type'],
                        [*_element_children_classes, PrebuiltPageType],
                        _element_kws, _element_types)
Esempio n. 9
0
import logging
import os
from fnmatch import fnmatch

from ermaket.api.config import Config
from ermaket.api.system.hierarchy import Activation
from ermaket.utils import get_project_root
from ermaket.utils.xml import RootMixin, xmllist, xmltuple

__all__ = ['Script', 'ScriptList', 'Activations']

Activations = xmllist('Activations', 'activations', Activation)

Script = xmltuple('Script',
                  'script', ['path', 'activations'], [Activations],
                  kws=['id'],
                  types={'id': int})

_ScriptList = xmllist('ScriptList', 'scripts', Script)


class ScriptList(_ScriptList, RootMixin):
    def __init__(self, xml=None, scripts=None):
        self._config = Config()
        args, kwargs = self._init_root(
            xml,
            self._config.XML["ScriptListAttributes"],
            values=scripts,
        )
        super().__init__(*args, **kwargs)
Esempio n. 10
0
from .elements import (_element_attrs, _element_children_classes, _element_kws,
                       _element_types)
from ermaket.utils.xml import xmllist, xmltuple, xmltag

__all__ = ['Section', 'Children']

ChildId = xmltag('ChildId', 'childId', int)
Children = xmllist('Children', 'children', ChildId)
_Section = xmltuple('_Section', 'section', [*_element_attrs, 'children'],
                    [*_element_children_classes, Children], _element_kws,
                    _element_types)


class Section(_Section):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        if self.children is None:
            self.children = Children()
        self._children = None

    def resolve_children(self, func):
        self._children = []
        for child_id in self.children:
            child = func(child_id)
            if child:
                self._children.append(child)
        return self.children.values

    def set_child_ids(self, ids):
        self._children = None
Esempio n. 11
0
_locations = {
    "all": [Location.TOP, Location.CARDHEADER],
    "tableEntry": [Location.ACTION]
}

SystemAction = xmlenum('SystemAction',
                       'action',
                       REGTOKEN='regToken',
                       PASSTOKEN='passToken')

Button = xmltuple('Button',
                  'button', [
                      'text', 'location', 'icon', 'column', 'tooltip',
                      'variant', 'scriptId', 'action'
                  ], [Location, SystemAction],
                  types={
                      'scriptId': lambda v: int(v) if v is not None else None,
                      'column': lambda v: int(v) if v is not None else None,
                  })
Buttons = xmllist('Buttons', 'buttonList', Button)

# Triggers
Activation = xmlenum(
    'Activation',
    'activation',
    OPEN='open',  # Before opening the hierarchy element
    AFTEROPEN='afterOpen',  # After opening the hierarchy element
    READ='read',  # Read this table
    TRANSACTION='transaction',  # Transaction (global)
    LOGIN='******',  # Login (global)