-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: add dbt test and fixtures #2580
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
78055db
add dbt test and fixtures
talagluck 2873e5c
remove unnecessary dependency
talagluck e32c07d
Merge branch 'main' into tal/add_dbt_test
talagluck f3adcd9
addressed code review comments
talagluck 0c01e15
add dbt dependency
talagluck 89dfe11
add dbt-core and dbt-postgres dependencies
talagluck c173482
update dependencies
talagluck 69387a6
Merge branch 'main' into tal/add_dbt_test
talagluck 5608a9e
update dependencies
talagluck 1ceb4bb
update credentials and dependencies
talagluck 5b25a4d
remove dbt-postgres dependency
talagluck bbe8858
poetry add
tychoish 2248ce0
Merge branch 'main' into tal/add_dbt_test
talagluck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,36 @@ | ||
|
||
# Name your project! Project names should contain only lowercase characters | ||
# and underscores. A good package name should reflect your organization's | ||
# name or the intended use of these models | ||
name: 'glaredb_dbt_test' | ||
version: '1.0.0' | ||
config-version: 2 | ||
|
||
# This setting configures which "profile" dbt uses for this project. | ||
profile: 'glaredb_dbt_test' | ||
|
||
# These configurations specify where dbt should look for different types of files. | ||
# The `model-paths` config, for example, states that models in this project can be | ||
# found in the "models/" directory. You probably won't need to change these! | ||
model-paths: ["models"] | ||
test-paths: ["tests"] | ||
macro-paths: ["macros"] | ||
snapshot-paths: ["snapshots"] | ||
|
||
clean-targets: # directories to be removed by `dbt clean` | ||
- "target" | ||
- "dbt_packages" | ||
|
||
|
||
# Configuring models | ||
# Full documentation: https://docs.getdbt.com/docs/configuring-models | ||
|
||
# In this example config, we tell dbt to build all models in the example/ | ||
# directory as views. These settings can be overridden in the individual model | ||
# files using the `{{ config(...) }}` macro. | ||
|
||
models: | ||
dbt_test: | ||
# Config indicated by + and applies to all files under models/example/ | ||
glaredb_data: | ||
+materialized: view |
2 changes: 2 additions & 0 deletions
2
tests/fixtures/dbt_project/models/glaredb_data/glaredb_model.sql
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,2 @@ | ||
select * | ||
from {{ source('public', 'dbt_test')}} |
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,7 @@ | ||
version: 2 | ||
|
||
sources: | ||
- name: public | ||
database: glaredb | ||
tables: | ||
- name: dbt_test |
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,12 @@ | ||
glaredb_dbt_test: | ||
outputs: | ||
test_target: | ||
dbname: glaredb | ||
host: 127.0.0.1 | ||
pass: "" | ||
port: 5432 | ||
schema: public | ||
threads: 1 | ||
type: postgres | ||
user: "{{ env_var('DBT_USER') }}" | ||
target: test_target |
Large diffs are not rendered by default.
Oops, something went wrong.
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,46 @@ | ||
import psycopg2.extensions | ||
import pytest | ||
import os | ||
|
||
from tests.fixtures.glaredb import glaredb_connection, debug_path | ||
|
||
from dbt.cli.main import dbtRunner, dbtRunnerResult | ||
|
||
|
||
def test_dbt_glaredb( | ||
glaredb_connection: psycopg2.extensions.connection, | ||
): | ||
dbt: dbtRunner = dbtRunner() | ||
|
||
os.environ["DBT_USER"] = glaredb_connection.info.user | ||
|
||
model_name: str = "glaredb_model" # TODO | ||
project_directory: str = "../fixtures/dbt_project/" # TODO | ||
dbt_profiles_directory: str = "../fixtures/dbt_project/" # TODO | ||
|
||
with glaredb_connection.cursor() as curr: | ||
curr.execute("create table dbt_test (amount int)") | ||
curr.execute( | ||
"INSERT INTO dbt_test (amount) VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9)" | ||
) | ||
|
||
cli_args: list = [ | ||
"run", | ||
"--project-dir", | ||
project_directory, | ||
"--profiles-dir", | ||
dbt_profiles_directory, | ||
"-m", | ||
model_name | ||
] | ||
# | ||
res: dbtRunnerResult = dbt.invoke(cli_args) | ||
|
||
# The below will currently fail. res contains the error message, but that message can be in different places based | ||
talagluck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# on where the failure is. Currently, it is under the top level `res.exception` key. | ||
# assert res.success is True | ||
# | ||
# with glaredb_connection.cursor() as curr: | ||
# query_result: list = curr.execute(f"select * from {model_name}").fetchall() | ||
# | ||
# assert len(query_result) == 10 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if you can just add this as an argument to the test to see if the magic pytest fixture thing works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you say more here? Are you suggesting I create a separate dbtRunner fixture?