def test_make_tag_for_table_metadata_should_set_all_available_fields( self): # noqa:E125 metadata_def = utils.Utils.get_metadata_def_obj(self.__MODULE_PATH) factory = datacatalog_tag_factory.DataCatalogTagFactory(metadata_def) tag_template = datacatalog.TagTemplate() tag_template.name = 'template_name' tables_dict = { 'creator': 'creator_test', 'owner': 'owner_test', 'update_user': '******', 'num_rows': 5, 'table_size_MB': 2.0, 'table_type': 'ROW', 'has_primary_key': 'TRUE' } tag = factory. \ make_tag_for_table_metadata(tag_template, tables_dict, 'schema') self.assertEqual('schema', tag.fields['schema_name'].string_value) self.assertEqual('creator_test', tag.fields['table_creator'].string_value) self.assertEqual('owner_test', tag.fields['table_owner'].string_value) self.assertEqual('update_user_test', tag.fields['table_update_user'].string_value) self.assertEqual(5, tag.fields['num_rows'].double_value) self.assertEqual(2.0, tag.fields['table_size_MB'].double_value) self.assertEqual('ROW', tag.fields['table_type'].string_value) self.assertEqual(True, tag.fields['has_primary_key'].bool_value)
def test_make_tags_for_columns_metadata_should_set_all_available_fields( self): # noqa:E125 metadata_def = utils.Utils.get_metadata_def_obj(self.__MODULE_PATH) factory = datacatalog_tag_factory.DataCatalogTagFactory(metadata_def) tag_template = datacatalog.TagTemplate() tag_template.name = 'template_name' tables_dict = { 'columns': [{ 'name': 'col_1', 'masked': 'TRUE', 'mask_expression': 'XXX-XXX-XXX' }, { 'name': 'col_2', 'masked': 'FALSE' }] } tags = factory. \ make_tags_for_columns_metadata(tag_template, tables_dict) tag_1 = tags[0] tag_2 = tags[1] self.assertEqual(True, tag_1.fields['masked'].bool_value) self.assertEqual('XXX-XXX-XXX', tag_1.fields['mask_expression'].string_value) self.assertEqual('col_1', tag_1.column) self.assertEqual(False, tag_2.fields['masked'].bool_value) self.assertIsNone(tag_2.fields.get('mask_expression')) self.assertEqual('col_2', tag_2.column)
def test_tag_for_table_zero_values_should_set_all_available_fields( # noqa:E501 self): # noqa:E125 metadata_def = utils.Utils.get_metadata_def_obj(self.__MODULE_PATH) factory = datacatalog_tag_factory.DataCatalogTagFactory(metadata_def) tag_template = datacatalog.TagTemplate() tag_template.name = 'template_name' tables_dict = { 'creator': 'creator_test', 'owner': 'owner_test', 'update_user': '******', 'num_rows': 0, 'table_size_MB': 0 } tag = factory. \ make_tag_for_table_metadata(tag_template, tables_dict, 'schema') self.assertEqual('schema', tag.fields['schema_name'].string_value) self.assertEqual('creator_test', tag.fields['table_creator'].string_value) self.assertEqual('owner_test', tag.fields['table_owner'].string_value) self.assertEqual('update_user_test', tag.fields['table_update_user'].string_value) self.assertEqual(0, tag.fields['num_rows'].double_value) self.assertEqual(0, tag.fields['table_size_MB'].double_value)
def test_tag_for_table_container_missing_fields_should_succeed( # noqa:E501 self): # noqa:E125 metadata_def = utils.Utils.get_metadata_def_obj(self.__MODULE_PATH) factory = datacatalog_tag_factory.DataCatalogTagFactory(metadata_def) tag_template = datacatalog.TagTemplate() tag_template.name = 'template_name' schema_dict = {'tables': [{}, {}]} tag = factory. \ make_tag_for_table_container_metadata(tag_template, schema_dict) self.assertEqual(2, tag.fields['num_tables'].double_value)
def test_make_tag_for_table_metadata_missing_fields_should_succeed( self): # noqa:E125 metadata_def = utils.Utils.get_metadata_def_obj(self.__MODULE_PATH) factory = datacatalog_tag_factory.DataCatalogTagFactory(metadata_def) tag_template = datacatalog.TagTemplate() tag_template.name = 'template_name' tables_dict = {'num_rows': 5} tag = factory. \ make_tag_for_table_metadata(tag_template, tables_dict, 'schema') self.assertEqual('schema', tag.fields['schema_name'].string_value) self.assertEqual(5, tag.fields['num_rows'].double_value)
def test_tag_for_table_container_should_set_all_available_fields( # noqa:E501 self): # noqa:E125 metadata_def = utils.Utils.get_metadata_def_obj(self.__MODULE_PATH) factory = datacatalog_tag_factory.DataCatalogTagFactory(metadata_def) tag_template = datacatalog.TagTemplate() tag_template.name = 'template_name' schema_dict = { 'creator': 'creator_test', 'owner': 'owner_test', 'update_user': '******', 'tables': [{}, {}] } tag = factory. \ make_tag_for_table_container_metadata(tag_template, schema_dict) self.assertEqual(2, tag.fields['num_tables'].double_value) self.assertEqual('creator_test', tag.fields['schema_creator'].string_value) self.assertEqual('owner_test', tag.fields['schema_owner'].string_value) self.assertEqual('update_user_test', tag.fields['schema_update_user'].string_value)