Esempio n. 1
0
def main():
    import pprint
    import os
    from test_func import test_table

    os.environ['LB-TESTING'] = '1'
    form_name = 'app'
    form = FormList(test_table(), form_name)

    assert type(form) == FormList

    assert len(FormList(test_table(), form_name)) > 0

    assert [f['name'] for f in FormList(test_table(), form_name)] == [
        'id', 'type', 'app-name', 'version', 'username', 'password',
        'app-token'
    ]

    assert [f['name'] for f in FormList(test_table(), form_name, ['c'])] == []

    #print('FormList(test_table(),form_name,[C])]', [f['name'] for f in FormList(test_table(),form_name,['c','C'])] )

    assert [f['name'] for f in FormList(test_table(), form_name, ['C', 'c'])
            ] == ['type', 'app-name', 'version', 'username', 'password']
    '''
    assert [f['name'] for f in FormList(test_table(),form_name,['I'])] == ['id', 'type']
    assert [f['name'] for f in FormList(test_table(),form_name,['U'])] == ['form']
    assert [f['name'] for f in FormList(test_table(),form_name,['u'])] == ['password','active']
    assert [f['name'] for f in FormList(test_table(),form_name,['u','U'])] == ['form','password','active']
    assert [f['name'] for f in FormList(test_table(),form_name,['u','U','I'])] == ['id','type','form','password','active']
    assert [f['name'] for f in FormList(test_table(),form_name,['R'])] == ['id','type','form']
    assert [f['name'] for f in FormList(test_table(),form_name,['r'])] == ['active', 'created', 'updated']
    assert [f['name'] for f in FormList(test_table(),form_name,['r','R'])] == ['id','type','form','active', 'created', 'updated']
    '''
    os.environ['LB-TESTING'] = '0'
Esempio n. 2
0
def main():
    import os
    from test_func import test_table
    from context_dict import ContextDict

    os.environ['LB-TESTING'] = '1'

    # FormKey
    assert FormKeyList(test_table()) == ['app', 'user']

    # InsertForm
    form = InsertForm(test_table(), 'app')
    assert type(form) == InsertForm
    assert form == {
        'type': 'app',
        'app-name': 'NA',
        'version': 'NA',
        'username': '******',
        'password': '******'
    }
    print('insert form', form)

    context = ContextDict().read()
    #print('context', context)
    form = context.goodify(form)
    print('context good', form)
    form = context.badify(form)
    print('context bad', form)

    # UpdateForm
    form = UpdateForm(test_table(), 'app')
    print('update form', form)
    assert type(form) == UpdateForm
    assert form == {
        'id': 'NA',
        'type': 'app',
        'app-name': 'NA',
        'username': '******',
        'password': '******'
    }
    form = context.goodify(form)
    print('context good', form)
    form = context.badify(form)
    print('context bad', form)

    form = InsertForm(test_table(), 'user')
    print('insert form', form)

    os.environ['LB-TESTING'] = '0'
def main():
    import test_func
    import pprint
    import os

    os.environ['LB-TESTING'] = '1'

    #if 1== 1: exit(0)
    helper = HelperTestAPITemplate().set_dictionary(test_func.test_table())
    #lines = helper.template()
    #print('\n'.join(lines))
    #print('fields', helper.getRequiredFields())

    #assert type(helper.getFields())==FieldList
    #assert type(helper.getFields()[0])==dict
    #print('xxx', [f['name'] for f in helper.getFields()])
    #assert [f['name'] for f in helper.getFields()] == ['id', 'type', 'form', 'password', 'active', 'created', 'updated']

    print('lsit', helper.getForm('app'))
    print('type', type(helper.getForm('app')))
    assert type(helper.getForm('app')) == FormList
    assert type(helper.getForm('app')[0]) == dict
    #print('app', helper.getForm('app'))
    #print('app[0]', helper.getForm('app')[0])

    print('app', [f['name'] for f in helper.getForm('app')])
    assert [f['name'] for f in helper.getForm('app')] == [
        'id', 'type', 'app-name', 'version', 'username', 'password', 'token'
    ]

    #print('insert object', {'app-name': 'my-app', 'version': '1.0.0', 'app-token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'})

    print('getTpye', helper.getForm('app'))

    #if 1==1 : exit(0)
    '''
    assert helper.getTestUpdateObject(helper.getForm('app')) == {'id': 'e53229aa-d09c-4cec-b566-ea553ae8078d', 'app-name': 'my-app', 'version': '1.0.0', 'app-token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'}

    assert type(helper.getForm('user')) == list
    assert type(helper.getForm('user')[0]) == dict
    assert type(helper.getTestUpdateObject(helper.getForm('user'))) == dict

    assert helper.getTestUpdateObject(helper.getForm('user')) == {'id': 'e53229aa-d09c-4cec-b566-ea553ae8078d', 'username': '******', 'password': '******'}

    print('combo list',    helper.expectedColumnCombinations(helper.getFields(), type='c'))
    assert helper.expectedColumnCombinations(helper.getFields(), type='c') == [('type', 'attributes'), ('attributes',), ('type',)]
    '''

    lines = helper.template()

    assert (type(lines) == list)  # is a list

    #pprint.pprint(lines)
    print('\n'.join(lines))

    #print('\n'.join(lines))
    os.environ['LB-TESTING'] = '0'
