7
7
class DependenciesTestCase(unittest.TestCase):
8
8
"""Tests for the dependencies transformer."""
11
super(DependenciesTestCase, self).setUp()
13
'pip_cache_dir': '/tmp/pipcache',
14
'target_path': '/srv/locolander/project',
10
17
def test_no_dependencies(self):
11
18
config = dict(somebase={})
12
res = ns2df._get_depends_prev(config, pip_cache_dir="/tmp/pipcache")
19
res = ns2df._get_depends_prev(config, **self.params)
13
20
self.assertEqual(res, [])
14
res = ns2df._get_depends_post(config, pip_cache_dir="/tmp/pipcache")
21
res = ns2df._get_depends_post(config, **self.params)
15
22
self.assertEqual(res, [])
17
24
def test_apt_one(self):
18
25
config = dict(somebase={
19
26
'apt': {'bzr': None}
21
res = ns2df._get_depends_prev(config, pip_cache_dir="/tmp/pipcache")
28
res = ns2df._get_depends_prev(config, **self.params)
22
29
self.assertEqual(res, ["run apt-get -q -y install bzr"])
24
31
def test_apt_several(self):
25
32
config = dict(somebase={
26
33
'apt': {'bzr': None, 'apache2': None}
28
res = ns2df._get_depends_prev(config, pip_cache_dir="/tmp/pipcache")
35
res = ns2df._get_depends_prev(config, **self.params)
29
36
self.assertEqual(res, [
30
"run apt-get -q -y install apache2",
31
"run apt-get -q -y install bzr",
37
"run apt-get -q -y install apache2 bzr",
34
40
def test_apt_versions(self):
35
41
config = dict(somebase={
36
42
'apt': {'bzr': None, 'apache2': '3.3-4'}
38
res = ns2df._get_depends_prev(config, pip_cache_dir="/tmp/pipcache")
44
res = ns2df._get_depends_prev(config, **self.params)
39
45
self.assertEqual(res, [
40
"run apt-get -q -y install apache2=3.3-4",
41
"run apt-get -q -y install bzr",
46
"run apt-get -q -y install apache2=3.3-4 bzr",
44
49
def test_pip_prev_one(self):
45
50
config = dict(somebase={
46
51
'pip': {'foo': None}
48
res = ns2df._get_depends_prev(config, pip_cache_dir="/tmp/pipcache")
53
res = ns2df._get_depends_prev(config, **self.params)
49
54
self.assertEqual(res, [
50
"run pip install --download=/tmp/pipcache --no-install foo",
55
"run cd /srv/locolander/project && pip install --download=/tmp/pipcache --no-install foo",
53
58
def test_pip_prev_several(self):
54
59
config = dict(somebase={
55
60
'pip': {'foo': None, 'bar': None}
57
res = ns2df._get_depends_prev(config, pip_cache_dir="/tmp/pipcache")
62
res = ns2df._get_depends_prev(config, **self.params)
58
63
self.assertEqual(res, [
59
"run pip install --download=/tmp/pipcache --no-install bar",
60
"run pip install --download=/tmp/pipcache --no-install foo",
64
"run cd /srv/locolander/project && pip install --download=/tmp/pipcache --no-install bar foo",
63
67
def test_pip_prev_versions(self):
64
68
config = dict(somebase={
65
69
'pip': {'foo': None, 'bar': '2.1'}
67
res = ns2df._get_depends_prev(config, pip_cache_dir="/tmp/pipcache")
68
self.assertEqual(res, [
69
"run pip install --download=/tmp/pipcache --no-install bar==2.1",
70
"run pip install --download=/tmp/pipcache --no-install foo",
71
res = ns2df._get_depends_prev(config, **self.params)
72
self.assertEqual(res, [
73
("run cd /srv/locolander/project && pip install --download=/tmp/pipcache --no-install "
77
def test_pip_prev_requirements(self):
78
config = dict(somebase={
79
'pip': '-r requirements.txt'
81
res = ns2df._get_depends_prev(config, **self.params)
82
self.assertEqual(res, [
83
("run cd /srv/locolander/project && pip install --download=/tmp/pipcache --no-install "
84
"-r requirements.txt"),
73
87
def test_pip_post_one(self):
74
88
config = dict(somebase={
75
89
'pip': {'foo': None}
77
res = ns2df._get_depends_post(config, pip_cache_dir="/tmp/pipcache")
91
res = ns2df._get_depends_post(config, **self.params)
78
92
self.assertEqual(res, [
79
"run pip install --find-links=file:///tmp/pipcache --no-index foo"
93
"run cd /srv/locolander/project && pip install --find-links=file:///tmp/pipcache --no-index foo"
82
96
def test_pip_post_several(self):
83
97
config = dict(somebase={
84
98
'pip': {'foo': None, 'bar': None}
86
res = ns2df._get_depends_post(config, pip_cache_dir="/tmp/pipcache")
100
res = ns2df._get_depends_post(config, **self.params)
87
101
self.assertEqual(res, [
88
"run pip install --find-links=file:///tmp/pipcache --no-index bar",
89
"run pip install --find-links=file:///tmp/pipcache --no-index foo",
102
("run cd /srv/locolander/project && pip install --find-links=file:///tmp/pipcache --no-index "
92
106
def test_pip_post_versions(self):
93
107
config = dict(somebase={
94
108
'pip': {'foo': None, 'bar': '2.1'}
96
res = ns2df._get_depends_post(config, pip_cache_dir="/tmcache")
97
self.assertEqual(res, [
98
"run pip install --find-links=file:///tmcache --no-index bar==2.1",
99
"run pip install --find-links=file:///tmcache --no-index foo",
110
res = ns2df._get_depends_post(config, **self.params)
111
self.assertEqual(res, [
112
("run cd /srv/locolander/project && pip install --find-links=file:///tmp/pipcache --no-index "
116
def test_pip_post_requirements(self):
117
config = dict(somebase={
118
'pip': '-r requirements.txt'
120
res = ns2df._get_depends_post(config, **self.params)
121
self.assertEqual(res, [
122
("run cd /srv/locolander/project && pip install --find-links=file:///tmp/pipcache --no-index "
123
"-r requirements.txt"),
102
126
def test_mixed_prev(self):
158
script, docker = ns2df.parse(config_text, "/tmp/pipcache")
159
self.assertEqual(script, "foo")
182
docker = ns2df.parse(config_text, "/tmp/pipcache", 'project')
160
183
self.assertEqual(docker,
161
"from ubuntu:precise\n"
162
"run apt-get -q -y install apache2=3.3-4\n"
163
"run apt-get -q -y install bzr\n"
164
"run pip install --download=/tmp/pipcache --no-install foobar\n"
184
"from locolander:precise\n"
185
"run mkdir -p /srv/locolander/project\n"
186
"add . /srv/locolander/project\n"
187
"run chown -R locolander.locolander /srv/locolander/project\n"
188
"run apt-get -q -y install apache2=3.3-4 bzr\n"
189
"run cd /srv/locolander/project && pip install --download=/tmp/pipcache --no-install foobar\n"
165
190
"run ip link set dev eth0 down\n"
166
"run pip install --find-links=file:///tmp/pipcache "
191
"run cd /srv/locolander/project && pip install --find-links=file:///tmp/pipcache "
192
"--no-index foobar\n"
193
"cmd cd /srv/locolander/project && timeout 300 foo"