def test_get_tags(self) -> None: with patch.object(GraphDatabase, 'driver'), patch.object( Neo4jProxy, '_execute_cypher_query') as mock_execute: mock_execute.return_value = [{ 'tag_name': { 'key': 'tag1' }, 'tag_count': 2 }, { 'tag_name': { 'key': 'tag2' }, 'tag_count': 1 }] neo4j_proxy = Neo4jProxy(endpoint='bogus') actual = neo4j_proxy.get_tags() expected = [ TagDetail(tag_name='tag1', tag_count=2), TagDetail(tag_name='tag2', tag_count=1), ] self.assertEqual(actual.__repr__(), expected.__repr__())
def test_get_tags(self) -> None: tag_response = {'tagEntities': {'PII': 3, 'NON_PII': 2}} mocked_metrics = MagicMock() mocked_metrics.tag = tag_response self.proxy._driver.admin_metrics = [mocked_metrics] response = self.proxy.get_tags() expected = [ TagDetail(tag_name='PII', tag_count=3), TagDetail(tag_name='NON_PII', tag_count=2) ] self.assertEqual(expected.__repr__(), response.__repr__())
def get_tags(self) -> List: """ Fetch all the glossary terms from atlas, along with their assigned entities as this will be used to generate the autocomplete on the table detail page :return: A list of TagDetail Objects """ tags = [] params = { 'typeName': "AtlasGlossaryTerm", 'limit': 1000, 'offset': 0, 'excludeDeletedEntities': True, 'includeSubTypes': True, 'attributes': [ "assignedEntities", ] } glossary_terms = self.client.discovery.faceted_search( search_parameters=params) for item in glossary_terms.entities or list(): tags.append( TagDetail(tag_name=item.attributes.get("name"), tag_count=len( item.attributes.get("assignedEntities")))) return tags
def test_get_tags(self, mock_rds_client: Any) -> None: mock_client = MagicMock() mock_rds_client.return_value = mock_client mock_create_session = MagicMock() mock_client.create_session.return_value = mock_create_session mock_session = MagicMock() mock_create_session.__enter__.return_value = mock_session mock_session_query = MagicMock() mock_session.query.return_value = mock_session_query mock_outerjoin = MagicMock() mock_session_query.outerjoin.return_value = mock_outerjoin mock_outerjoin_outerjoin = MagicMock() mock_outerjoin.outerjoin.return_value = mock_outerjoin_outerjoin mock_outerjoin_outerjoin_filter = MagicMock() mock_outerjoin_outerjoin.filter.return_value = mock_outerjoin_outerjoin_filter mock_filter_groupby = MagicMock() mock_outerjoin_outerjoin_filter.group_by.return_value = mock_filter_groupby mock_groupby_having = MagicMock() mock_filter_groupby.having.return_value = mock_groupby_having mock_groupby_having.all.return_value = [ MagicMock(tag_name='tag1', tag_count=2), MagicMock(tag_name='tag2', tag_count=1) ] proxy = MySQLProxy() actual = proxy.get_tags() expected = [ TagDetail(tag_name='tag1', tag_count=2), TagDetail(tag_name='tag2', tag_count=1), ] self.assertEqual(expected.__repr__(), actual.__repr__())
def get_tags(self) -> List: """ Fetch all the classification entity definitions from atlas as this will be used to generate the autocomplete on the table detail page :return: A list of TagDetail Objects """ tags = [] for metrics in self._driver.admin_metrics: tag_stats = metrics.tag for tag, count in tag_stats["tagEntities"].items(): tags.append(TagDetail(tag_name=tag, tag_count=count)) return tags
def test_get_tags(self): name = "DUMMY_CLASSIFICATION" mocked_classif = MagicMock() mocked_classif.name = name mocked_def = MagicMock() mocked_def.classificationDefs = [mocked_classif] self.proxy._driver.typedefs = [mocked_def] response = self.proxy.get_tags() expected = [TagDetail(tag_name=name, tag_count=0)] self.assertEqual(response.__repr__(), expected.__repr__())
def get_tags(self) -> List: """ Fetch all the classification entity definitions from atlas as this will be used to generate the autocomplete on the table detail page :return: A list of TagDetail Objects """ tags = [] for type_def in self._driver.typedefs: for classification in type_def.classificationDefs: tags.append( TagDetail( tag_name=classification.name, tag_count=0 # FixMe (Verdan): Implement the tag count )) return tags
def test_get_tags(self) -> None: mocked_term = MagicMock() mocked_term.attributes = { "name": "PII", "assignedEntities": ["a", "b"] } result = MagicMock() result.entities = [mocked_term] self.proxy.client.discovery.faceted_search = MagicMock( return_value=result) response = self.proxy.get_tags() expected = [TagDetail(tag_name='PII', tag_count=2)] self.assertEqual(expected.__repr__(), response.__repr__())
def get_tags(self) -> List: """ Get all existing tags from neo4j :return: """ LOGGER.info('Get all the tags') query = textwrap.dedent(""" MATCH (t:Tag) OPTIONAL MATCH (tbl:Table)-[:TAGGED_BY]->(t) RETURN t as tag_name, count(distinct tbl.key) as tag_count """) records = self._execute_cypher_query(statement=query, param_dict={}) results = [] for record in records: results.append( TagDetail(tag_name=record['tag_name']['key'], tag_count=record['tag_count'])) return results
def get_tags(self) -> List: """ Get all existing tags from neo4j :return: """ LOGGER.info('Get all the tags') # todo: Currently all the tags are default type, we could open it up if we want to include badge query = textwrap.dedent(""" MATCH (t:Tag{tag_type: 'default'}) OPTIONAL MATCH (tbl:Table)-[:TAGGED_BY]->(t) RETURN t as tag_name, count(distinct tbl.key) as tag_count """) records = self._execute_cypher_query(statement=query, param_dict={}) results = [] for record in records: results.append(TagDetail(tag_name=record['tag_name']['key'], tag_count=record['tag_count'])) return results
def test_tag_rt(self) -> None: table = Fixtures.next_table() self.get_proxy().put_table(table=table) test_tag_detail = TagDetail(tag_name='a', tag_count=1) self.get_proxy().add_tag(id=checkNotNone(table.key), tag=test_tag_detail.tag_name, tag_type='default', resource_type=ResourceType.Table) tags_added = self.get_proxy().get_tags() self.assertIn(test_tag_detail, tags_added) self.get_proxy().delete_tag(id=checkNotNone(table.key), tag=test_tag_detail.tag_name, tag_type='default', resource_type=ResourceType.Table) tags_removed = self.get_proxy().get_tags() self.assertNotIn(test_tag_detail, tags_removed) relations = self.get_relationship(node_type1='Table', node_key1=checkNotNone(table.key), node_type2='Tag', node_key2=test_tag_detail.tag_name) self.assertEqual(0, len(relations))