-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1406 from fishtown-analytics/fix/run-operation-re…
…turn-codes Fix run operation return codes (#1377)
- Loading branch information
Showing
5 changed files
with
125 additions
and
11 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
24 changes: 24 additions & 0 deletions
24
test/integration/044_run_operations_test/macros/happy_macros.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,24 @@ | ||
{% macro no_args() %} | ||
{% if execute %} | ||
{% call statement(auto_begin=True) %} | ||
create table "{{ schema }}"."no_args" (id int); | ||
commit; | ||
{% endcall %} | ||
{% endif %} | ||
{% endmacro %} | ||
|
||
|
||
{% macro table_name_args(table_name) %} | ||
{% if execute %} | ||
{% call statement(auto_begin=True) %} | ||
create table "{{ schema }}"."{{ table_name }}" (id int); | ||
commit; | ||
{% endcall %} | ||
{% endif %} | ||
{% endmacro %} | ||
|
||
{% macro vacuum(table_name) %} | ||
{% call statement(auto_begin=false) %} | ||
vacuum "{{ schema }}"."{{ table_name }}" | ||
{% endcall %} | ||
{% endmacro %} |
7 changes: 7 additions & 0 deletions
7
test/integration/044_run_operations_test/macros/sad_macros.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,7 @@ | ||
{% macro syntax_error() %} | ||
{% if execute %} | ||
{% call statement() %} | ||
select NOPE NOT A VALID QUERY | ||
{% endcall %} | ||
{% endif %} | ||
{% endmacro %} |
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 @@ | ||
select 1 as id |
58 changes: 58 additions & 0 deletions
58
test/integration/044_run_operations_test/test_run_operations.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,58 @@ | ||
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 "test/integration/044_run_operations_test/models" | ||
|
||
@property | ||
def project_config(self): | ||
return { | ||
"macro-paths": ['test/integration/044_run_operations_test/macros'], | ||
} | ||
|
||
def run_operation(self, macro, expect_pass=True, extra_args=None, **kwargs): | ||
args = ['run-operation'] | ||
if macro: | ||
args.extend(('--macro', 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') |