From fef956fcaa42ad639d630f74ead45c17382e8a92 Mon Sep 17 00:00:00 2001 From: Mike Alfare <13974384+mikealfare@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:58:25 -0500 Subject: [PATCH] Fix testing migration (#102) --- .../adapter/column_types/test_column_types.py | 4 +- dbt/tests/adapter/hooks/data/seed_model.sql | 16 ++++++++ dbt/tests/adapter/hooks/data/seed_run.sql | 16 ++++++++ dbt/tests/adapter/hooks/fixtures.py | 40 ------------------- dbt/tests/adapter/hooks/test_model_hooks.py | 2 +- dbt/tests/adapter/hooks/test_run_hooks.py | 3 +- 6 files changed, 38 insertions(+), 43 deletions(-) create mode 100644 dbt/tests/adapter/hooks/data/seed_model.sql create mode 100644 dbt/tests/adapter/hooks/data/seed_run.sql diff --git a/dbt/tests/adapter/column_types/test_column_types.py b/dbt/tests/adapter/column_types/test_column_types.py index 1f99d610..995ac2b0 100644 --- a/dbt/tests/adapter/column_types/test_column_types.py +++ b/dbt/tests/adapter/column_types/test_column_types.py @@ -15,6 +15,8 @@ def run_and_test(self): results = run_dbt(["test"]) assert len(results) == 1 + +class BasePostgresColumnTypes(BaseColumnTypes): @pytest.fixture(scope="class") def models(self): return {"model.sql": fixtures.model_sql, "schema.yml": fixtures.schema_yml} @@ -23,5 +25,5 @@ def test_run_and_test(self, project): self.run_and_test() -class TestPostgresColumnTypes(BaseColumnTypes): +class TestPostgresColumnTypes(BasePostgresColumnTypes): pass diff --git a/dbt/tests/adapter/hooks/data/seed_model.sql b/dbt/tests/adapter/hooks/data/seed_model.sql new file mode 100644 index 00000000..6727acb3 --- /dev/null +++ b/dbt/tests/adapter/hooks/data/seed_model.sql @@ -0,0 +1,16 @@ +drop table if exists {schema}.on_model_hook; + +create table {schema}.on_model_hook ( + test_state TEXT, -- start|end + target_dbname TEXT, + target_host TEXT, + target_name TEXT, + target_schema TEXT, + target_type TEXT, + target_user TEXT, + target_pass TEXT, + target_threads INTEGER, + run_started_at TEXT, + invocation_id TEXT, + thread_id TEXT +); diff --git a/dbt/tests/adapter/hooks/data/seed_run.sql b/dbt/tests/adapter/hooks/data/seed_run.sql new file mode 100644 index 00000000..079ed34a --- /dev/null +++ b/dbt/tests/adapter/hooks/data/seed_run.sql @@ -0,0 +1,16 @@ +drop table if exists {schema}.on_run_hook; + +create table {schema}.on_run_hook ( + test_state TEXT, -- start|end + target_dbname TEXT, + target_host TEXT, + target_name TEXT, + target_schema TEXT, + target_type TEXT, + target_user TEXT, + target_pass TEXT, + target_threads INTEGER, + run_started_at TEXT, + invocation_id TEXT, + thread_id TEXT +); diff --git a/dbt/tests/adapter/hooks/fixtures.py b/dbt/tests/adapter/hooks/fixtures.py index 6f44aea6..c9f1e7da 100644 --- a/dbt/tests/adapter/hooks/fixtures.py +++ b/dbt/tests/adapter/hooks/fixtures.py @@ -360,43 +360,3 @@ 4,5,6 7,8,9 """ - - -tables__on_model_hook = """ -drop table if exists {schema}.on_model_hook; - -create table {schema}.on_model_hook ( - test_state TEXT, -- start|end - target_dbname TEXT, - target_host TEXT, - target_name TEXT, - target_schema TEXT, - target_type TEXT, - target_user TEXT, - target_pass TEXT, - target_threads INTEGER, - run_started_at TEXT, - invocation_id TEXT, - thread_id TEXT -); -""" - - -tables__on_run_hook = """ -drop table if exists {schema}.on_run_hook; - -create table {schema}.on_run_hook ( - test_state TEXT, -- start|end - target_dbname TEXT, - target_host TEXT, - target_name TEXT, - target_schema TEXT, - target_type TEXT, - target_user TEXT, - target_pass TEXT, - target_threads INTEGER, - run_started_at TEXT, - invocation_id TEXT, - thread_id TEXT -); -""" diff --git a/dbt/tests/adapter/hooks/test_model_hooks.py b/dbt/tests/adapter/hooks/test_model_hooks.py index 6f90b93d..6a544af0 100644 --- a/dbt/tests/adapter/hooks/test_model_hooks.py +++ b/dbt/tests/adapter/hooks/test_model_hooks.py @@ -73,7 +73,7 @@ class BaseTestPrePost: @pytest.fixture(scope="class", autouse=True) def setUp(self, project): - project.run_sql(fixtures.tables__on_model_hook) + project.run_sql_file(project.test_data_dir / Path("seed_model.sql")) def get_ctx_vars(self, state, count, project): fields = [ diff --git a/dbt/tests/adapter/hooks/test_run_hooks.py b/dbt/tests/adapter/hooks/test_run_hooks.py index 656c84f6..89565c70 100644 --- a/dbt/tests/adapter/hooks/test_run_hooks.py +++ b/dbt/tests/adapter/hooks/test_run_hooks.py @@ -1,4 +1,5 @@ import os +from pathlib import Path import pytest @@ -9,7 +10,7 @@ class BasePrePostRunHooks: @pytest.fixture(scope="function") def setUp(self, project): - project.run_sql(fixtures.tables__on_run_hook) + project.run_sql_file(project.test_data_dir / Path("seed_run.sql")) project.run_sql(f"drop table if exists { project.test_schema }.schemas") project.run_sql(f"drop table if exists { project.test_schema }.db_schemas") os.environ["TERM_TEST"] = "TESTING"