Skip to content

Commit

Permalink
copy from existing test
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-winkler committed Oct 21, 2024
1 parent 01a9f46 commit 7688a82
Show file tree
Hide file tree
Showing 2 changed files with 234 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/functional/python_model_tests/fixtures.py
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 tests/functional/python_model_tests/test_override_dataproc_project.py
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)

0 comments on commit 7688a82

Please sign in to comment.