Esempio n. 4
0
def main():
    from test_func import test_table, test_db
    from configuration_interface import InterfaceConfiguration
    from pprint import pprint
    import os
    from list_forms import FormList

    os.environ['LB-TESTING'] = '1'
    #print('Function', Function(test_table(),'[[type]]'))
    #print('toString', Function(test_table(), '[[type]]').toString())
    # [[type]] applies to all templates
    func = Function(test_table(), '-- test comment').run()
    assert func == ['-- test comment']
    func = Function(test_table(), '[[type]]').run()
    assert func == ['table']
    assert func.toString() == 'table'
    print('getTemplateLine', func.getTemplateLine)

    os.environ['LB-TESTING'] = '0'
Esempio n. 5
0
def main():
    import pprint
    import os
    from test_func import test_table

    os.environ['LB-TESTING'] = '1'
    methods = MethodList(test_table(), 'app')

    assert type(methods) == MethodList
    #print('methond', methods)
    assert methods == ['upsert', 'select']

    os.environ['LB-TESTING'] = '0'
Esempio n. 6
0
def main():
    from test_func import test_table, test_db
    from configuration_interface import InterfaceConfiguration
    from pprint import pprint
    import os

    os.environ['LB-TESTING'] = '1'
    dictionary_tbl = InterfaceConfiguration('app').load(test_table())
    print('dictionary_tbl', dictionary_tbl)
    tmpl = Template_Table(dictionary_tbl)
    print('list table')
    #print('\n'.join(tmpl))
    print('tmpl.toString()', tmpl.toString())
    os.environ['LB-TESTING'] = '0'
Esempio n. 7
0
def main():
    from test_func import test_table, test_db
    from configuration_interface import InterfaceConfiguration
    from pprint import pprint
    import os

    os.environ['LB-TESTING'] = '1'
    dictionary_tbl = InterfaceConfiguration('app').load(test_table())
    # print('dictionary_tbl',dictionary_tbl)
    tmpl = Template_InterfaceTest(
        dictionary_tbl)  #.run() # have to run for test

    print('list upsert')
    print(tmpl.toString())
    #print('\n'.join(tmpl))

    os.environ['LB-TESTING'] = '0'
Esempio n. 8
0
def main():
    from pathlib import Path
    from util import Util
    import os
    from test_func import test_table
    from pprint import pprint

    #from app_settings import TestAppSettings

    os.environ['LB-TESTING'] = '1'
    #appSettings = TestAppSettings()
    flat = InterfaceConfiguration('app').load(test_table())
    #print('flat')
    pprint(flat)
    assert 'api-form' in flat
    assert 'api-name' in flat
    assert flat['api-name'] == 'user'
    assert flat['api-version'] == '1.0.0'

    os.environ['LB-TESTING'] = '0'
Esempio n. 9
0
def main():
    from test_func import test_table, test_db
    from configuration_interface import InterfaceConfiguration
    from pprint import pprint
    import os
    from list_forms import FormList

    os.environ['LB-TESTING'] = '1'
    dictionary_tbl = InterfaceConfiguration('app').load(test_table())
    #dictionary_db = InterfaceConfiguration('app').load(test_db())
    #template = []

    func = Function_Anchor(dictionary_tbl,
                           '-- Always start with Function_Anchor')
    print('A Function', func)
    print('A getTemplateLine', func.getTemplateLine())

    assert func == []
    assert func.getTemplateLine() == '-- Always start with Function_Anchor'

    os.environ['LB-TESTING'] = '0'
