コード例 #1
0
def test_apply_default_attr():
    """ should index map into many index structure """
    index = Index()
    r = index.apply_default_fields(build_map()[0])
    assert 'BankApp' in r['app_name']
    assert 'id' in r['map']['Conta']['fields']
    assert 'meta_instance_id' in r['map']['Conta']['fields']
コード例 #2
0
def test_parse():
    """ should index map into many index structure """
    index = Index()
    index.parse(build_map())
    assert 'BankApp' in index.model_cache
    assert 'Conta' in index.model_cache['BankApp']
    assert 'fields' in index.model_cache['BankApp']['Conta']
    assert 'attributes' in index.projection_cache['BankApp']['Conta']
コード例 #3
0
def test_get_filters_with_optional_params_all_not_passed():
    query = {"filter": "filtro_opcional"}
    index = Index()
    index.parse(build_map())
    _filter = Transform(index).get_filters('BankApp', 'Conta', query)
    assert 'params' in _filter
    assert 'query' in _filter
    assert _filter['query'] == ""
コード例 #4
0
def test_get_projection():
    index = Index()
    index.parse(build_map())
    proj = index.get_projection("BankApp")
    assert 'Conta' in proj
    assert 'attributes' in proj['Conta']
    for p in proj['Conta']['attributes']:
        assert p[0] == p[1]
コード例 #5
0
def test_get_filters_with_optional_params_list():
    query = {"filter": "filtro_opcional_2", "ids": "1;2"}
    index = Index()
    index.parse(build_map())
    _filter = Transform(index).get_filters('BankApp', 'Conta', query)
    assert 'params' in _filter
    assert 'query' in _filter
    assert _filter['query'] == "id in (:ids0,:ids1)"
コード例 #6
0
def test_get_filters_with_in_filters_double():
    query = {"filter": "lista_ids", "ids": "1.5;2.0;3.1"}
    index = Index()
    index.parse(build_map())
    _filter = Transform(index).get_filters('BankApp', 'Conta', query)
    assert 'params' in _filter
    assert 'query' in _filter
    assert "ids" not in _filter["params"]
    assert "ids0" in _filter["params"]
    assert "ids1" in _filter["params"]
    assert "ids2" in _filter["params"]
コード例 #7
0
 def build(self):
     if not MapBuilder.cache_enable or not MapBuilder.loaded:
         maps = Loader().build()
         index = Index()
         index.parse(maps)
         transform = Transform(index)
         translator = Translator(index)
         MapBuilder.built = Mapper(index, transform, translator)
         MapBuilder.loaded = True
         MapBuilder.loaded_at = datetime.datetime.now()
     return MapBuilder.built
コード例 #8
0
def test_to_domain_without_metadata():
    index = Index()
    index.parse(build_map())
    mapped = {
        "saldo":10,
        "titular": "teste"
    }
    domain = Translator(index).to_domain('BankApp',mapped)
    assert "saldo" in domain
    assert "titular" in domain
    assert domain["saldo"] == mapped["saldo"]
    assert domain["titular"] == mapped["titular"]
コード例 #9
0
def test_to_domain_with_wrong_type():
    index = Index()
    index.parse(build_map())
    mapped = {
        "saldo":10,
        "titular": "teste",
        "_metadata":{
            "type":"conta"
        }
    }
    with pytest.raises(AttributeError):
        Translator(index).to_domain('BankApp',mapped)
コード例 #10
0
def test_to_map_without_metadata():
    index = Index()
    index.parse(build_map())
    domain = {
        "id": "13123",
        "meta_instance_id":"1313123",
        "cl_saldo":10,
        "cl_titular": "teste"
    }
    mapped = Translator(index).to_map('BankApp',domain)
    assert "cl_saldo" in mapped
    assert "cl_titular" in mapped
コード例 #11
0
def test_get_filters():
    query = {
        "filter": "transferencia",
        "origem": "teste_origem",
        "destino": "teste_destino"
    }
    index = Index()
    index.parse(build_map())
    _filter = Transform(index).get_filters('BankApp', 'Conta', query)

    assert 'params' in _filter
    assert 'query' in _filter
コード例 #12
0
def test_get_filters_with_in_filters_integer_as_string():
    query = {"filter": "lista_ids1", "ids": "1;2;3"}
    index = Index()
    index.parse(build_map())
    _filter = Transform(index).get_filters('BankApp', 'Conta', query)
    assert 'params' in _filter
    assert 'query' in _filter
    assert "ids" not in _filter["params"]
    assert "ids0" in _filter["params"]
    assert "ids1" in _filter["params"]
    assert "ids2" in _filter["params"]
    assert type(_filter["params"]["ids0"]) is str
    assert type(_filter["params"]["ids1"]) is str
    assert type(_filter["params"]["ids2"]) is str
