forked from dbt-labs/dbt-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_yaml_renderer.py
103 lines (89 loc) · 2.84 KB
/
test_yaml_renderer.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
import unittest
import dbt.exceptions
import dbt.utils
from dbt.parser.schema_renderer import SchemaYamlRenderer
class TestYamlRendering(unittest.TestCase):
def test__models(self):
context = {
"test_var": "1234",
"alt_var": "replaced",
}
renderer = SchemaYamlRenderer(context, 'models')
# Verify description is not rendered and misc attribute is rendered
dct = {
"name": "my_model",
"description": "{{ test_var }}",
"attribute": "{{ test_var }}",
}
expected = {
"name": "my_model",
"description": "{{ test_var }}",
"attribute": "1234",
}
dct = renderer.render_data(dct)
self.assertEqual(expected, dct)
# Verify description in columns is not rendered
dct = {
'name': 'my_test',
'attribute': "{{ test_var }}",
'columns': [
{'description': "{{ test_var }}", 'name': 'id'},
]
}
expected = {
'name': 'my_test',
'attribute': "1234",
'columns': [
{'description': "{{ test_var }}", 'name': 'id'},
]
}
dct = renderer.render_data(dct)
self.assertEqual(expected, dct)
def test__sources(self):
context = {
"test_var": "1234",
"alt_var": "replaced",
}
renderer = SchemaYamlRenderer(context, 'sources')
# Only descriptions have jinja, none should be rendered
dct = {
"name": "my_source",
"description": "{{ alt_var }}",
"tables": [
{
"name": "my_table",
"description": "{{ alt_var }}",
"columns": [
{
"name": "id",
"description": "{{ alt_var }}",
}
]
}
]
}
rendered = renderer.render_data(dct)
self.assertEqual(dct, rendered)
def test__macros(self):
context = {
"test_var": "1234",
"alt_var": "replaced",
}
renderer = SchemaYamlRenderer(context, 'macros')
# Look for description in arguments
dct = {
"name": "my_macro",
"arguments": [
{"name": "my_arg", "attr": "{{ alt_var }}"},
{"name": "an_arg", "description": "{{ alt_var}}"}
]
}
expected = {
"name": "my_macro",
"arguments": [
{"name": "my_arg", "attr": "replaced"},
{"name": "an_arg", "description": "{{ alt_var}}"}
]
}
dct = renderer.render_data(dct)
self.assertEqual(dct, expected)