-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathtest_docs_blocks.py
149 lines (122 loc) · 4.15 KB
/
test_docs_blocks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import json
import os
from test.integration.base import DBTIntegrationTest, use_profile
import dbt.exceptions
class TestGoodDocsBlocks(DBTIntegrationTest):
@property
def schema(self):
return 'docs_blocks_035'
@staticmethod
def dir(path):
return os.path.normpath(path)
@property
def models(self):
return self.dir("models")
@use_profile('postgres')
def test_postgres_valid_doc_ref(self):
self.assertEqual(len(self.run_dbt()), 1)
self.assertTrue(os.path.exists('./target/manifest.json'))
with open('./target/manifest.json') as fp:
manifest = json.load(fp)
model_data = manifest['nodes']['model.test.model']
self.assertEqual(
model_data['description'],
'My model is just a copy of the seed'
)
self.assertEqual(
{
'name': 'id',
'description': 'The user ID number',
'data_type': None,
},
model_data['columns']['id']
)
self.assertEqual(
{
'name': 'first_name',
'description': "The user's first name",
'data_type': None,
},
model_data['columns']['first_name']
)
self.assertEqual(
{
'name': 'last_name',
'description': "The user's last name",
'data_type': None,
},
model_data['columns']['last_name']
)
self.assertEqual(len(model_data['columns']), 3)
@use_profile('postgres')
def test_postgres_alternative_docs_path(self):
self.use_default_project({"docs-paths": [self.dir("docs")]})
self.assertEqual(len(self.run_dbt()), 1)
self.assertTrue(os.path.exists('./target/manifest.json'))
with open('./target/manifest.json') as fp:
manifest = json.load(fp)
model_data = manifest['nodes']['model.test.model']
self.assertEqual(
model_data['description'],
'Alt text about the model'
)
self.assertEqual(
{
'name': 'id',
'description': 'The user ID number with alternative text',
'data_type': None,
},
model_data['columns']['id']
)
self.assertEqual(
{
'name': 'first_name',
'description': "The user's first name",
'data_type': None,
},
model_data['columns']['first_name']
)
self.assertEqual(
{
'name': 'last_name',
'description': "The user's last name in this other file",
'data_type': None,
},
model_data['columns']['last_name']
)
self.assertEqual(len(model_data['columns']), 3)
@use_profile('postgres')
def test_postgres_alternative_docs_path_missing(self):
self.use_default_project({"docs-paths": [self.dir("not-docs")]})
with self.assertRaises(dbt.exceptions.CompilationException):
self.run_dbt()
class TestMissingDocsBlocks(DBTIntegrationTest):
@property
def schema(self):
return 'docs_blocks_035'
@staticmethod
def dir(path):
return os.path.normpath(path)
@property
def models(self):
return self.dir("missing_docs_models")
@use_profile('postgres')
def test_postgres_missing_doc_ref(self):
# The run should fail since we could not find the docs reference.
with self.assertRaises(dbt.exceptions.CompilationException):
self.run_dbt()
class TestBadDocsBlocks(DBTIntegrationTest):
@property
def schema(self):
return 'docs_blocks_035'
@staticmethod
def dir(path):
return os.path.normpath(path)
@property
def models(self):
return self.dir("invalid_name_models")
@use_profile('postgres')
def test_postgres_invalid_doc_ref(self):
# The run should fail since we could not find the docs reference.
with self.assertRaises(dbt.exceptions.CompilationException):
self.run_dbt(expect_pass=False)