Skip to content

Commit

Permalink
Ct 1827/064 column comments tests conversion (#6654)
Browse files Browse the repository at this point in the history
* Convert test and make it a bit more pytest-onic

* Ax old integration test.

* Run black on test conversion

* I didn't like how pytest was running the fixture so wrapped it into a closure.

* Merge converted test into persist docs.

Co-authored-by: Mila Page <versusfacit@users.noreply.github.com>
  • Loading branch information
VersusFacit and VersusFacit authored Jan 26, 2023
1 parent b0651b1 commit c65ba11
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 96 deletions.

This file was deleted.

9 changes: 0 additions & 9 deletions test/integration/064_column_comments_tests/models/schema.yml

This file was deleted.

43 changes: 0 additions & 43 deletions test/integration/064_column_comments_tests/test_column_comments.py

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()

0 comments on commit c65ba11

Please sign in to comment.