Skip to content

Commit

Permalink
rename resource class
Browse files Browse the repository at this point in the history
  • Loading branch information
benpankow committed Aug 7, 2024
1 parent 0a70410 commit 8671933
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from dagster._core.definitions.asset_spec import AssetSpec

from .resource import PowerBIResource
from .resource import PowerBiWorkspace
from .translator import (
DagsterPowerBITranslator,
PowerBIContentData,
Expand All @@ -12,20 +12,20 @@


def fetch_powerbi_workspace_data(
powerbi_resource: PowerBIResource,
powerbi_workspace: PowerBiWorkspace,
) -> PowerBIWorkspaceData:
"""Retrieves all Power BI content from the workspace and returns it as a PowerBIWorkspaceData object.
Future work will cache this data to avoid repeated calls to the Power BI API.
Args:
powerbi_resource (PowerBIResource): The Power BI resource to use to fetch the data.
powerbi_workspace (PowerBiWorkspace): The Power BI resource to use to fetch the data.
Returns:
PowerBIWorkspaceData: A snapshot of the Power BI workspace's content.
"""
dashboard_data = powerbi_resource.get_dashboards()["value"]
dashboard_data = powerbi_workspace.get_dashboards()["value"]
augmented_dashboard_data = [
{**dashboard, "tiles": powerbi_resource.get_dashboard_tiles(dashboard["id"])}
{**dashboard, "tiles": powerbi_workspace.get_dashboard_tiles(dashboard["id"])}
for dashboard in dashboard_data
]
dashboards = [
Expand All @@ -35,12 +35,12 @@ def fetch_powerbi_workspace_data(

reports = [
PowerBIContentData(content_type=PowerBIContentType.REPORT, properties=data)
for data in powerbi_resource.get_reports()["value"]
for data in powerbi_workspace.get_reports()["value"]
]
semantic_models_data = powerbi_resource.get_semantic_models()["value"]
semantic_models_data = powerbi_workspace.get_semantic_models()["value"]
data_sources_by_id = {}
for dataset in semantic_models_data:
dataset_sources = powerbi_resource.get_semantic_model_sources(dataset["id"])["value"]
dataset_sources = powerbi_workspace.get_semantic_model_sources(dataset["id"])["value"]
dataset["sources"] = [source["datasourceId"] for source in dataset_sources]
for data_source in dataset_sources:
data_sources_by_id[data_source["datasourceId"]] = PowerBIContentData(
Expand All @@ -60,22 +60,22 @@ def fetch_powerbi_workspace_data(

def build_powerbi_asset_specs(
*,
powerbi_resource: PowerBIResource,
powerbi_workspace: PowerBiWorkspace,
dagster_powerbi_translator: Type[DagsterPowerBITranslator] = DagsterPowerBITranslator,
) -> Sequence[AssetSpec]:
"""Fetches Power BI content from the workspace and translates it into AssetSpecs,
using the provided translator.
Future work will cache this data to avoid repeated calls to the Power BI API.
Args:
powerbi_resource (PowerBIResource): The Power BI resource to use to fetch the data.
powerbi_workspace (PowerBiWorkspace): The Power BI resource to use to fetch the data.
dagster_powerbi_translator (Type[DagsterPowerBITranslator]): The translator to use
to convert Power BI content into AssetSpecs. Defaults to DagsterPowerBITranslator.
Returns:
Sequence[AssetSpec]: A list of AssetSpecs representing the Power BI content.
"""
workspace_data = fetch_powerbi_workspace_data(powerbi_resource)
workspace_data = fetch_powerbi_workspace_data(powerbi_workspace)
translator = dagster_powerbi_translator(context=workspace_data)

all_content = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import uuid

from dagster._core.definitions.asset_key import AssetKey
from dagster_powerbi import PowerBIResource
from dagster_powerbi import PowerBiWorkspace


def test_fetch_powerbi_workspace_data(workspace_data_api_mocks: None, workspace_id: str) -> None:
fake_token = uuid.uuid4().hex
resource = PowerBIResource(
resource = PowerBiWorkspace(
api_token=fake_token,
workspace_id=workspace_id,
)
from dagster_powerbi.asset_specs import fetch_powerbi_workspace_data

actual_workspace_data = fetch_powerbi_workspace_data(powerbi_resource=resource)
actual_workspace_data = fetch_powerbi_workspace_data(powerbi_workspace=resource)
assert len(actual_workspace_data.dashboards_by_id) == 1
assert len(actual_workspace_data.reports_by_id) == 1
assert len(actual_workspace_data.semantic_models_by_id) == 1
Expand All @@ -23,11 +23,11 @@ def test_translator_dashboard_spec(workspace_data_api_mocks: None, workspace_id:
from dagster_powerbi.asset_specs import build_powerbi_asset_specs

fake_token = uuid.uuid4().hex
resource = PowerBIResource(
resource = PowerBiWorkspace(
api_token=fake_token,
workspace_id=workspace_id,
)
all_asset_specs = build_powerbi_asset_specs(powerbi_resource=resource)
all_asset_specs = build_powerbi_asset_specs(powerbi_workspace=resource)

# 1 dashboard, 1 report, 1 semantic model, 2 data sources
assert len(all_asset_specs) == 5
Expand Down

0 comments on commit 8671933

Please sign in to comment.