コード例 #13
0
def test_apply_function_fields():
    model = {
        "saldo": 10,
        "titular": "teste",
        "meta_instance_id": "123",
        "_metadata": {
            "type": "Conta"
        }
    }
    index = Index()
    index.parse(build_map())
    processed = Transform(index).apply_function_fields(model, 'BankApp',
                                                       'Conta', {})
    assert "premio" in processed
    assert processed["premio"] == 11
コード例 #14
0
def test_to_domain():
    index = Index()
    index.parse(build_map())
    mapped = {
        "saldo":10,
        "titular": "teste",
        "_metadata":{
            "type":"Conta"
        }
    }
    domain = Translator(index).to_domain('BankApp',mapped)
    assert "cl_saldo" in domain
    assert "cl_titular" in domain
    assert domain["cl_saldo"] == mapped["saldo"]
    assert domain["cl_titular"] == mapped["titular"]
コード例 #15
0
def test_to_map():
    index = Index()
    index.parse(build_map())
    domain = {
        "id": "13123",
        "meta_instance_id":"1313123",
        "cl_saldo":10,
        "cl_titular": "teste",
        "_metadata": {
            "type":"conta"
        }
    }
    mapped = Translator(index).to_map('BankApp',domain)

    assert "saldo" in mapped
    assert "titular" in mapped
    assert domain["cl_saldo"] == mapped["saldo"]
    assert domain["cl_titular"] == mapped["titular"]
コード例 #16
0
def test_apply_runtime_fields_with_instance_id():
    model = {"nome": "teste", "meta_instance_id": "123"}
    index = Index()
    processed = Transform(index).apply_runtime_fields('BankApp', 'Conta',
                                                      [model])
    assert '_metadata' in processed[0]
    assert 'type' in processed[0]['_metadata']
    assert processed[0]['_metadata']['type'] == 'Conta'
    assert not 'meta_instance_id' in processed[0]
    assert '123' in processed[0]['_metadata']['instance_id']
コード例 #17
0
def test_get_map_by_app_id_wrong():
    index = Index()
    index.parse(build_map())
    assert index.get_map('Wrong') == dict()
コード例 #18
0
def test_get_functions():
    index = Index()
    index.parse(build_map())
    assert "premio" in index.get_functions('BankApp', 'Conta')
コード例 #19
0
def test_replace_all_atributes():
    index = Index()
    assert Transform(index).replace_all_atributes(
        """ {"nome":"elvis"} """, "nome", "nome1") == """ {"nome1":"elvis"} """
コード例 #20
0
def test_get_filters_with_empty_params():
    query = dict()
    index = Index()
    index.parse(build_map())
    _filter = Transform(index).get_filters('BankApp', 'Conta', query)
    assert _filter == dict()
コード例 #21
0
def test_get_filters_with_wrong_app():
    query = dict()
    index = Index()
    index.parse(build_map())
    _filter = Transform(index).get_filters('WApp', 'donta', query)
    assert _filter == dict()
コード例 #22
0
def test_get_functions_without_functions():
    index = Index()
    index.parse(build_map())
    assert index.get_functions('BankApp', 'Pessoa') == dict()
コード例 #23
0
def test_get_filters_with_wrong_filter_name():
    query = {"filter": "wrong", "ids": "1.5;2.0;3.1"}
    index = Index()
    index.parse(build_map())
    _filter = Transform(index).get_filters('BankApp', 'Conta', query)
    assert _filter == {}
コード例 #24
0
def test_get_map_type_by_domain_type_wrong():
    index = Index()
    index.parse(build_map())
    assert index.get_map_type_by_domain_type('BankApp', 'wrong') == ""
コード例 #25
0
def test_get_map_type_by_domain_type():
    index = Index()
    index.parse(build_map())
    assert index.get_map_type_by_domain_type('BankApp', 'conta') == "Conta"
コード例 #26
0
def test_columns_from_map_type():
    index = Index()
    index.parse(build_map())
    _map = index.columns_from_map_type("BankApp", "Conta")
    for col, reference in _map:
        assert col == reference
コード例 #27
0
 def build_from_map(self, map_):
     index = Index()
     index.parse([map_])
     transform = Transform(index)
     translator = Translator(index)
     return Mapper(index, transform, translator)
コード例 #28
0
def test_get_map_by_app_id_and_name_wrong_name():
    index = Index()
    index.parse(build_map())
    assert index.get_map('BankApp', 'Wrong') == dict()
コード例 #29
0
def test_get_map_by_app_id_and_name():
    index = Index()
    index.parse(build_map())
    assert index.get_map('BankApp', 'Conta') != None
コード例 #30
0
def test_get_map_by_app_id():
    index = Index()
    index.parse(build_map())
    assert index.get_map('BankApp') != None