def main():
    from function_anchor import Function_Anchor
    from test_func import test_table, test_db
    from configuration_interface import InterfaceConfiguration
    from pprint import pprint
    import os
    from list_forms import FormList

    os.environ['LB-TESTING'] = '1'
    dictionary_tbl = InterfaceConfiguration('app').load(test_table())
    dictionary_db = InterfaceConfiguration('app').load(test_db())
    template = []

    ### F
    nxt = Function_UpdateCombinationCode()
    tmpl = "<<update-combination-code>>"
    func =  Function_Anchor(dictionary_tbl, tmpl) \
            .add(nxt)
    print('A Function nxt', nxt)
    print('A toString', func.toString())
    assert func.getTemplateLine().startswith("            if _json ? 'password' and _json ? 'active' then")
Esempio n. 11
0
def main():
    from test_func import test_table, test_db
    from configuration_interface import InterfaceConfiguration
    from pprint import pprint
    import os

    os.environ['LB-TESTING'] = '1'
    print('### A')
    dictionary_tbl = InterfaceConfiguration('user').load(test_table())
    print('### B')

    #print('dictionary_tbl',dictionary_tbl)

    tmpl = Template_Upsert(dictionary_tbl)
    print('### C')

    print('list upsert')
    print(tmpl.toString())
    #print('\n'.join(tmpl))
    print('### D')

    os.environ['LB-TESTING'] = '0'
Esempio n. 12
0
def main():
    import os
    from app_settings import AppSettingsTest
    from test_func import test_table, test_table_template, test_upsert_template
    from configuration_interface import InterfaceConfiguration
    from pprint import pprint
    os.environ['LB-TESTING'] = '1'
    # folders
    appSettings = AppSettingsTest().createFolders()
    dictionary_tbl = test_table()
    #dictionary_tbl = InterfaceConfiguration('app').load(test_table())
    #print('test_table_template()', test_table_template())

    template = Template(dictionary_tbl,
                        aux_template_list=test_table_template())
    template.getTemplateList() == test_table_template()

    print('toString', template.toString())

    assert type(template) == Template

    os.environ['LB-TESTING'] = '1'
def main():
    from function_anchor import Function_Anchor
    from test_func import test_table, test_db
    from configuration_interface import InterfaceConfiguration
    from pprint import pprint
    import os
    from list_forms import FormList

    os.environ['LB-TESTING'] = '1'
    dictionary_tbl = InterfaceConfiguration('app').load(test_table())
    dictionary_db = InterfaceConfiguration('app').load(test_db())
    template = []

    ### F
    nxt = Function_TableFieldCode()
    tmpl_line = "<<table-fields>>"
    func =  Function_Anchor(dictionary_tbl, tmpl_line) \
            .add(nxt)
    print('toString', func.toString())
    assert func.toString().startswith(
        '[[tbl-prefix]]_id TEXT PRIMARY KEY DEFAULT uuid_generate_v4 (),')

    print('toString', func.toString())
    os.environ['LB-TESTING'] = '0'
