|
23 | 23 | PowerBIDashboard, |
24 | 24 | PowerBiTable, |
25 | 25 | PowerBITableSource, |
| 26 | + ReportPage, |
26 | 27 | UpstreaDataflow, |
27 | 28 | ) |
28 | 29 | from metadata.utils import fqn |
@@ -741,3 +742,87 @@ def test_create_dataset_upstream_dataset_column_lineage(self): |
741 | 742 | self.assertEqual( |
742 | 743 | result[0].toColumn.root, "service.downstream_dataset.orders.order_id" |
743 | 744 | ) |
| 745 | + |
| 746 | + @pytest.mark.order(13) |
| 747 | + def test_get_report_url(self): |
| 748 | + """ |
| 749 | + Test report URL generation with different page scenarios |
| 750 | + """ |
| 751 | + from unittest.mock import MagicMock |
| 752 | + |
| 753 | + workspace_id = "test-workspace-123" |
| 754 | + dashboard_id = "test-dashboard-456" |
| 755 | + |
| 756 | + # Create a mock client with api_client |
| 757 | + mock_api_client = MagicMock() |
| 758 | + self.powerbi.client = MagicMock() |
| 759 | + self.powerbi.client.api_client = mock_api_client |
| 760 | + |
| 761 | + # Test with multiple pages - should use first page name |
| 762 | + with patch( |
| 763 | + "metadata.ingestion.source.dashboard.powerbi.metadata.clean_uri" |
| 764 | + ) as mock_clean_uri: |
| 765 | + mock_clean_uri.return_value = "https://app.powerbi.com" |
| 766 | + mock_api_client.fetch_report_pages.return_value = [ |
| 767 | + ReportPage(name="page1", displayName="Page 1"), |
| 768 | + ReportPage(name="page2", displayName="Page 2"), |
| 769 | + ReportPage(name="page3", displayName="Page 3"), |
| 770 | + ] |
| 771 | + |
| 772 | + result = self.powerbi._get_report_url(workspace_id, dashboard_id) |
| 773 | + |
| 774 | + mock_api_client.fetch_report_pages.assert_called_once_with( |
| 775 | + workspace_id, dashboard_id |
| 776 | + ) |
| 777 | + self.assertEqual( |
| 778 | + result, |
| 779 | + f"https://app.powerbi.com/groups/{workspace_id}/reports/{dashboard_id}/page1?experience=power-bi", |
| 780 | + ) |
| 781 | + |
| 782 | + # Test with single page - should use that page name |
| 783 | + with patch( |
| 784 | + "metadata.ingestion.source.dashboard.powerbi.metadata.clean_uri" |
| 785 | + ) as mock_clean_uri: |
| 786 | + mock_clean_uri.return_value = "https://app.powerbi.com" |
| 787 | + mock_api_client.fetch_report_pages.reset_mock() |
| 788 | + mock_api_client.fetch_report_pages.return_value = [ |
| 789 | + ReportPage(name="single-page", displayName="Single Page") |
| 790 | + ] |
| 791 | + |
| 792 | + result = self.powerbi._get_report_url(workspace_id, dashboard_id) |
| 793 | + |
| 794 | + self.assertEqual( |
| 795 | + result, |
| 796 | + f"https://app.powerbi.com/groups/{workspace_id}/reports/{dashboard_id}/single-page?experience=power-bi", |
| 797 | + ) |
| 798 | + |
| 799 | + # Test with no pages - should not add page_id |
| 800 | + with patch( |
| 801 | + "metadata.ingestion.source.dashboard.powerbi.metadata.clean_uri" |
| 802 | + ) as mock_clean_uri: |
| 803 | + mock_clean_uri.return_value = "https://app.powerbi.com" |
| 804 | + mock_api_client.fetch_report_pages.reset_mock() |
| 805 | + mock_api_client.fetch_report_pages.return_value = [] |
| 806 | + |
| 807 | + result = self.powerbi._get_report_url(workspace_id, dashboard_id) |
| 808 | + |
| 809 | + self.assertEqual( |
| 810 | + result, |
| 811 | + f"https://app.powerbi.com/groups/{workspace_id}/reports/{dashboard_id}?experience=power-bi", |
| 812 | + ) |
| 813 | + |
| 814 | + # Test with exception during fetch_report_pages - should handle gracefully |
| 815 | + with patch( |
| 816 | + "metadata.ingestion.source.dashboard.powerbi.metadata.clean_uri" |
| 817 | + ) as mock_clean_uri: |
| 818 | + mock_clean_uri.return_value = "https://app.powerbi.com" |
| 819 | + mock_api_client.fetch_report_pages.reset_mock() |
| 820 | + mock_api_client.fetch_report_pages.side_effect = Exception("API Error") |
| 821 | + |
| 822 | + result = self.powerbi._get_report_url(workspace_id, dashboard_id) |
| 823 | + |
| 824 | + # Should build URL without page_id when exception occurs |
| 825 | + self.assertEqual( |
| 826 | + result, |
| 827 | + f"https://app.powerbi.com/groups/{workspace_id}/reports/{dashboard_id}?experience=power-bi", |
| 828 | + ) |
0 commit comments