-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01a9f46
commit 7688a82
Showing
2 changed files
with
234 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
import pytest | ||
from dbt.tests.fixtures.project import write_project_files | ||
|
||
ALT_DATABASE = os.getenv("BIGQUERY_TEST_ALT_DATABASE") | ||
|
||
models__view_1_sql = """ | ||
select 1 as id | ||
""" | ||
|
||
models__python_model_py = """ | ||
def model(dbt, session): | ||
return dbt.ref("view_1") | ||
""" | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def models(): | ||
return { | ||
"view_1.sql": models__view_1_sql, | ||
"python_model.py": models__python_model_py, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def project_files( | ||
project_root, | ||
models, | ||
): | ||
write_project_files(project_root, "models", models) |
204 changes: 204 additions & 0 deletions
204
tests/functional/python_model_tests/test_override_dataproc_project.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,204 @@ | ||
import os | ||
from unittest.mock import patch | ||
|
||
from dbt.tests.util import run_dbt, check_relations_equal_with_relations | ||
from tests.unit.test_bigquery_adapter import BaseTestBigQueryAdapter | ||
|
||
from tests.functional.python_model_tests.files import SINGLE_RECORD # noqa: F401 | ||
|
||
ALT_DATABASE = os.getenv("BIGQUERY_TEST_ALT_DATABASE") | ||
|
||
""" | ||
dataset: dbt_mwinkler_core_dev | ||
keyfile: /Users/matt-winkler/Downloads/sales-demo-project-314714-2e886a5c2612.json | ||
method: service-account | ||
project: sales-demo-project-314714 | ||
threads: 4 | ||
type: bigquery | ||
gcs_bucket: matt-w-python-demo | ||
dataproc_cluster_name: matt-w-python-demo | ||
dataproc_region: us-west1 | ||
dataproc_project: test-some-other-project | ||
""" | ||
|
||
|
||
# Test application of dataproc_batch configuration to a | ||
# google.cloud.dataproc_v1.Batch object. | ||
# This reuses the machinery from BaseTestBigQueryAdapter to get hold of the | ||
# parsed credentials | ||
class TestOverrideDataprocProject(BaseTestBigQueryAdapter): | ||
@patch( | ||
"dbt.adapters.bigquery.connections.get_bigquery_defaults", | ||
return_value=("credentials", "project_id"), | ||
) | ||
def test_update_dataproc_cluster(self): | ||
adapter = self.get_adapter("dataproc-serverless-configured") | ||
raw_profile = self.raw_profile["outputs"]["dataproc-serverless-configured"][ | ||
"dataproc_batch" | ||
] | ||
print("showing raw_profile") | ||
print(raw_profile) | ||
|
||
|
||
# class BaseOverrideDatabase: | ||
# @pytest.fixture(scope="class") | ||
# def model_path(self): | ||
# return "models" | ||
|
||
# @pytest.fixture(scope="class") | ||
# def project_config_update(self): | ||
# return { | ||
# "config-version": 2, | ||
# "seed-paths": ["seeds"], | ||
# "vars": { | ||
# "alternate_db": ALT_DATABASE, | ||
# }, | ||
# "quoting": { | ||
# "database": True, | ||
# }, | ||
# "seeds": { | ||
# "quote_columns": False, | ||
# }, | ||
# } | ||
|
||
# @pytest.fixture(scope="function") | ||
# def clean_up(self, project): | ||
# yield | ||
# relation = project.adapter.Relation.create( | ||
# database=ALT_DATABASE, schema=project.test_schema | ||
# ) | ||
# project.adapter.drop_schema(relation) | ||
|
||
|
||
# class TestModelOverrideBigQuery(BaseOverrideDatabase): | ||
# def run_database_override(self, project): | ||
# run_dbt(["seed"]) | ||
# assert len(run_dbt(["run"])) == 4 | ||
# check_relations_equal_with_relations( | ||
# project.adapter, | ||
# [ | ||
# project.adapter.Relation.create(schema=project.test_schema, identifier="seed"), | ||
# project.adapter.Relation.create( | ||
# database=ALT_DATABASE, schema=project.test_schema, identifier="view_2" | ||
# ), | ||
# project.adapter.Relation.create(schema=project.test_schema, identifier="view_1"), | ||
# project.adapter.Relation.create(schema=project.test_schema, identifier="view_3"), | ||
# project.adapter.Relation.create( | ||
# database=ALT_DATABASE, schema=project.test_schema, identifier="view_4" | ||
# ), | ||
# ], | ||
# ) | ||
|
||
# def test_bigquery_database_override(self, project, clean_up): | ||
# self.run_database_override(project) | ||
|
||
|
||
# class BaseTestProjectModelOverrideBigQuery(BaseOverrideDatabase): | ||
# def run_database_override(self, project): | ||
# run_dbt(["seed"]) | ||
# assert len(run_dbt(["run"])) == 4 | ||
# self.assertExpectedRelations(project) | ||
|
||
# def assertExpectedRelations(self, project): | ||
# check_relations_equal_with_relations( | ||
# project.adapter, | ||
# [ | ||
# project.adapter.Relation.create(schema=project.test_schema, identifier="seed"), | ||
# project.adapter.Relation.create( | ||
# database=ALT_DATABASE, schema=project.test_schema, identifier="view_2" | ||
# ), | ||
# project.adapter.Relation.create( | ||
# database=ALT_DATABASE, schema=project.test_schema, identifier="view_1" | ||
# ), | ||
# project.adapter.Relation.create(schema=project.test_schema, identifier="view_3"), | ||
# project.adapter.Relation.create( | ||
# database=ALT_DATABASE, schema=project.test_schema, identifier="view_4" | ||
# ), | ||
# ], | ||
# ) | ||
|
||
|
||
# class TestProjectModelOverrideBigQuery(BaseTestProjectModelOverrideBigQuery): | ||
# @pytest.fixture(scope="class") | ||
# def project_config_update(self): | ||
# return { | ||
# "config-version": 2, | ||
# "models": { | ||
# "database": ALT_DATABASE, | ||
# "test": {"subfolder": {"database": "{{ target.database }}"}}, | ||
# }, | ||
# "seed-paths": ["seeds"], | ||
# "vars": { | ||
# "alternate_db": ALT_DATABASE, | ||
# }, | ||
# "quoting": { | ||
# "database": True, | ||
# }, | ||
# "seeds": { | ||
# "quote_columns": False, | ||
# }, | ||
# } | ||
|
||
# def test_bigquery_database_override(self, project, clean_up): | ||
# self.run_database_override(project) | ||
|
||
|
||
# class TestProjectModelAliasOverrideBigQuery(BaseTestProjectModelOverrideBigQuery): | ||
# @pytest.fixture(scope="class") | ||
# def project_config_update(self): | ||
# return { | ||
# "config-version": 2, | ||
# "models": { | ||
# "project": ALT_DATABASE, | ||
# "test": {"subfolder": {"project": "{{ target.database }}"}}, | ||
# }, | ||
# "seed-paths": ["seeds"], | ||
# "vars": { | ||
# "alternate_db": ALT_DATABASE, | ||
# }, | ||
# "quoting": { | ||
# "database": True, | ||
# }, | ||
# "seeds": { | ||
# "quote_columns": False, | ||
# }, | ||
# } | ||
|
||
# def test_bigquery_project_override(self, project, clean_up): | ||
# self.run_database_override(project) | ||
|
||
|
||
# class TestProjectSeedOverrideBigQuery(BaseOverrideDatabase): | ||
# @pytest.fixture(scope="class") | ||
# def project_config_update(self): | ||
# return { | ||
# "config-version": 2, | ||
# "seed-paths": ["seeds"], | ||
# "vars": { | ||
# "alternate_db": ALT_DATABASE, | ||
# }, | ||
# "seeds": {"database": ALT_DATABASE}, | ||
# } | ||
|
||
# def run_database_override(self, project): | ||
# run_dbt(["seed"]) | ||
# assert len(run_dbt(["run"])) == 4 | ||
# check_relations_equal_with_relations( | ||
# project.adapter, | ||
# [ | ||
# project.adapter.Relation.create( | ||
# database=ALT_DATABASE, schema=project.test_schema, identifier="seed" | ||
# ), | ||
# project.adapter.Relation.create( | ||
# database=ALT_DATABASE, schema=project.test_schema, identifier="view_2" | ||
# ), | ||
# project.adapter.Relation.create(schema=project.test_schema, identifier="view_1"), | ||
# project.adapter.Relation.create(schema=project.test_schema, identifier="view_3"), | ||
# project.adapter.Relation.create( | ||
# database=ALT_DATABASE, schema=project.test_schema, identifier="view_4" | ||
# ), | ||
# ], | ||
# ) | ||
|
||
# def test_bigquery_database_override(self, project, clean_up): | ||
# self.run_database_override(project) |