test_persist_docs.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License in the LICENSE file at the
  6. # root of this repository, or online at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import json
  16. import os
  17. import pytest
  18. from dbt.tests.adapter.persist_docs.test_persist_docs import (
  19. BasePersistDocs,
  20. BasePersistDocsColumnMissing,
  21. BasePersistDocsCommentOnQuotedColumn,
  22. )
  23. from dbt.tests.util import run_dbt
  24. from fixtures import (
  25. cross_database_reference_schema_yml,
  26. cross_database_reference_sql,
  27. )
  28. class TestPersistDocsMaterialize(BasePersistDocs):
  29. pass
  30. class TestPersistDocsColumnMissingMaterialize(BasePersistDocsColumnMissing):
  31. pass
  32. class TestPersistDocsCommentOnQuotedColumnMaterialize(
  33. BasePersistDocsCommentOnQuotedColumn
  34. ):
  35. pass
  36. class TestCrossDatabaseDocs:
  37. @pytest.fixture(scope="class")
  38. def models(self):
  39. return {
  40. "cross_db_reference.sql": cross_database_reference_sql,
  41. "schema.yml": cross_database_reference_schema_yml,
  42. }
  43. def test_cross_db_docs_generate(self, project):
  44. results = run_dbt(["run"])
  45. # Run dbt docs generate to generate documentation
  46. results = run_dbt(["docs", "generate"])
  47. assert results is not None
  48. # Validate the generated documentation
  49. with open(os.path.join(project.project_root, "target/catalog.json")) as f:
  50. catalog = json.load(f)
  51. assert "source.test.test_database_1.table1" in catalog["sources"]
  52. assert "source.test.test_database_2.table2" in catalog["sources"]
  53. cross_db_reference = catalog["nodes"]["model.test.cross_db_reference"]
  54. assert "id" in cross_db_reference["columns"]