Skip to content

Commit

Permalink
add a pretty janky data test to expose quoting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Beck committed Apr 16, 2019
1 parent d515903 commit fc4fc57
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/integration/001_simple_copy_test/test_simple_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def models(self):


class TestSimpleCopy(BaseTestSimpleCopy):

@use_profile("postgres")
def test__postgres__simple_copy(self):
self.use_default_project({"data-paths": [self.dir("seed-initial")]})
Expand Down Expand Up @@ -83,6 +84,12 @@ def test__snowflake__simple_copy(self):

self.assertManyTablesEqual(["SEED", "VIEW_MODEL", "INCREMENTAL", "MATERIALIZED"])

self.use_default_project({
"test-paths": [self.dir("tests")],
"data-paths": [self.dir("seed-update")],
})
self.run_dbt(['test'])

@use_profile("snowflake")
def test__snowflake__simple_copy__quoting_off(self):
self.use_default_project({
Expand All @@ -108,6 +115,13 @@ def test__snowflake__simple_copy__quoting_off(self):

self.assertManyTablesEqual(["SEED", "VIEW_MODEL", "INCREMENTAL", "MATERIALIZED"])

self.use_default_project({
"test-paths": [self.dir("tests")],
"data-paths": [self.dir("seed-update")],
"quoting": {"identifier": False},
})
self.run_dbt(['test'])

@use_profile("snowflake")
def test__snowflake__seed__quoting_switch(self):
self.use_default_project({
Expand All @@ -124,6 +138,12 @@ def test__snowflake__seed__quoting_switch(self):
})
results = self.run_dbt(["seed"], expect_pass=False)

self.use_default_project({
"test-paths": [self.dir("tests")],
"data-paths": [self.dir("seed-initial")],
})
self.run_dbt(['test'])

@use_profile("bigquery")
def test__bigquery__simple_copy(self):
self.use_default_project({"data-paths": [self.dir("seed-initial")]})
Expand Down Expand Up @@ -181,6 +201,8 @@ def test__snowflake__simple_copy__quoting_on(self):

self.assertManyTablesEqual(["seed", "view_model", "incremental", "materialized"])

# can't run the test as this one's identifiers will be the wrong case


class BaseLowercasedSchemaTest(BaseTestSimpleCopy):
def unique_schema(self):
Expand Down Expand Up @@ -210,6 +232,12 @@ def test__snowflake__simple_copy(self):

self.assertManyTablesEqual(["SEED", "VIEW_MODEL", "INCREMENTAL", "MATERIALIZED"])

self.use_default_project({
"test-paths": [self.dir("tests")],
"data-paths": [self.dir("seed-update")],
})
self.run_dbt(['test'])


class TestSnowflakeSimpleLowercasedSchemaQuoted(BaseLowercasedSchemaTest):
@property
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{%- set tgt = ref('seed') -%}
{%- set got = adapter.get_relation(database=tgt.database, schema=tgt.schema, identifier=tgt.identifier) | string -%}
{% set replaced = got.replace('"', '-') %}
{% set expected = "-" + tgt.database.upper() + '-.-' + tgt.schema.upper() + '-.-' + tgt.identifier.upper() + '-' %}

with cte as (
select '{{ replaced }}' as name
)
select * from cte where name not like '{{ expected }}'

0 comments on commit fc4fc57

Please sign in to comment.