Exemplo n.º 1
0
def test_api_model_from_internal(husky_model):
    api_model = FdqModelMapper.from_internal(husky_model)
    assert api_model.dict(by_alias=True) == {
        'data_source':
        '.'.join(husky_model.fully_qualified_name_parts),
        'fields': [
            FdqModelAttributeMapper.from_internal(attr.tel_transformation,
                                                  [attr],
                                                  _VIRTUAL_DATA_SOURCE).dict()
            for attr in husky_model.attributes.values()
        ],
        'identifiers': [
            remove_virtual_data_source_prefix(_VIRTUAL_DATA_SOURCE, slug)
            for slug, a in husky_model.attributes.items() if a.identifier
        ],
        'joins': [
            FdqModelJoinMapper.from_internal(
                join, _VIRTUAL_DATA_SOURCE).dict(by_alias=True)
            for join in husky_model.joins
        ],
        'model_name':
        remove_virtual_data_source_prefix(_VIRTUAL_DATA_SOURCE,
                                          husky_model.name),
        'visibility':
        husky_model.visibility,
    }
Exemplo n.º 2
0
def test_api_model_attribute_from_internal(transformation, model_attrs):
    attr = FdqModelAttributeMapper.from_internal(transformation, model_attrs,
                                                 _VIRTUAL_DATA_SOURCE)

    assert attr.dict(by_alias=True) == {
        'data_reference':
        transformation,
        'field_map': [
            remove_virtual_data_source_prefix(_VIRTUAL_DATA_SOURCE,
                                              model_attrs[0].taxon)
        ],
    }