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 5584a97 commit 68febd0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
40 changes: 30 additions & 10 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 All @@ -148,20 +168,11 @@ def test__bigquery__simple_copy(self):
self.assertTablesEqual("seed","incremental")
self.assertTablesEqual("seed","materialized")


class TestSimpleCopyQuotingIdentifierOn(BaseTestSimpleCopy):
@property
def project_config(self):
return {
'quoting': {
'identifier': True,
},
}

@use_profile("snowflake")
def test__snowflake__simple_copy__quoting_on(self):
self.use_default_project({
"data-paths": [self.dir("seed-initial")],
"quoting": {"identifier": True}
})

results = self.run_dbt(["seed"])
Expand All @@ -173,6 +184,7 @@ def test__snowflake__simple_copy__quoting_on(self):

self.use_default_project({
"data-paths": [self.dir("seed-update")],
"quoting": {"identifier": True}
})
results = self.run_dbt(["seed"])
self.assertEqual(len(results), 1)
Expand All @@ -181,6 +193,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 +224,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 68febd0

Please sign in to comment.