From 39c5c42215b4d6751e9644324040a1c716742224 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Mon, 14 Nov 2022 10:39:57 -0500 Subject: [PATCH] converting 044_test_run_operations (#6122) * converting 044_test_run_operations --- .../macros/sad_macros.sql | 7 -- .../044_run_operations_tests/models/model.sql | 1 - .../test_run_operations.py | 76 ------------- .../functional/run_operations/fixtures.py | 18 ++- .../run_operations/test_run_operations.py | 104 ++++++++++++++++++ 5 files changed, 121 insertions(+), 85 deletions(-) delete mode 100644 test/integration/044_run_operations_tests/macros/sad_macros.sql delete mode 100644 test/integration/044_run_operations_tests/models/model.sql delete mode 100644 test/integration/044_run_operations_tests/test_run_operations.py rename test/integration/044_run_operations_tests/macros/happy_macros.sql => tests/functional/run_operations/fixtures.py (82%) create mode 100644 tests/functional/run_operations/test_run_operations.py diff --git a/test/integration/044_run_operations_tests/macros/sad_macros.sql b/test/integration/044_run_operations_tests/macros/sad_macros.sql deleted file mode 100644 index 4f2c80bc40f..00000000000 --- a/test/integration/044_run_operations_tests/macros/sad_macros.sql +++ /dev/null @@ -1,7 +0,0 @@ -{% macro syntax_error() %} - {% if execute %} - {% call statement() %} - select NOPE NOT A VALID QUERY - {% endcall %} - {% endif %} -{% endmacro %} diff --git a/test/integration/044_run_operations_tests/models/model.sql b/test/integration/044_run_operations_tests/models/model.sql deleted file mode 100644 index 43258a71464..00000000000 --- a/test/integration/044_run_operations_tests/models/model.sql +++ /dev/null @@ -1 +0,0 @@ -select 1 as id diff --git a/test/integration/044_run_operations_tests/test_run_operations.py b/test/integration/044_run_operations_tests/test_run_operations.py deleted file mode 100644 index d0308abe9b9..00000000000 --- a/test/integration/044_run_operations_tests/test_run_operations.py +++ /dev/null @@ -1,76 +0,0 @@ -from test.integration.base import DBTIntegrationTest, use_profile -import yaml - - -class TestOperations(DBTIntegrationTest): - @property - def schema(self): - return "run_operations_044" - - @property - def models(self): - return "models" - - @property - def project_config(self): - return { - 'config-version': 2, - "macro-paths": ['macros'], - } - - def run_operation(self, macro, expect_pass=True, extra_args=None, **kwargs): - args = ['run-operation', macro] - if kwargs: - args.extend(('--args', yaml.safe_dump(kwargs))) - if extra_args: - args.extend(extra_args) - return self.run_dbt(args, expect_pass=expect_pass) - - @use_profile('postgres') - def test__postgres_macro_noargs(self): - self.run_operation('no_args') - self.assertTableDoesExist('no_args') - - @use_profile('postgres') - def test__postgres_macro_args(self): - self.run_operation('table_name_args', table_name='my_fancy_table') - self.assertTableDoesExist('my_fancy_table') - - @use_profile('postgres') - def test__postgres_macro_exception(self): - self.run_operation('syntax_error', False) - - @use_profile('postgres') - def test__postgres_macro_missing(self): - self.run_operation('this_macro_does_not_exist', False) - - @use_profile('postgres') - def test__postgres_cannot_connect(self): - self.run_operation('no_args', - extra_args=['--target', 'noaccess'], - expect_pass=False) - - @use_profile('postgres') - def test__postgres_vacuum(self): - self.run_dbt(['run']) - # this should succeed - self.run_operation('vacuum', table_name='model') - - @use_profile('postgres') - def test__postgres_vacuum_ref(self): - self.run_dbt(['run']) - # this should succeed - self.run_operation('vacuum_ref', ref_target='model') - - @use_profile('postgres') - def test__postgres_select(self): - self.run_operation('select_something', name='world') - - @use_profile('postgres') - def test__postgres_access_graph(self): - self.run_operation('log_graph') - - @use_profile('postgres') - def test__postgres_print(self): - # Tests that calling the `print()` macro does not cause an exception - self.run_operation('print_something') diff --git a/test/integration/044_run_operations_tests/macros/happy_macros.sql b/tests/functional/run_operations/fixtures.py similarity index 82% rename from test/integration/044_run_operations_tests/macros/happy_macros.sql rename to tests/functional/run_operations/fixtures.py index c5c6df4dc8a..f6ed82e20ec 100644 --- a/test/integration/044_run_operations_tests/macros/happy_macros.sql +++ b/tests/functional/run_operations/fixtures.py @@ -1,3 +1,4 @@ +happy_macros_sql = """ {% macro no_args() %} {% if execute %} {% call statement(auto_begin=True) %} @@ -53,4 +54,19 @@ {% macro print_something() %} {{ print("You're doing awesome!") }} -{% endmacro %} \ No newline at end of file +{% endmacro %} +""" + +sad_macros_sql = """ +{% macro syntax_error() %} + {% if execute %} + {% call statement() %} + select NOPE NOT A VALID QUERY + {% endcall %} + {% endif %} +{% endmacro %} +""" + +model_sql = """ +select 1 as id +""" diff --git a/tests/functional/run_operations/test_run_operations.py b/tests/functional/run_operations/test_run_operations.py new file mode 100644 index 00000000000..f91ef2d8359 --- /dev/null +++ b/tests/functional/run_operations/test_run_operations.py @@ -0,0 +1,104 @@ +import os +import pytest +import yaml + +from dbt.tests.util import ( + check_table_does_exist, + run_dbt +) +from tests.functional.run_operations.fixtures import ( + happy_macros_sql, + sad_macros_sql, + model_sql +) + + +class TestOperations: + @pytest.fixture(scope="class") + def models(self): + return {"model.sql": model_sql} + + @pytest.fixture(scope="class") + def macros(self): + return { + "happy_macros.sql": happy_macros_sql, + "sad_macros.sql": sad_macros_sql + } + + @pytest.fixture(scope="class") + def dbt_profile_data(self, unique_schema): + return { + "config": {"send_anonymous_usage_stats": False}, + "test": { + "outputs": { + "default": { + "type": "postgres", + "threads": 4, + "host": "localhost", + "port": int(os.getenv("POSTGRES_TEST_PORT", 5432)), + "user": os.getenv("POSTGRES_TEST_USER", "root"), + "pass": os.getenv("POSTGRES_TEST_PASS", "password"), + "dbname": os.getenv("POSTGRES_TEST_DATABASE", "dbt"), + "schema": unique_schema, + }, + "noaccess": { + "type": "postgres", + "threads": 4, + "host": "localhost", + "port": int(os.getenv("POSTGRES_TEST_PORT", 5432)), + "user": 'noaccess', + "pass": 'password', + "dbname": os.getenv("POSTGRES_TEST_DATABASE", "dbt"), + 'schema': unique_schema + } + }, + "target": "default", + }, + } + + def run_operation(self, macro, expect_pass=True, extra_args=None, **kwargs): + args = ['run-operation', macro] + if kwargs: + args.extend(('--args', yaml.safe_dump(kwargs))) + if extra_args: + args.extend(extra_args) + return run_dbt(args, expect_pass=expect_pass) + + def test_macro_noargs(self, project): + self.run_operation('no_args') + check_table_does_exist(project.adapter, 'no_args') + + def test_macro_args(self, project): + self.run_operation('table_name_args', table_name='my_fancy_table') + check_table_does_exist(project.adapter, 'my_fancy_table') + + def test_macro_exception(self, project): + self.run_operation('syntax_error', False) + + def test_macro_missing(self, project): + self.run_operation('this_macro_does_not_exist', False) + + def test_cannot_connect(self, project): + self.run_operation('no_args', + extra_args=['--target', 'noaccess'], + expect_pass=False) + + def test_vacuum(self, project): + run_dbt(['run']) + # this should succeed + self.run_operation('vacuum', table_name='model') + + def test_vacuum_ref(self, project): + run_dbt(['run']) + # this should succeed + self.run_operation('vacuum_ref', ref_target='model') + + def test_select(self, project): + self.run_operation('select_something', name='world') + + def test_access_graph(self, project): + self.run_operation('log_graph') + + def test_print(self, project): + # Tests that calling the `print()` macro does not cause an exception + self.run_operation('print_something')