def main():
    from test_func import test_table, test_db
    from configuration_interface import InterfaceConfiguration
    from pprint import pprint
    import os
    from list_forms import FormList

    os.environ['LB-TESTING'] = '1'
    dictionary_tbl = InterfaceConfiguration('app').load(test_table())
    dictionary_db = InterfaceConfiguration('app').load(test_db())
    template = []

    #### B
    nxt = Function_SimpleTemplatize()
    func =  Function_Anchor(dictionary_tbl, '-- Always start with Function_Anchor [[tbl-name]]') \
            .add(nxt)
    print('B Function', func)
    print('B getTemplateLine', func.getTemplateLine())

    assert nxt == ['[[tbl-name]]']
    assert func.getTemplateLine(
    ) == '-- Always start with Function_Anchor register'

    ### C
    nxt = Function_SimpleTemplatize()
    func =  Function_Anchor(dictionary_tbl, '-- Always start with Function_Anchor [[tbl-name]][[tbl-name]]') \
            .add(nxt)

    print('C Function nxt', nxt)
    print('C getTemplateLine', func.getTemplateLine())

    assert nxt == ['[[tbl-name]]', '[[tbl-name]]']

    ### D
    nxt = Function_SimpleTemplatize()
    tmpl = "-- Always start with Function_Anchor [[tbl-name]] [[tbl-name]] [[tbl-fields.context:pk.json ? '{{name}}']]"
    func =  Function_Anchor(dictionary_tbl, tmpl) \
            .add(nxt)
    print('D Function nxt', nxt)
    print('D getTemplateLine', func.getTemplateLine())

    assert nxt == [
        '[[tbl-name]]', '[[tbl-name]]',
        "[[tbl-fields.context:pk.json ? '{{name}}']]"
    ]
    assert func.getTemplateLine(
    ) == "-- Always start with Function_Anchor register register json ? 'id'"

    ### E
    nxt = Function_SimpleTemplatize()
    tmpl = "[[tbl-fields.*:*.Declare _{{name}} {{type}};]]"
    func = Function_Anchor(dictionary_tbl, tmpl) \
        .add(nxt)
    print('E Function nxt', nxt)
    print('E getTemplateLine', func.getTemplateLine())

    assert nxt == ['[[tbl-fields.*:*.Declare _{{name}} {{type}};]]']
    assert func.getTemplateLine().startswith('Declare _id UUID;')

    ### F
    nxt = Function_SimpleTemplatize()
    tmpl = "[[tbl-fields.crud:(Cc).{{tbl-prefix}}_{{name}}., ]]"
    func = Function_Anchor(dictionary_tbl, tmpl) \
        .add(nxt)
    print('F Function nxt', nxt)
    print('F getTemplateLine', func.getTemplateLine())

    assert nxt == ['[[tbl-fields.crud:(Cc).{{tbl-prefix}}_{{name}}., ]]']
    assert func.getTemplateLine() == 'reg_type, reg_password'

    ### G
    nxt = Function_SimpleTemplatize()
    tmpl = "[[LB_DB_MODEL_password]]"
    func = Function_Anchor(dictionary_tbl, tmpl) \
        .add(nxt)
    print('G Function nxt', nxt)
    print('G getTemplateLine', func.getTemplateLine())

    assert nxt == ['[[LB_DB_MODEL_password]]']
    assert func.getTemplateLine() == 'PASSWORD.must.BE.AT.LEAST.32.CHARS.LONG'

    os.environ['LB-TESTING'] = '0'
