Skip to content

Commit

Permalink
Merge pull request #5 from SMeltser/correct_backup_param_order
Browse files Browse the repository at this point in the history
update tests
  • Loading branch information
SMeltser authored Feb 11, 2022
2 parents 69ba795 + d9efafd commit 5a4a2d9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{
config(
materialized='table', backup=True, dist='distkey'
materialized='table', backup=False, dist='distkey'
)
}}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{
config(
materialized='table', backup=True, sort='sortkey'
materialized='table', backup=False, sort='sortkey'
)
}}

Expand Down
64 changes: 42 additions & 22 deletions tests/integration/backup_table_tests/test_backup_table_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ def check_backup_param_template(self, test_table_name, backup_is_expected):
# Use raw DDL statement to confirm backup is set correctly on new table
with open('target/run/test/models/{}.sql'.format(test_table_name), 'r') as ddl_file:
ddl_statement = ddl_file.readlines()
self.assertEqual('backup no' not in ' '.join(ddl_statement).lower(), backup_is_expected)
if backup_is_expected:
distkey_index = ' '.join(ddl_statement).lower().find('distkey')
sortkey_index = ' '.join(ddl_statement).lower().find('sortkey')
backup_index = ' '.join(ddl_statement).lower().find('backup no')
self.assertEqual((backup_index < distkey_index) or distkey_index == -1, backup_is_expected)
self.assertEqual((backup_index < sortkey_index) or sortkey_index == -1, backup_is_expected)
lowercase_statement = ' '.join(ddl_statement).lower()
self.assertEqual('backup no' not in lowercase_statement, backup_is_expected)

@use_profile('redshift')
def test__redshift_backup_table_option(self):
Expand All @@ -50,12 +45,6 @@ def test__redshift_backup_table_option(self):
# Any view should not contain a BACKUP NO parameter, regardless of the specified config (create will fail)
self.check_backup_param_template('model_backup_true_view', True)

# model_backup_param_before_distkey should contain a BACKUP NO parameter which precedes a DISTKEY in the table ddl
self.check_backup_param_template('model_backup_param_before_distkey', True)

# model_backup_param_before_sortkey should contain a BACKUP NO parameter which precedes a SORTKEY in the table ddl
self.check_backup_param_template('model_backup_param_before_sortkey', True)

class TestBackupTableOptionProjectFalse(DBTIntegrationTest):
@property
def schema(self):
Expand All @@ -82,13 +71,8 @@ def check_backup_param_template(self, test_table_name, backup_is_expected):
# Use raw DDL statement to confirm backup is set correctly on new table
with open('target/run/test/models/{}.sql'.format(test_table_name), 'r') as ddl_file:
ddl_statement = ddl_file.readlines()
self.assertEqual('backup no' not in ' '.join(ddl_statement).lower(), backup_is_expected)
if backup_is_expected:
distkey_index = ' '.join(ddl_statement).lower().find('distkey')
sortkey_index = ' '.join(ddl_statement).lower().find('sortkey')
backup_index = ' '.join(ddl_statement).lower().find('backup no')
self.assertEqual((backup_index < distkey_index) or distkey_index == -1, backup_is_expected)
self.assertEqual((backup_index < sortkey_index) or sortkey_index == -1, backup_is_expected)
lowercase_statement = ' '.join(ddl_statement).lower()
self.assertEqual('backup no' not in lowercase_statement, backup_is_expected)

@use_profile('redshift')
def test__redshift_backup_table_option_project_config_false(self):
Expand All @@ -106,8 +90,44 @@ def test__redshift_backup_table_option_project_config_false(self):
# Any view should not contain a BACKUP NO parameter, regardless of the specified config (create will fail)
self.check_backup_param_template('model_backup_true_view', True)

class TestBackupTableOptionOrder(DBTIntegrationTest):
@property
def schema(self):
return 'backup_table_tests'

@staticmethod
def dir(path):
return os.path.normpath(path)

@property
def models(self):
return self.dir("models")

@property
def project_config(self):
return {
'config-version': 2
}

def check_backup_param_template(self, test_table_name, backup_flag_is_expected):
# Use raw DDL statement to confirm backup is set correctly on new table
with open('target/run/test/models/{}.sql'.format(test_table_name), 'r') as ddl_file:
ddl_statement = ddl_file.readlines()
lowercase_statement = ' '.join(ddl_statement).lower()
self.assertEqual('backup no' not in lowercase_statement, backup_flag_is_expected)
if backup_flag_is_expected:
distkey_index = lowercase_statement.find('distkey')
sortkey_index = lowercase_statement.find('sortkey')
backup_index = lowercase_statement.find('backup no')
self.assertEqual((backup_index < distkey_index) or distkey_index == -1, backup_flag_is_expected)
self.assertEqual((backup_index < sortkey_index) or sortkey_index == -1, backup_flag_is_expected)

@use_profile('redshift')
def test__redshift_backup_table_option_project_config_false(self):
self.assertEqual(len(self.run_dbt()), 6)

# model_backup_param_before_distkey should contain a BACKUP NO parameter which precedes a DISTKEY in the table ddl
self.check_backup_param_template('model_backup_param_before_distkey', True)
self.check_backup_param_template('model_backup_param_before_distkey', False)

# model_backup_param_before_sortkey should contain a BACKUP NO parameter which precedes a SORTKEY in the table ddl
self.check_backup_param_template('model_backup_param_before_sortkey', True)
self.check_backup_param_template('model_backup_param_before_sortkey', False)

0 comments on commit 5a4a2d9

Please sign in to comment.