This repository has been archived by the owner on Apr 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(dbt-fal): add source tests (#698)
* Add source freshness project * Add behave feature for testing sources * Add TODO tags to some integration tests
- Loading branch information
Showing
7 changed files
with
108 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
@TODO-duckdb | ||
@TODO-bigquery | ||
Feature: dbt-fal can query sources | ||
Background: Project Setup | ||
Given the project source_freshness | ||
|
||
Scenario: Run a Python model that queries a source in local environment | ||
When the following shell command is invoked: | ||
""" | ||
python $baseDir/load_freshness_table.py $baseDir $profilesDir | ||
""" | ||
And the following shell command is invoked: | ||
""" | ||
dbt run --profiles-dir $profilesDir --project-dir $baseDir | ||
""" | ||
Then the following models are calculated in order: | ||
| model_a | | ||
|
||
@cloud | ||
Scenario: Run a Python model that queries a source with Isolate Cloud | ||
When the following shell command is invoked: | ||
""" | ||
python $baseDir/load_freshness_table.py $baseDir $profilesDir | ||
""" | ||
And the following shell command is invoked: | ||
""" | ||
dbt run --profiles-dir $profilesDir --project-dir $baseDir -t prod | ||
""" | ||
Then the following models are calculated in order: | ||
| model_a | |
17 changes: 17 additions & 0 deletions
17
adapter/integration_tests/projects/source_freshness/dbt_project.yml
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,17 @@ | ||
name: "source_test" | ||
version: "1.0.0" | ||
config-version: 2 | ||
profile: "fal_test" | ||
|
||
model-paths: ["models"] | ||
seed-paths: ["data"] | ||
macro-paths: ["macros"] | ||
snapshot-paths: ["snapshots"] | ||
|
||
target-path: "{{ env_var('temp_dir') }}/target" | ||
|
||
vars: | ||
fal-scripts-path: "fal_scripts" | ||
|
||
models: | ||
+schema: custom |
8 changes: 8 additions & 0 deletions
8
adapter/integration_tests/projects/source_freshness/fal_project.yml
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,8 @@ | ||
environments: | ||
- name: not-funny | ||
type: venv | ||
|
||
- name: funny | ||
type: venv | ||
requirements: | ||
- pyjokes==0.6.0 |
22 changes: 22 additions & 0 deletions
22
adapter/integration_tests/projects/source_freshness/load_freshness_table.py
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,22 @@ | ||
from datetime import datetime as dt, timezone as tz | ||
from pandas import DataFrame | ||
from fal import FalDbt | ||
from sys import argv | ||
|
||
project_dir = argv[1] if len(argv) >= 2 else "." | ||
profiles_dir = argv[2] if len(argv) >= 3 else ".." | ||
|
||
faldbt = FalDbt(project_dir=project_dir, profiles_dir=profiles_dir) | ||
|
||
# 10 rows | ||
df = DataFrame({"loaded_at": dt.now(tz=tz.utc).isoformat(), "info": range(0, 10)}) | ||
|
||
print(df) | ||
faldbt.write_to_source(df, "freshness_test", "freshness_table", mode="overwrite") | ||
|
||
from time import sleep | ||
|
||
# Let BigQuery cache load it | ||
sleep(5) | ||
|
||
print("Loaded") |
8 changes: 8 additions & 0 deletions
8
adapter/integration_tests/projects/source_freshness/models/model_a.py
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,8 @@ | ||
def model(dbt, fal): | ||
dbt.config(materialized="table") | ||
dbt.config(fal_environment="funny") | ||
import pyjokes | ||
joke = pyjokes.get_joke() | ||
df = dbt.source("freshness_test", "freshness_table") | ||
df["my_joke"] = joke | ||
return df |
19 changes: 19 additions & 0 deletions
19
adapter/integration_tests/projects/source_freshness/models/schema.yml
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,19 @@ | ||
version: 2 | ||
|
||
sources: | ||
- name: freshness_test | ||
database: "{{ env_var('DBT_DATABASE', 'test') }}" | ||
schema: "{{ env_var('DBT_SCHEMA', 'dbt_fal_custom') }}" | ||
freshness: | ||
warn_after: { "count": 5, "period": minute } | ||
error_after: { "count": 30, "period": minute } | ||
tables: | ||
- name: "freshness_table" | ||
loaded_at_field: "current_timestamp" | ||
columns: | ||
- name: info | ||
tests: | ||
- unique | ||
|
||
models: | ||
- name: model_a |