def test_get_dashboard(self) -> None: with patch.object(GraphDatabase, 'driver'), patch.object( Neo4jProxy, '_execute_cypher_query') as mock_execute: mock_execute.return_value.single.side_effect = [{ 'cluster_name': 'cluster_name', 'uri': 'foo_dashboard://gold.bar/dashboard_id', 'url': 'http://www.foo.bar/dashboard_id', 'product': 'foobar', 'name': 'dashboard name', 'created_timestamp': 123456789, 'description': 'description', 'group_name': 'group_name', 'group_url': 'http://www.group_url.com', 'last_successful_run_timestamp': 9876543210, 'last_run_timestamp': 987654321, 'last_run_state': 'good_state', 'updated_timestamp': 123456654321, 'recent_view_count': 100, 'owners': [{ 'employee_type': 'teamMember', 'full_name': 'test_full_name', 'is_active': 'True', 'github_username': '******', 'slack_id': 'test_id', 'last_name': 'test_last_name', 'first_name': 'test_first_name', 'team_name': 'test_team', 'email': 'test_email', }, { 'employee_type': 'teamMember', 'full_name': 'test_full_name2', 'is_active': 'True', 'github_username': '******', 'slack_id': 'test_id2', 'last_name': 'test_last_name2', 'first_name': 'test_first_name2', 'team_name': 'test_team2', 'email': 'test_email2', }], 'tags': [{ 'key': 'tag_key1', 'tag_type': 'tag_type1' }, { 'key': 'tag_key2', 'tag_type': 'tag_type2' }], 'charts': [{ 'name': 'chart1' }, { 'name': 'chart2' }], 'queries': [{ 'name': 'query1' }, { 'name': 'query2', 'url': 'http://foo.bar/query', 'query_text': 'SELECT * FROM foo.bar' }], 'tables': [{ 'database': 'db1', 'name': 'table1', 'description': 'table description 1', 'cluster': 'cluster1', 'schema': 'schema1' }, { 'database': 'db2', 'name': 'table2', 'description': None, 'cluster': 'cluster2', 'schema': 'schema2' }] }, { 'cluster_name': 'cluster_name', 'uri': 'foo_dashboard://gold.bar/dashboard_id', 'url': 'http://www.foo.bar/dashboard_id', 'product': 'foobar', 'name': 'dashboard name', 'created_timestamp': 123456789, 'description': None, 'group_name': 'group_name', 'group_url': 'http://www.group_url.com', 'last_run_timestamp': None, 'last_run_state': None, 'updated_timestamp': None, 'recent_view_count': 0, 'owners': [], 'tags': [], 'charts': [], 'queries': [], 'tables': [] }] neo4j_proxy = Neo4jProxy(host='DOES_NOT_MATTER', port=0000) dashboard = neo4j_proxy.get_dashboard(id='dashboard_id') expected = DashboardDetail( uri='foo_dashboard://gold.bar/dashboard_id', cluster='cluster_name', group_name='group_name', group_url='http://www.group_url.com', product='foobar', name='dashboard name', url='http://www.foo.bar/dashboard_id', description='description', created_timestamp=123456789, last_successful_run_timestamp=9876543210, updated_timestamp=123456654321, last_run_timestamp=987654321, last_run_state='good_state', owners=[ User(email='test_email', first_name='test_first_name', last_name='test_last_name', full_name='test_full_name', is_active='True', github_username='******', team_name='test_team', slack_id='test_id', employee_type='teamMember', manager_fullname=''), User(email='test_email2', first_name='test_first_name2', last_name='test_last_name2', full_name='test_full_name2', is_active='True', github_username='******', team_name='test_team2', slack_id='test_id2', employee_type='teamMember', manager_fullname='') ], frequent_users=[], chart_names=['chart1', 'chart2'], query_names=['query1', 'query2'], queries=[ DashboardQuery(name='query1'), DashboardQuery(name='query2', url='http://foo.bar/query', query_text='SELECT * FROM foo.bar') ], tables=[ PopularTable(database='db1', name='table1', description='table description 1', cluster='cluster1', schema='schema1'), PopularTable(database='db2', name='table2', cluster='cluster2', schema='schema2'), ], tags=[ Tag(tag_type='tag_type1', tag_name='tag_key1'), Tag(tag_type='tag_type2', tag_name='tag_key2') ], recent_view_count=100) self.assertEqual(expected, dashboard) dashboard2 = neo4j_proxy.get_dashboard(id='dashboard_id') expected2 = DashboardDetail( uri='foo_dashboard://gold.bar/dashboard_id', cluster='cluster_name', group_name='group_name', group_url='http://www.group_url.com', product='foobar', name='dashboard name', url='http://www.foo.bar/dashboard_id', description=None, created_timestamp=123456789, updated_timestamp=None, last_run_timestamp=None, last_run_state=None, owners=[], frequent_users=[], chart_names=[], query_names=[], tables=[], tags=[], last_successful_run_timestamp=None, recent_view_count=0) self.assertEqual(expected2, dashboard2)
def test_get_dashboard(self, mock_rds_client: Any) -> None: # dashboard_metadata dashboard = RDSDashboard( rk='foo_dashboard://gold.bar/dashboard_id', name='dashboard name', dashboard_url='http://www.foo.bar/dashboard_id', created_timestamp=123456789) dashboard_group = RDSDashboardGroup( name='group_name', dashboard_group_url='http://www.group_url.com') dashboard_group.cluster = RDSCluster(name='cluster_name') dashboard.group = dashboard_group dashboard.description = RDSDashboardDescription( description='description') dashboard.execution = [ RDSDashboardExecution(rk='dashboard_last_successful_execution', timestamp=9876543210), RDSDashboardExecution(rk='dashboard_last_execution', timestamp=987654321, state='good_state') ] dashboard.timestamp = RDSDashboardTimestamp(timestamp=123456654321) dashboard.tags = [ RDSTag(rk='tag_key1', tag_type='default'), RDSTag(rk='tag_key2', tag_type='default') ] dashboard.badges = [RDSBadge(rk='golden', category='table_status')] dashboard.owners = [ RDSUser(email='test_email', first_name='test_first_name', last_name='test_last_name', full_name='test_full_name', is_active=True, github_username='******', team_name='test_team', slack_id='test_id', employee_type='teamMember'), RDSUser(email='test_email2', first_name='test_first_name2', last_name='test_last_name2', full_name='test_full_name2', is_active=True, github_username='******', team_name='test_team2', slack_id='test_id2', employee_type='teamMember') ] dashboard.usage = [RDSDashboardUsage(read_count=100)] 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_session_query_filter = MagicMock() mock_session_query.filter.return_value = mock_session_query_filter mock_session_query_filter.first.return_value = dashboard # queries query1 = RDSDashboardQuery(name='query1') query2 = RDSDashboardQuery(name='query2', url='http://foo.bar/query', query_text='SELECT * FROM foo.bar') query1.charts = [RDSDashboardChart(name='chart1')] query2.charts = [RDSDashboardChart(name='chart2')] queries = [query1, query2] # tables database1 = RDSDatabase(name='db1') database2 = RDSDatabase(name='db2') cluster1 = RDSCluster(name='cluster1') cluster2 = RDSCluster(name='cluster2') schema1 = RDSSchema(name='schema1') schema2 = RDSSchema(name='schema2') table1 = RDSTable(name='table1') table2 = RDSTable(name='table2') description1 = RDSTableDescription(description='table description 1') schema1.cluster = cluster1 cluster1.database = database1 schema2.cluster = cluster2 cluster2.database = database2 table1.schema = schema1 table2.schema = schema2 table1.description = description1 tables = [table1, table2] mock_session_query_filter_options = MagicMock() mock_session_query_filter.options.return_value = mock_session_query_filter_options mock_session_query_filter_options.all.side_effect = [queries, tables] expected = DashboardDetail( uri='foo_dashboard://gold.bar/dashboard_id', cluster='cluster_name', group_name='group_name', group_url='http://www.group_url.com', product='foo', name='dashboard name', url='http://www.foo.bar/dashboard_id', description='description', created_timestamp=123456789, last_successful_run_timestamp=9876543210, updated_timestamp=123456654321, last_run_timestamp=987654321, last_run_state='good_state', owners=[ User(email='test_email', first_name='test_first_name', last_name='test_last_name', full_name='test_full_name', is_active=True, github_username='******', team_name='test_team', slack_id='test_id', employee_type='teamMember', manager_fullname=''), User(email='test_email2', first_name='test_first_name2', last_name='test_last_name2', full_name='test_full_name2', is_active=True, github_username='******', team_name='test_team2', slack_id='test_id2', employee_type='teamMember', manager_fullname='') ], frequent_users=[], chart_names=['chart1', 'chart2'], query_names=['query1', 'query2'], queries=[ DashboardQuery(name='query1'), DashboardQuery(name='query2', url='http://foo.bar/query', query_text='SELECT * FROM foo.bar') ], tables=[ PopularTable(database='db1', name='table1', description='table description 1', cluster='cluster1', schema='schema1'), PopularTable(database='db2', name='table2', cluster='cluster2', schema='schema2'), ], tags=[ Tag(tag_type='default', tag_name='tag_key1'), Tag(tag_type='default', tag_name='tag_key2') ], badges=[Badge(badge_name='golden', category='table_status')], recent_view_count=100) proxy = MySQLProxy() actual = proxy.get_dashboard(id='dashboard_id') self.assertEqual(expected, actual)
def test_get_dashboard(self) -> None: self.proxy.client.entity.get_entity_by_attribute = MagicMock( return_value=self.dashboard_data) # type: ignore self.proxy._get_dashboard_group = MagicMock( return_value=self.dashboard_group_data) # type: ignore self.proxy.client.entity.get_entities_by_guids = MagicMock( return_value=DottedDict({'entities': [DottedDict(self.entity1)]})) expected = DashboardDetail( uri='superset_dashboard://datalab.prod/1', cluster='datalab', group_name='prod superset', group_url='https://superset.prod', product='superset', name='Prod Usage', url='https://prod.superset/dashboards/1', description='Robs famous dashboard', created_timestamp=1619517099, updated_timestamp=1619626531, last_successful_run_timestamp=1619517099, last_run_timestamp=1619517150, last_run_state='failed', owners=[ User(user_id='lisa_salinas', email='lisa_salinas', first_name=None, last_name=None, full_name=None, display_name=None, is_active=True, github_username=None, team_name=None, slack_id=None, employee_type=None, manager_fullname=None, manager_email=None, manager_id=None, role_name=None, profile_url=None, other_key_values={}) ], frequent_users=[], chart_names=['Count Users by Time', 'Total Count'], query_names=['User Count By Time', 'Total Count'], queries=[ DashboardQuery( name='User Count By Time', url='https://prod.superset/dashboards/1/query/1', query_text='SELECT date, COUNT(1) FROM db.table GROUP BY 1' ), DashboardQuery( name='Total Count', url='https://prod.superset/dashboards/1/query/2', query_text='SELECT COUNT(1) FROM db.table') ], tables=[ PopularTable(database='hive_table', cluster='TEST_CLUSTER', schema='TEST_DB', name='Table1', description='Dummy Description') ], tags=[], badges=[], recent_view_count=0) result = self.proxy.get_dashboard( id='superset_dashboard://datalab.prod/1') self.assertEqual(expected, result)