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, }
def test_api_model_to_internal(api_model): husky_model = FdqModelMapper.to_internal(api_model, _VIRTUAL_DATA_SOURCE, 'company_id') assert husky_model.to_primitive() == { 'data_sources': [_VIRTUAL_DATA_SOURCE], 'fully_qualified_name_parts': api_model.data_source.split('.'), 'model_type': 'metric', 'attributes': { attr.taxon: attr.to_primitive() for api_attr in api_model.attributes for attr in FdqModelAttributeMapper.to_internal( api_attr, _VIRTUAL_DATA_SOURCE, set(api_model.identifiers)) }, 'company_id': 'company_id', 'joins': [ FdqModelJoinMapper.to_internal( join, _VIRTUAL_DATA_SOURCE).to_primitive() for join in api_model.joins ], 'name': prefix_with_virtual_data_source(_VIRTUAL_DATA_SOURCE, api_model.model_name), 'project_id': None, 'visibility': api_model.visibility.name, }
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) ], }
def test_api_model_attribute_to_internal(model_attr): identifiers = {'taxon_slug'} attrs = FdqModelAttributeMapper.to_internal(model_attr, _VIRTUAL_DATA_SOURCE, identifiers) assert [attr.to_primitive() for attr in attrs] == [{ 'tel_transformation': model_attr.data_reference, 'taxon': prefix_with_virtual_data_source(_VIRTUAL_DATA_SOURCE, model_attr.field_map[0]), 'identifier': model_attr.field_map[0] in identifiers, 'quantity_type': ValueQuantityType.scalar.value, }]