diff --git a/test/integration/064_column_comments_tests/models/quote_model.sql b/test/integration/064_column_comments_tests/models/quote_model.sql deleted file mode 100644 index 2255b4bd7f0..00000000000 --- a/test/integration/064_column_comments_tests/models/quote_model.sql +++ /dev/null @@ -1 +0,0 @@ -select 1 as {{ adapter.quote("2id") }} diff --git a/test/integration/064_column_comments_tests/models/schema.yml b/test/integration/064_column_comments_tests/models/schema.yml deleted file mode 100644 index 1e82165fabf..00000000000 --- a/test/integration/064_column_comments_tests/models/schema.yml +++ /dev/null @@ -1,9 +0,0 @@ -version: 2 -models: - - name: quote_model - description: "model to test column quotes and comments" - columns: - - name: 2id - description: "XXX My description" - quote: true - diff --git a/test/integration/064_column_comments_tests/test_column_comments.py b/test/integration/064_column_comments_tests/test_column_comments.py deleted file mode 100644 index bd94b642cb6..00000000000 --- a/test/integration/064_column_comments_tests/test_column_comments.py +++ /dev/null @@ -1,43 +0,0 @@ -import json - -from test.integration.base import DBTIntegrationTest, use_profile - - -class TestColumnComment(DBTIntegrationTest): - @property - def schema(self): - return "column_comment_060" - - @property - def models(self): - return "models" - - @property - def project_config(self): - return { - 'config-version': 2, - 'models': { - 'test': { - 'materialized': 'table', - '+persist_docs': { - "relation": True, - "columns": True, - }, - } - } - } - - def run_has_comments(self): - self.run_dbt() - self.run_dbt(['docs', 'generate']) - with open('target/catalog.json') as fp: - catalog_data = json.load(fp) - assert 'nodes' in catalog_data - assert len(catalog_data['nodes']) == 1 - column_node = catalog_data['nodes']['model.test.quote_model'] - column_comment = column_node['columns']['2id']['comment'] - assert column_comment.startswith('XXX') - - @use_profile('postgres') - def test_postgres_comments(self): - self.run_has_comments() diff --git a/tests/functional/persist_docs_tests/fixtures.py b/tests/functional/persist_docs_tests/fixtures.py index c596f5219cf..f7179bb1ab5 100644 --- a/tests/functional/persist_docs_tests/fixtures.py +++ b/tests/functional/persist_docs_tests/fixtures.py @@ -1,3 +1,62 @@ +_MODELS__VIEW = """ +{{ config(materialized='view') }} +select 2 as id, 'Bob' as name +""" + +_MODELS__NO_DOCS_MODEL = """ +select 1 as id, 'Alice' as name +""" + +_DOCS__MY_FUN_DOCS = """ +{% docs my_fun_doc %} +name Column description "with double quotes" +and with 'single quotes' as welll as other; +'''abc123''' +reserved -- characters +-- +/* comment */ +Some $lbl$ labeled $lbl$ and $$ unlabeled $$ dollar-quoting + +{% enddocs %} +""" + +_MODELS__TABLE = """ +{{ config(materialized='table') }} +select 1 as id, 'Joe' as name +""" + + +_MODELS__MISSING_COLUMN = """ +{{ config(materialized='table') }} +select 1 as id, 'Ed' as name +""" + +_MODELS__MODEL_USING_QUOTE_UTIL = """ +select 1 as {{ adapter.quote("2id") }} +""" + +_PROPERTIES__QUOTE_MODEL = """ +version: 2 +models: + - name: quote_model + description: "model to test column quotes and comments" + columns: + - name: 2id + description: "XXX My description" + quote: true +""" + +_PROPERITES__SCHEMA_MISSING_COL = """ +version: 2 +models: + - name: missing_column + columns: + - name: id + description: "test id column description" + - name: column_that_does_not_exist + description: "comment that cannot be created" +""" + _PROPERTIES__SCHEMA_YML = """ version: 2 @@ -71,49 +130,6 @@ {{ doc('my_fun_doc')}} """ -_MODELS__VIEW = """ -{{ config(materialized='view') }} -select 2 as id, 'Bob' as name -""" - -_MODELS__NO_DOCS_MODEL = """ -select 1 as id, 'Alice' as name -""" - -_DOCS__MY_FUN_DOCS = """ -{% docs my_fun_doc %} -name Column description "with double quotes" -and with 'single quotes' as welll as other; -'''abc123''' -reserved -- characters --- -/* comment */ -Some $lbl$ labeled $lbl$ and $$ unlabeled $$ dollar-quoting - -{% enddocs %} -""" - -_MODELS__TABLE = """ -{{ config(materialized='table') }} -select 1 as id, 'Joe' as name -""" - - -_MODELS__MISSING_COLUMN = """ -{{ config(materialized='table') }} -select 1 as id, 'Ed' as name -""" - -_PROPERITES__SCHEMA_MISSING_COL = """ -version: 2 -models: - - name: missing_column - columns: - - name: id - description: "test id column description" - - name: column_that_does_not_exist - description: "comment that cannot be created" -""" _SEEDS__SEED = """id,name 1,Alice diff --git a/tests/functional/persist_docs_tests/test_persist_docs.py b/tests/functional/persist_docs_tests/test_persist_docs.py index 8c3822b497a..7ca5dcfabe8 100644 --- a/tests/functional/persist_docs_tests/test_persist_docs.py +++ b/tests/functional/persist_docs_tests/test_persist_docs.py @@ -9,9 +9,11 @@ from tests.functional.persist_docs_tests.fixtures import ( _DOCS__MY_FUN_DOCS, _MODELS__MISSING_COLUMN, + _MODELS__MODEL_USING_QUOTE_UTIL, _MODELS__NO_DOCS_MODEL, _MODELS__TABLE, _MODELS__VIEW, + _PROPERTIES__QUOTE_MODEL, _PROPERITES__SCHEMA_MISSING_COL, _PROPERTIES__SCHEMA_YML, _SEEDS__SEED, @@ -148,3 +150,45 @@ def test_postgres_missing_column(self, project): table_node = catalog_data["nodes"]["model.test.missing_column"] table_id_comment = table_node["columns"]["id"]["comment"] assert table_id_comment.startswith("test id column description") + + +class TestPersistDocsColumnComment: + @pytest.fixture(scope="class") + def models(self): + return {"quote_model.sql": _MODELS__MODEL_USING_QUOTE_UTIL} + + @pytest.fixture(scope="class") + def properties(self): + return {"properties.yml": _PROPERTIES__QUOTE_MODEL} + + @pytest.fixture(scope="class") + def project_config_update(self): + return { + "models": { + "test": { + "materialized": "table", + "+persist_docs": { + "relation": True, + "columns": True, + }, + } + } + } + + @pytest.fixture(scope="class") + def run_has_comments(self, project): + def fixt(): + run_dbt() + run_dbt(["docs", "generate"]) + with open("target/catalog.json") as fp: + catalog_data = json.load(fp) + assert "nodes" in catalog_data + assert len(catalog_data["nodes"]) == 1 + column_node = catalog_data["nodes"]["model.test.quote_model"] + column_comment = column_node["columns"]["2id"]["comment"] + assert column_comment.startswith("XXX") + + return fixt + + def test_postgres_comments(self, run_has_comments): + run_has_comments()