This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates
DbtCloudCredentials
to implement CredentialsBlock
interfa…
…ce (#109) * Adds metadata client * Enhances docstrings * Adds tests * Adds changelog entry
- Loading branch information
1 parent
09d4202
commit 21d31e6
Showing
6 changed files
with
272 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
prefect>=2.7.2 | ||
prefect_shell>=0.1.0 | ||
sgqlc>=16.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import json | ||
from unittest.mock import MagicMock | ||
|
||
from prefect_dbt.cloud.clients import DbtCloudMetadataClient | ||
|
||
|
||
def test_metadata_client_query(monkeypatch): | ||
mock_response = { | ||
"data": { | ||
"metrics": [ | ||
{ | ||
"uniqueId": "metric.tpch.total_revenue", | ||
"name": "total_revenue", | ||
"packageName": "tpch", | ||
"tags": [], | ||
"label": "Total Revenue ($)", | ||
"runId": 108952046, | ||
"description": "", | ||
"type": "sum", | ||
"sql": "net_item_sales_amount", | ||
"timestamp": "order_date", | ||
"timeGrains": ["day", "week", "month"], | ||
"dimensions": ["status_code", "priority_code"], | ||
"meta": {}, | ||
"resourceType": "metric", | ||
"filters": [], | ||
"model": {"name": "fct_orders"}, | ||
} | ||
] | ||
} | ||
} | ||
urlopen_mock = MagicMock() | ||
urlopen_mock.getcode.return_value = 200 | ||
urlopen_mock.return_value = urlopen_mock | ||
urlopen_mock.read.return_value = json.dumps(mock_response).encode() | ||
urlopen_mock.__enter__.return_value = urlopen_mock | ||
monkeypatch.setattr("urllib.request.urlopen", urlopen_mock) | ||
dbt_cloud_metadata_client = DbtCloudMetadataClient(api_key="my_api_key") | ||
mock_query = """ | ||
{ | ||
metrics(jobId: 123) { | ||
uniqueId | ||
name | ||
packageName | ||
tags | ||
label | ||
runId | ||
description | ||
type | ||
sql | ||
timestamp | ||
timeGrains | ||
dimensions | ||
meta | ||
resourceType | ||
filters { | ||
field | ||
operator | ||
value | ||
} | ||
model { | ||
name | ||
} | ||
} | ||
} | ||
""" | ||
assert dbt_cloud_metadata_client.query(mock_query) == mock_response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import pytest | ||
|
||
from prefect_dbt import DbtCloudCredentials | ||
from prefect_dbt.cloud.clients import ( | ||
DbtCloudAdministrativeClient, | ||
DbtCloudMetadataClient, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def dbt_cloud_credentials(): | ||
return DbtCloudCredentials(api_key="my_api_key", account_id=123456789) | ||
|
||
|
||
def test_get_administrative_client(dbt_cloud_credentials: DbtCloudCredentials): | ||
assert isinstance( | ||
dbt_cloud_credentials.get_administrative_client(), DbtCloudAdministrativeClient | ||
) | ||
|
||
|
||
def test_get_metadata_client(dbt_cloud_credentials: DbtCloudCredentials): | ||
assert isinstance( | ||
dbt_cloud_credentials.get_metadata_client(), DbtCloudMetadataClient | ||
) | ||
|
||
|
||
def test_get_client(dbt_cloud_credentials: DbtCloudCredentials): | ||
assert isinstance( | ||
dbt_cloud_credentials.get_client("administrative"), DbtCloudAdministrativeClient | ||
) | ||
assert isinstance( | ||
dbt_cloud_credentials.get_client("metadata"), DbtCloudMetadataClient | ||
) | ||
with pytest.raises(ValueError, match="'blorp' is not a supported client type"): | ||
dbt_cloud_credentials.get_client("blorp") |