Esempio n. 15
0
def main():
    from test_func import test_table, test_db
    from app_settings import AppSettingsTest
    from configuration_interface import InterfaceConfiguration
    from pprint import pprint
    import os
    #from list_forms import FormList

    os.environ['LB-TESTING'] = '1'
    appSettings = AppSettingsTest()
    pprint(appSettings)
    ##
    print('#########')
    parseList = ParseTagToList('[[tbl-name]]')
    print('A parseList', parseList)
    print('A multi', MultiList(parseList, test_table()))
    print('A toString', MultiList(parseList, test_table()).toString())

    assert parseList == ['None', ['None', 'None'], '{{tbl-name}}']
    assert MultiList(parseList, test_table()) == ['register']
    assert MultiList(parseList, test_table()).toString() == 'register'

    # singleton environment
    '''
    parseList = ParseTagToList('[[LB_DB_MODEL_password]]')
    print('K parseList', parseList)
    print('K MultiList', MultiList(parseList, test_table()))
    print('K toString', MultiList(parseList, test_table()).toString())
    assert parseList == ['None', ['None', 'None'], '{{LB_DB_MODEL_password}}']
    assert MultiList(parseList, test_table()) == ['PASSWORD.must.BE.AT.LEAST.32.CHARS.LONG']
    assert MultiList(parseList, test_table()).toString() == 'PASSWORD.must.BE.AT.LEAST.32.CHARS.LONG'
    '''
    print('#########')
    ## singleton
    parseList = ParseTagToList('[[tbl-fields.context:pk.{{name}}]]')
    print('A parseList', parseList)
    print('A multi', MultiList(parseList, test_table()))
    print('A toString', MultiList(parseList, test_table()).toString())

    assert parseList == ['tbl-fields', ['context', 'pk'], '{{name}}']
    assert MultiList(parseList, test_table()) == ['id']
    assert MultiList(parseList, test_table()).toString() == 'id'

    print('#########')
    ## singleton
    parseList = ParseTagToList(
        '[[tbl-fields.context:type.{{context}}-{{type}}]]')
    print('B parseList', parseList)
    print('B multi', MultiList(parseList, test_table()))
    print('B toString', MultiList(parseList, test_table()).toString())
    assert parseList == [
        'tbl-fields', ['context', 'type'], '{{context}}-{{type}}'
    ]
    assert MultiList(parseList, test_table()) == ['type-TEXT']
    assert MultiList(parseList, test_table()).toString() == 'type-TEXT'
    print('#########')
    ## singleton with multiple attributes
    parseList = ParseTagToList('[[tbl-fields.context:pk.{{name}}-{{type}}]]')
    print('C parseList', parseList)
    print('C MultiList', MultiList(parseList, test_table()))
    print('C toString', MultiList(parseList, test_table()).toString())

    assert parseList == ['tbl-fields', ['context', 'pk'], '{{name}}-{{type}}']
    assert MultiList(parseList, test_table()) == ['id-TEXT']
    assert MultiList(parseList, test_table()).toString() == 'id-TEXT'
    print('#########')
    ## multi with array value
    parseList = ParseTagToList('[[tbl-fields.crud:(C).{{name}}. and ]]')
    print('D parseList', parseList)
    print('D getFilterValue', parseList.getFilterValue())
    print('D MultiList', MultiList(parseList, test_table()))
    print('D toString', MultiList(parseList, test_table()).toString())
    assert parseList == ['tbl-fields', ['crud', ['C']], '{{name}}', ' and ']
    assert MultiList(parseList, test_table()) == ['type', 'password']
    assert MultiList(parseList, test_table()).toString() == 'type and password'

    print('#########')
    ## multi with array value
    parseList = ParseTagToList('[[tbl-fields.crud:(Cc).{{name}}. and ]]')
    print('E parseList', parseList)
    print('E MultiList', MultiList(parseList, test_table()))
    print('E toString', MultiList(parseList, test_table()).toString())
    assert parseList == [
        'tbl-fields', ['crud', ['C', 'c']], '{{name}}', ' and '
    ]
    assert MultiList(parseList, test_table()) == ['type', 'password']
    assert MultiList(parseList, test_table()).toString() == 'type and password'
    print('#########')
    ##
    parseList = ParseTagToList(
        "[[tbl-fields.crud:(Cc).json ? '{{name}}'. or ]]")
    print('F parseList', parseList)
    print('F MultiList', MultiList(parseList, test_table()))
    print('F toString', MultiList(parseList, test_table()).toString())
    assert parseList == [
        'tbl-fields', ['crud', ['C', 'c']], "json ? '{{name}}'", ' or '
    ]
    assert MultiList(parseList,
                     test_table()) == ["json ? 'type'", "json ? 'password'"]
    assert MultiList(
        parseList,
        test_table()).toString() == "json ? 'type' or json ? 'password'"
    print('#########')
    ##
    parseList = ParseTagToList(
        "[[tbl-fields.crud:(Cc).json ? '{{context}}-{{type}}'. and ]]")
    print('G parseList', parseList)
    print('G MultiList', MultiList(parseList, test_table()))
    print('G toString', MultiList(parseList, test_table()).toString())

    assert parseList == [
        'tbl-fields', ['crud', ['C', 'c']], "json ? '{{context}}-{{type}}'",
        ' and '
    ]
    assert MultiList(parseList, test_table()) == [
        "json ? 'type-TEXT'", "json ? 'password-TEXT'"
    ]
    assert MultiList(parseList, test_table()).toString(
    ) == "json ? 'type-TEXT' and json ? 'password-TEXT'"

    print('#########')
    ##
    parseList = ParseTagToList(
        '[[tbl-fields.*:*.Declare _{{name}} {{type}}; ]]')
    print('H parseList', parseList)
    print('H MultiList', MultiList(parseList, test_table()))
    print('H toString', MultiList(parseList, test_table()).toString())

    assert parseList == [
        'tbl-fields', ['*', '*'], "Declare _{{name}} {{type}}; "
    ]
    assert MultiList(parseList, test_table()) == [
        'Declare _id TEXT; ', 'Declare _type TEXT; ', 'Declare _form JSONB; ',
        'Declare _password TEXT; ', 'Declare _active BOOLEAN; ',
        'Declare _created TIMESTAMP; ', 'Declare _updated TIMESTAMP; '
    ]
    assert MultiList(parseList, test_table()).toString(
    ) == 'Declare _id TEXT; Declare _type TEXT; Declare _form JSONB; Declare _password TEXT; Declare _active BOOLEAN; Declare _created TIMESTAMP; Declare _updated TIMESTAMP; '

    print('#########')
    #"[[tbl-fields.crud:(Cc).{{tbl-prefix}}_{{name}}., ]]"
    ##
    parseList = ParseTagToList(
        '[[tbl-fields.crud:(Cc).{{tbl-prefix}}_{{name}}., ]]')
    print('I parseList', parseList)
    print('I MultiList', MultiList(parseList, test_table()))
    print('I toString', MultiList(parseList, test_table()).toString())

    assert parseList == [
        'tbl-fields', ['crud', ['C', 'c']], '{{tbl-prefix}}_{{name}}', ', '
    ]
    assert MultiList(parseList, test_table()) == ['reg_type', 'reg_password']
    assert MultiList(parseList,
                     test_table()).toString() == 'reg_type, reg_password'

    print('#########')

    # '[[db-extensions.*:*.create extension IF NOT EXISTS {{name}}.; ]]'
    #pprint(test_db())
    parseList = ParseTagToList(
        '[[db-extensions.*:*.create extension IF NOT EXISTS {{name}};.; ]]')
    print('J parseList', parseList)
    print('J MultiList', MultiList(parseList, test_db()))
    print('J toString', MultiList(parseList, test_db()).toString())

    assert parseList == [
        'db-extensions', ['*', '*'],
        'create extension IF NOT EXISTS {{name}};', '; '
    ]
    assert MultiList(parseList, test_db()) == [
        'create extension IF NOT EXISTS pgcrypto;',
        'create extension IF NOT EXISTS pgtap;',
        'create extension IF NOT EXISTS pgjwt;',
        'create extension IF NOT EXISTS "uuid-ossp";'
    ]
    assert MultiList(parseList, test_db()).toString(
    ) == 'create extension IF NOT EXISTS pgcrypto;; create extension IF NOT EXISTS pgtap;; create extension IF NOT EXISTS pgjwt;; create extension IF NOT EXISTS "uuid-ossp";'

    print('#########')
    print('K Parse_WhereClause', Parse_WhereClause())
    print('K MultiList_WhereClause(MultiList)',
          MultiList_WhereClause(test_table()))
    print('K toString', MultiList_WhereClause(test_table()).toString())

    assert Parse_WhereClause() == [
        'tbl-fields', ['crud', ['I']],
        "{{tbl-prefix}}_{{name}} = cast(_json::jsonb ->> '{{name}}' as {{type}})",
        ' and '
    ]
    assert MultiList_WhereClause(test_table()) == [
        "reg_id = cast(_json::jsonb ->> 'id' as TEXT)",
        "reg_type = cast(_json::jsonb ->> 'type' as TEXT)"
    ]
    assert MultiList_WhereClause(test_table()).toString(
    ) == "reg_id = cast(_json::jsonb ->> 'id' as TEXT) and reg_type = cast(_json::jsonb ->> 'type' as TEXT)"

    print('#########')
    #"[[tbl-fields.crud:(Cc).{{tbl-prefix}}_{{name}}., ]]"
    ##
    #    parseList = ParseTagToList('[[api-test-forms..type:insert..select {{LB_PROJECT_prefix}}_schema.{{api-name}}(\'{{form}}\'::TEXT);]]')

    parseList = ParseTagToList(
        '[[api-test-forms..type:insert..select {{LB_PROJECT_prefix}}_schema.{{api-name}}(\'{{form}}\'::TEXT);]]'
    )
    print('L parseList', parseList)
    print(
        'L MultiList',
        MultiList(parseList,
                  InterfaceConfiguration('app').load(test_table())))
    print(
        'L toString',
        MultiList(parseList,
                  InterfaceConfiguration('app').load(test_table())).toString())

    assert parseList == [
        'api-test-forms', ['type', 'insert'],
        'select {{LB_PROJECT_prefix}}_schema.{{api-name}}(\'{{form}}\'::TEXT);'
    ]

    #                                                                                 ['select reg_schema.app(\'{                           "type": "app", "app-name": "my-test-app", "version": "1.0.0", "username": "******", "email": "*****@*****.**", "password": "******", "test": "insert"}\'::TEXT);']
    assert MultiList(
        parseList,
        InterfaceConfiguration('app').load(test_table())
    ) == [
        'select reg_schema.app(\'{"type": "app", "app-name": "my-test-app", "version": "1.0.0", "username": "******", "email": "*****@*****.**", "password": "******", "test": "insert"}\'::TEXT);'
    ]

    assert MultiList(
        parseList,
        InterfaceConfiguration('app').load(test_table())
    ).toString(
    ) == 'select reg_schema.app(\'{"type": "app", "app-name": "my-test-app", "version": "1.0.0", "username": "******", "email": "*****@*****.**", "password": "******", "test": "insert"}\'::TEXT);'

    print('#########')
    #"[[tbl-fields.crud:(Cc).{{tbl-prefix}}_{{name}}., ]]"
    ##
    parseList = ParseTagToList(
        '[[models.*:*.ALTER DATABASE {{LB_PROJECT_prefix}}_db SET "{{app-key}}" TO \'{{model}}\';]]'
    )
    print('M parseList', parseList)
    print('M MultiList', MultiList(parseList, test_db()))
    print('M toString', MultiList(parseList, test_db()).toString())

    assert parseList == [
        'models', ['*', '*'],
        'ALTER DATABASE {{LB_PROJECT_prefix}}_db SET "{{app-key}}" TO \'{{model}}\';'
    ]

    #assert MultiList(parseList, test_db()) == ['ALTER DATABASE reg_db SET "app.jwt_secret" TO \'PASSWORD.must.BE.AT.LEAST.32.CHARS.LONG\';']

    #assert MultiList(parseList, test_db()).toString() == 'ALTER DATABASE reg_db SET "app.jwt_secret" TO \'PASSWORD.must.BE.AT.LEAST.32.CHARS.LONG\';'
    print('#########')

    ##
    parseList = ParseTagToList(
        '[[api-privileges..type:FUNCTION..GRANT {{privilege}} ON {{type}} {{LB_PROJECT_prefix}}_schema.{{api-name}} ({{parameters}}) TO {{role}};]]'
    )
    print('N parseList', parseList)
    print(
        'N MultiList',
        MultiList(parseList,
                  InterfaceConfiguration('app').load(test_table())))
    print(
        'N toString',
        MultiList(parseList,
                  InterfaceConfiguration('app').load(test_table())).toString())

    assert parseList == [
        'api-privileges', ['type', 'FUNCTION'],
        'GRANT {{privilege}} ON {{type}} {{LB_PROJECT_prefix}}_schema.{{api-name}} ({{parameters}}) TO {{role}};'
    ]
    assert MultiList(
        parseList,
        InterfaceConfiguration('app').load(test_table())) == [
            'GRANT EXECUTE ON FUNCTION reg_schema.app (JSONB) TO anonymous;'
        ]
    assert MultiList(
        parseList,
        InterfaceConfiguration('app').load(test_table())).toString(
        ) == 'GRANT EXECUTE ON FUNCTION reg_schema.app (JSONB) TO anonymous;'

    print('#########')

    ##
    parseList = ParseTagToList('[[api-test-forms..type:insert..{{pattern}}]]')
    print('O parseList', parseList)
    print(
        'O MultiList',
        MultiList(parseList,
                  InterfaceConfiguration('user').load(test_table())))
    print(
        'O toString',
        MultiList(parseList,
                  InterfaceConfiguration('user').load(
                      test_table())).toString())

    assert parseList == ['api-test-forms', ['type', 'insert'], '{{pattern}}']
    assert MultiList(
        parseList,
        InterfaceConfiguration('user').load(test_table())) == [
            '{"username": "******", "role": "anonymous"}'
        ]
    assert MultiList(
        parseList,
        InterfaceConfiguration('user').load(test_table())).toString(
        ) == '{"username": "******", "role": "anonymous"}'

    print('#########')

    ##
    parseList = ParseTagToList(
        "[[api-test-forms..type:select..( matches( {{db-prefix}}_schema.{{api-name}}( {{token}}, {{form}} )::JSONB, {{expected}}, {{description}} )::JSONB ->> 'result' ) ->> 'token']]"
    )
    print('P parseList', parseList)
    print(
        'P MultiList',
        MultiList(parseList,
                  InterfaceConfiguration('app').load(test_table())))
    print(
        'P toString',
        MultiList(parseList,
                  InterfaceConfiguration('app').load(test_table())).toString())

    assert parseList == [
        'api-test-forms', ['type', 'select'],
        "( matches( {{db-prefix}}_schema.{{api-name}}( {{token}}, {{form}} )::JSONB, {{expected}}, {{description}} )::JSONB ->> 'result' ) ->> 'token'"
    ]
    assert MultiList(
        parseList,
        InterfaceConfiguration('app').load(test_table())
    ) == [
        '( matches( reg_schema.app( sign(\'{"username": "******", "role": "anonymous"}\', current_setting(\'app.jwt_secret\') ), {"id": "[email protected]"} )::JSONB, [a-zA-Z\\.0-9_]+, app - select and check token )::JSONB ->> \'result\' ) ->> \'token\''
    ]
    assert MultiList(
        parseList,
        InterfaceConfiguration('app').load(test_table())
    ).toString(
    ) == '( matches( reg_schema.app( sign(\'{"username": "******", "role": "anonymous"}\', current_setting(\'app.jwt_secret\') ), {"id": "[email protected]"} )::JSONB, [a-zA-Z\.0-9_]+, app - select and check token )::JSONB ->> \'result\' ) ->> \'token\''
    print('#########')

    ##
    parseList = ParseTagToList(
        "[[api-test-forms..type:insert..is ( {{db-prefix}}_schema.{{api-name}}( {{token}}, '{{form}}'::JSONB )::JSONB, {{expected}}, {{description}} );]]"
    )
    print('Q parseList', parseList)
    print(
        'Q MultiList',
        MultiList(parseList,
                  InterfaceConfiguration('app').load(test_table())))
    print(
        'Q toString',
        MultiList(parseList,
                  InterfaceConfiguration('app').load(test_table())).toString())

    assert parseList == [
        'api-test-forms', ['type', 'insert'],
        "is ( {{db-prefix}}_schema.{{api-name}}( {{token}}, '{{form}}'::JSONB )::JSONB, {{expected}}, {{description}} );"
    ]
    assert MultiList(
        parseList,
        InterfaceConfiguration('app').load(test_table())
    ) == [
        'is ( reg_schema.app( sign(\'{"username": "******", "role": "anonymous"}\', current_setting(\'app.jwt_secret\')), \'{"type": "app", "app-name": "my-test-app", "version": "1.0.0", "username": "******", "email": "*****@*****.**", "password": "******", "test": "insert"}\'::JSONB )::JSONB, \'{"status": "200", "msg": "ok"}\'::JSONB, \'app - insert test\'::TEXT );'
    ]
    assert MultiList(
        parseList,
        InterfaceConfiguration('app').load(test_table())
    ).toString(
    ) == 'is ( reg_schema.app( sign(\'{"username": "******", "role": "anonymous"}\', current_setting(\'app.jwt_secret\')), \'{"type": "app", "app-name": "my-test-app", "version": "1.0.0", "username": "******", "email": "*****@*****.**", "password": "******", "test": "insert"}\'::JSONB )::JSONB, \'{"status": "200", "msg": "ok"}\'::JSONB, \'app - insert test\'::TEXT );'
    print('#########')
    ##
    parseList = ParseTagToList("[[LB_PROJECT_prefix]]")
    print('R parseList', parseList)
    print(
        'R MultiList',
        MultiList(parseList,
                  InterfaceConfiguration('app').load(test_table())))
    print(
        'R toString',
        MultiList(parseList,
                  InterfaceConfiguration('app').load(test_table())).toString())

    assert parseList == ['None', ['None', 'None'], '{{LB_PROJECT_prefix}}']
    assert MultiList(parseList,
                     InterfaceConfiguration('app').load(
                         test_table())) == ['reg']
    assert MultiList(parseList,
                     InterfaceConfiguration('app').load(
                         test_table())).toString() == 'reg'
    print('#########')
