1
+ import os
2
+
1
3
import pytest
2
4
from dbt .tests .adapter .basic .expected_catalog import (
3
5
base_expected_catalog ,
7
9
from dbt .tests .adapter .basic .test_docs_generate import (
8
10
BaseDocsGenerate ,
9
11
BaseDocsGenReferences ,
12
+ get_artifact ,
10
13
ref_models__docs_md ,
11
14
ref_models__ephemeral_copy_sql ,
12
15
ref_models__schema_yml ,
13
16
ref_sources__schema_yml ,
17
+ run_and_generate ,
18
+ verify_metadata ,
14
19
)
15
20
16
21
22
+ def verify_catalog (project , expected_catalog , start_time , ignore_owner ):
23
+ # get the catalog.json
24
+ catalog_path = os .path .join (project .project_root , "target" , "catalog.json" )
25
+ assert os .path .exists (catalog_path )
26
+ catalog = get_artifact (catalog_path )
27
+
28
+ # verify the catalog
29
+ assert set (catalog ) == {"errors" , "metadata" , "nodes" , "sources" }
30
+ verify_metadata (
31
+ catalog ["metadata" ],
32
+ "https://schemas.getdbt.com/dbt/catalog/v1.json" ,
33
+ start_time ,
34
+ )
35
+ assert not catalog ["errors" ]
36
+ for key in "nodes" , "sources" :
37
+ for unique_id , expected_node in expected_catalog [key ].items ():
38
+ found_node = catalog [key ][unique_id ]
39
+ for node_key in expected_node :
40
+ assert node_key in found_node
41
+
42
+ if node_key == "metadata" and ignore_owner :
43
+ expected_node [node_key ]["owner" ] = found_node [node_key ]["owner" ]
44
+
45
+ assert (
46
+ found_node [node_key ] == expected_node [node_key ]
47
+ ), f"Key '{ node_key } ' in '{ unique_id } ' did not match"
48
+
49
+
17
50
class TestDocsGenerateSQLServer (BaseDocsGenerate ):
18
51
@pytest .fixture (scope = "class" )
19
52
def expected_catalog (self , project ):
@@ -28,6 +61,22 @@ def expected_catalog(self, project):
28
61
model_stats = no_stats (),
29
62
)
30
63
64
+ # Test "--no-compile" flag works and produces no manifest.json
65
+ def test_run_and_generate_no_compile (self , project , expected_catalog , is_azure : bool ):
66
+ start_time = run_and_generate (project , ["--no-compile" ])
67
+ assert not os .path .exists (os .path .join (project .project_root , "target" , "manifest.json" ))
68
+ verify_catalog (project , expected_catalog , start_time , is_azure )
69
+
70
+ # Test generic "docs generate" command
71
+ def test_run_and_generate (self , project , expected_catalog , is_azure : bool ):
72
+ start_time = run_and_generate (project )
73
+ verify_catalog (project , expected_catalog , start_time , is_azure )
74
+
75
+ # Check that assets have been copied to the target directory for use in the docs html page
76
+ assert os .path .exists (os .path .join ("." , "target" , "assets" ))
77
+ assert os .path .exists (os .path .join ("." , "target" , "assets" , "lorem-ipsum.txt" ))
78
+ assert not os .path .exists (os .path .join ("." , "target" , "non-existent-assets" ))
79
+
31
80
32
81
class TestDocsGenReferencesSQLServer (BaseDocsGenReferences ):
33
82
@pytest .fixture (scope = "class" )
@@ -77,3 +126,7 @@ def models(self):
77
126
"ephemeral_copy.sql" : ref_models__ephemeral_copy_sql ,
78
127
"docs.md" : ref_models__docs_md ,
79
128
}
129
+
130
+ def test_references (self , project , expected_catalog , is_azure : bool ):
131
+ start_time = run_and_generate (project )
132
+ verify_catalog (project , expected_catalog , start_time , is_azure )
0 commit comments