def test_make_tag_for_dashboard_should_set_all_available_fields(self): tag_template_factory = prepare.DataCatalogTagTemplateFactory( 'project_id', 'us_central_1') template_id, template = tag_template_factory\ .make_tag_template_for_dashboard() metadata = [{ 'id': 'a123-b456', 'luid': 'c234-d567', 'path': 'test/dashboard', 'workbook': { 'luid': 'e345-f678', 'name': 'Test Workbook Name', 'site': { 'name': 'test-site' } } }] tags = datacatalog_tag_factory.DataCatalogTagFactory\ .make_tags_for_dashboards(template, metadata) tag = tags[0] self.assertEqual('a123-b456', tag.fields['id'].string_value) self.assertEqual('c234-d567', tag.fields['luid'].string_value) self.assertEqual('e345-f678', tag.fields['workbook_luid'].string_value) self.assertEqual('Test Workbook Name', tag.fields['workbook_name'].string_value) self.assertEqual('test-site', tag.fields['site_name'].string_value) self.assertEqual(True, tag.fields['has_external_url'].bool_value)
def test_make_tag_for_dashboard_no_ext_url_should_skip_field(self): tag_template_factory = prepare.DataCatalogTagTemplateFactory( 'project_id', 'us_central_1') template_id, template = tag_template_factory\ .make_tag_template_for_dashboard() metadata = [{'path': '', 'workbook': {'site': {}}}] tags = datacatalog_tag_factory.DataCatalogTagFactory\ .make_tags_for_dashboards(template, metadata) tag = tags[0] self.assertEqual(False, tag.fields['has_external_url'].bool_value)
def test_make_tag_for_workbook_no_upstream_tables_should_skip_field(self): tag_template_factory = prepare.DataCatalogTagTemplateFactory( 'project_id', 'us_central_1') template_id, template = tag_template_factory\ .make_tag_template_for_workbook() metadata = [{'site': {}}] tags = datacatalog_tag_factory.DataCatalogTagFactory\ .make_tags_for_workbooks(template, metadata) tag = tags[0] self.assertFalse('upstream_tables' in tag.fields)
def test_make_tag_for_sheet_no_external_url_should_set_all_fields(self): tag_template_factory = prepare.DataCatalogTagTemplateFactory( 'project_id', 'us_central_1') template_id, template = tag_template_factory\ .make_tag_template_for_sheet() metadata = [{'path': ''}] workbook_metadata = {'site': {}} tags = datacatalog_tag_factory.DataCatalogTagFactory\ .make_tags_for_sheets(template, metadata, workbook_metadata) tag = tags[0] self.assertEqual(False, tag.fields['has_external_url'].bool_value)
def test_make_tag_template_for_workbook(self): tag_template_factory = prepare.DataCatalogTagTemplateFactory( 'project_id', 'us_central_1') template_id, tag_template = tag_template_factory\ .make_tag_template_for_workbook() self.assertEqual('Tableau Workbook Metadata', tag_template.display_name) self.assertEqual(self.__STRING_TYPE, tag_template.fields['luid'].type.primitive_type) self.assertEqual('Unique identifier for the REST API', tag_template.fields['luid'].display_name) self.assertEqual(self.__STRING_TYPE, tag_template.fields['site_name'].type.primitive_type) self.assertEqual('Site name', tag_template.fields['site_name'].display_name) self.assertEqual( self.__STRING_TYPE, tag_template.fields['project_name'].type.primitive_type) self.assertEqual('Project name', tag_template.fields['project_name'].display_name) self.assertEqual( self.__STRING_TYPE, tag_template.fields['owner_username'].type.primitive_type) self.assertEqual('Owner username', tag_template.fields['owner_username'].display_name) self.assertEqual(self.__STRING_TYPE, tag_template.fields['owner_name'].type.primitive_type) self.assertEqual('Owner name', tag_template.fields['owner_name'].display_name) self.assertEqual( self.__STRING_TYPE, tag_template. fields['upstream_table_definition'].type.primitive_type) self.assertEqual( 'upstream_tables values meaning', tag_template.fields['upstream_table_definition'].display_name) self.assertEqual( self.__STRING_TYPE, tag_template.fields['upstream_tables'].type.primitive_type) self.assertEqual('Tables used by the workbook', tag_template.fields['upstream_tables'].display_name)
def test_make_tag_template_for_dashboard(self): tag_template_factory = prepare.DataCatalogTagTemplateFactory( 'project_id', 'us_central_1') template_id, tag_template = tag_template_factory\ .make_tag_template_for_dashboard() self.assertEqual('Tableau Dashboard Metadata', tag_template.display_name) self.assertEqual(self.__STRING_TYPE, tag_template.fields['id'].type.primitive_type) self.assertEqual('Unique identifier for the Metadata API', tag_template.fields['id'].display_name) self.assertEqual(self.__STRING_TYPE, tag_template.fields['luid'].type.primitive_type) self.assertEqual('Unique identifier for the REST API', tag_template.fields['luid'].display_name) self.assertEqual( self.__STRING_TYPE, tag_template.fields['workbook_luid'].type.primitive_type) self.assertEqual('Workbook identifier for the REST API', tag_template.fields['workbook_luid'].display_name) self.assertEqual( self.__STRING_TYPE, tag_template.fields['workbook_name'].type.primitive_type) self.assertEqual('Workbook name', tag_template.fields['workbook_name'].display_name) self.assertEqual( self.__STRING_TYPE, tag_template.fields['workbook_entry'].type.primitive_type) self.assertEqual('Data Catalog Entry for the Workbook', tag_template.fields['workbook_entry'].display_name) self.assertEqual(self.__STRING_TYPE, tag_template.fields['site_name'].type.primitive_type) self.assertEqual('Site name', tag_template.fields['site_name'].display_name) self.assertEqual( self.__BOOL_TYPE, tag_template.fields['has_external_url'].type.primitive_type) self.assertEqual('Has external URL', tag_template.fields['has_external_url'].display_name)
def test_make_tag_for_workbook_should_set_all_available_fields(self): tag_template_factory = prepare.DataCatalogTagTemplateFactory( 'project_id', 'us_central_1') template_id, template = tag_template_factory\ .make_tag_template_for_workbook() metadata = [{ 'luid': 'c234-d567', 'site': { 'name': 'test-site' }, 'projectName': 'Test Project Name', 'owner': { 'username': '******', 'name': 'Test User Name' }, 'upstreamTables': [{ 'fullName': '[Test schema].[Test table]', 'database': { 'luid': 'b234-c567' } }], 'upstreamDatabases': [{ 'luid': 'b234-c567', 'name': 'Test db', 'connectionType': 'Test conn' }] }] tags = datacatalog_tag_factory.DataCatalogTagFactory\ .make_tags_for_workbooks(template, metadata) tag = tags[0] self.assertEqual('c234-d567', tag.fields['luid'].string_value) self.assertEqual('test-site', tag.fields['site_name'].string_value) self.assertEqual('Test Project Name', tag.fields['project_name'].string_value) self.assertEqual('Test User Name', tag.fields['owner_name'].string_value) self.assertEqual('test-username', tag.fields['owner_username'].string_value) self.assertEqual('DATABASE NAME (CONNECTION TYPE) / TABLE NAME', tag.fields['upstream_table_definition'].string_value) self.assertEqual('Test db (Test conn)/[Test schema].[Test table]', tag.fields['upstream_tables'].string_value)
def test_make_tag_for_sheet_should_set_all_available_fields(self): tag_template_factory = prepare.DataCatalogTagTemplateFactory( 'project_id', 'us_central_1') template_id, template = tag_template_factory\ .make_tag_template_for_sheet() metadata = [{'id': 'a123-b456', 'path': 'test/sheet'}] workbook_metadata = { 'name': 'Test Workbook Name', 'site': { 'name': 'test-site' } } tags = datacatalog_tag_factory.DataCatalogTagFactory\ .make_tags_for_sheets(template, metadata, workbook_metadata) tag = tags[0] self.assertEqual('Test Workbook Name', tag.fields['workbook_name'].string_value) self.assertEqual('test-site', tag.fields['site_name'].string_value) self.assertEqual(True, tag.fields['has_external_url'].bool_value)
def test_make_tag_for_workbook_no_upstream_databases_should_succeed(self): tag_template_factory = prepare.DataCatalogTagTemplateFactory( 'project_id', 'us_central_1') template_id, template = tag_template_factory\ .make_tag_template_for_workbook() metadata = [{ 'site': {}, 'upstreamTables': [{ 'fullName': '[Test schema].[Test table]', 'database': { 'luid': 'b234-c567' } }] }] tags = datacatalog_tag_factory.DataCatalogTagFactory\ .make_tags_for_workbooks(template, metadata) tag = tags[0] self.assertEqual('/[Test schema].[Test table]', tag.fields['upstream_tables'].string_value)
def __init__(self, tableau_server_address, tableau_api_version, tableau_username, tableau_password, datacatalog_project_id, datacatalog_location_id, asset_types, tableau_site=None): super().__init__() self.__project_id = datacatalog_project_id self.__location_id = datacatalog_location_id self.__asset_types = asset_types self.__site_content_url = tableau_site self._metadata_scraper = scrape.MetadataScraper( server_address=tableau_server_address, api_version=tableau_api_version, username=tableau_username, password=tableau_password, site_content_url=tableau_site) self._entry_factory = \ prepare.AssembledEntryFactory( project_id=datacatalog_project_id, location_id=datacatalog_location_id, entry_group_id=self.__ENTRY_GROUP_ID, user_specified_system=self.__SPECIFIED_SYSTEM, server_address=tableau_server_address) self._tag_template_factory = \ prepare.DataCatalogTagTemplateFactory( project_id=datacatalog_project_id, location_id=datacatalog_location_id)