Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ct 1827/064 column comments tests conversion #6654

Merged
merged 5 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

102 changes: 59 additions & 43 deletions tests/functional/persist_docs_tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions tests/functional/persist_docs_tests/test_persist_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()