-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
test_dependency_options.py
102 lines (91 loc) · 3.48 KB
/
test_dependency_options.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 os
import shutil
import pytest
from dbt.tests.util import run_dbt
class TestDepsOptions(object):
# this revision of dbt-integration-project requires dbt-utils.git@0.5.0, which the
# package config handling should detect
@pytest.fixture(scope="class")
def packages(self):
return {
"packages": [
{
"package": "fivetran/fivetran_utils",
"version": "0.4.7",
},
]
}
@pytest.fixture
def clean_start(self, project):
if os.path.exists("dbt_packages"):
shutil.rmtree("dbt_packages")
if os.path.exists("package-lock.yml"):
os.remove("package-lock.yml")
def test_deps_lock(self, clean_start):
run_dbt(["deps", "--lock"])
assert not os.path.exists("dbt_packages")
assert os.path.exists("package-lock.yml")
with open("package-lock.yml") as fp:
contents = fp.read()
fivetran_package = "- package: fivetran/fivetran_utils\n version: 0.4.7"
# dbt-utils is a dep in fivetran so we can't check for a specific version or this test fails everytime a new dbt-utils version comes out
dbt_labs_package = "- package: dbt-labs/dbt_utils"
package_sha = "sha1_hash: 71304bca2138cf8004070b3573a1e17183c0c1a8"
assert fivetran_package in contents
assert dbt_labs_package in contents
assert package_sha in contents
def test_deps_default(self, clean_start):
run_dbt(["deps"])
assert len(os.listdir("dbt_packages")) == 2
assert os.path.exists("package-lock.yml")
with open("package-lock.yml") as fp:
contents = fp.read()
fivetran_package = "- package: fivetran/fivetran_utils\n version: 0.4.7"
# dbt-utils is a dep in fivetran so we can't check for a specific version or this test fails everytime a new dbt-utils version comes out
dbt_labs_package = "- package: dbt-labs/dbt_utils"
package_sha = "sha1_hash: 71304bca2138cf8004070b3573a1e17183c0c1a8"
assert fivetran_package in contents
assert dbt_labs_package in contents
assert package_sha in contents
def test_deps_add(self, clean_start):
run_dbt(["deps", "--add-package", "dbt-labs/audit_helper@0.9.0"])
with open("packages.yml") as fp:
contents = fp.read()
assert (
contents
== """packages:
- package: fivetran/fivetran_utils
version: 0.4.7
- package: dbt-labs/audit_helper
version: 0.9.0
"""
)
assert len(os.listdir("dbt_packages")) == 3
def test_deps_add_without_install(self, clean_start):
os.rename("packages.yml", "dependencies.yml")
run_dbt(
[
"deps",
"--add-package",
"dbt-labs/audit_helper@0.9.0",
"--lock",
]
)
assert not os.path.exists("dbt_packages")
assert not os.path.exists("packages.yml")
with open("dependencies.yml") as fp:
contents = fp.read()
assert (
contents
== """packages:
- package: fivetran/fivetran_utils
version: 0.4.7
- package: dbt-labs/audit_helper
version: 0.9.0
"""
)
def test_deps_upgrade(self, clean_start, mocker):
run_dbt(["deps", "--lock"])
patched_lock = mocker.patch("dbt.task.deps.DepsTask.lock")
run_dbt(["deps", "--upgrade"])
assert patched_lock.call_count == 1