Esempio n. 16
0
def main():
    import pprint
    import os
    from test_func import test_table

    os.environ['LB-TESTING'] = '1'
    fields = FieldList(test_table())

    assert type(FieldList(test_table())) == FieldList
    assert len(FieldList(test_table())) > 0
    assert [f['name'] for f in FieldList(test_table())] == [
        'id', 'type', 'form', 'password', 'active', 'created', 'updated'
    ]
    print('required', [f['name'] for f in FieldList(test_table(), ['C'])])
    assert [f['name']
            for f in FieldList(test_table(), ['C'])] == ['type', 'password']
    assert [f['name'] for f in FieldList(test_table(), ['c'])] == []
    assert [f['name'] for f in FieldList(test_table(), ['C', 'c'])
            ] == ['type', 'password']
    assert [f['name']
            for f in FieldList(test_table(), ['I'])] == ['id', 'type']
    assert [f['name'] for f in FieldList(test_table(), ['U'])] == []
    assert [f['name']
            for f in FieldList(test_table(), ['u'])] == ['password', 'active']
    assert [f['name'] for f in FieldList(test_table(), ['u', 'U'])
            ] == ['password', 'active']
    assert [f['name'] for f in FieldList(test_table(), ['u', 'U', 'I'])
            ] == ['id', 'type', 'password', 'active']
    assert [f['name']
            for f in FieldList(test_table(), ['R'])] == ['id', 'type', 'form']
    assert [f['name'] for f in FieldList(test_table(), ['r'])
            ] == ['active', 'created', 'updated']
    assert [f['name'] for f in FieldList(test_table(), ['r', 'R'])
            ] == ['id', 'type', 'form', 'active', 'created', 'updated']

    os.environ['LB-TESTING'] = '0'