~ricardokirkner/locolander/explicit-dependencies

« back to all changes in this revision

Viewing changes to tests/test_ns2df.py

  • Committer: Ricardo Kirkner
  • Date: 2013-07-11 17:32:28 UTC
  • mfrom: (9.1.6 requirements)
  • Revision ID: ricardo.kirkner@canonical.com-20130711173228-jtmyg8wzpmvd9sk8
pre-requisites to make locolander able to land itself

- updated requirements
- updated locolander config
- updated ns2df.py script to create Dockerfile from locolander config

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
class DependenciesTestCase(unittest.TestCase):
8
8
    """Tests for the dependencies transformer."""
9
9
 
 
10
    def setUp(self):
 
11
        super(DependenciesTestCase, self).setUp()
 
12
        self.params = {
 
13
            'pip_cache_dir': '/tmp/pipcache',
 
14
            'target_path': '/srv/locolander/project',
 
15
        }
 
16
 
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, [])
16
23
 
17
24
    def test_apt_one(self):
18
25
        config = dict(somebase={
19
26
            'apt': {'bzr': None}
20
27
        })
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"])
23
30
 
24
31
    def test_apt_several(self):
25
32
        config = dict(somebase={
26
33
            'apt': {'bzr': None, 'apache2': None}
27
34
        })
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",
32
38
        ])
33
39
 
34
40
    def test_apt_versions(self):
35
41
        config = dict(somebase={
36
42
            'apt': {'bzr': None, 'apache2': '3.3-4'}
37
43
        })
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",
42
47
        ])
43
48
 
44
49
    def test_pip_prev_one(self):
45
50
        config = dict(somebase={
46
51
            'pip': {'foo': None}
47
52
        })
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",
51
56
        ])
52
57
 
53
58
    def test_pip_prev_several(self):
54
59
        config = dict(somebase={
55
60
            'pip': {'foo': None, 'bar': None}
56
61
        })
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",
61
65
        ])
62
66
 
63
67
    def test_pip_prev_versions(self):
64
68
        config = dict(somebase={
65
69
            'pip': {'foo': None, 'bar': '2.1'}
66
70
        })
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 "
 
74
             "bar==2.1 foo"),
 
75
        ])
 
76
 
 
77
    def test_pip_prev_requirements(self):
 
78
        config = dict(somebase={
 
79
            'pip': '-r requirements.txt'
 
80
        })
 
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"),
71
85
        ])
72
86
 
73
87
    def test_pip_post_one(self):
74
88
        config = dict(somebase={
75
89
            'pip': {'foo': None}
76
90
        })
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"
80
94
        ])
81
95
 
82
96
    def test_pip_post_several(self):
83
97
        config = dict(somebase={
84
98
            'pip': {'foo': None, 'bar': None}
85
99
        })
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 "
 
103
             "bar foo"),
90
104
        ])
91
105
 
92
106
    def test_pip_post_versions(self):
93
107
        config = dict(somebase={
94
108
            'pip': {'foo': None, 'bar': '2.1'}
95
109
        })
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 "
 
113
             "bar==2.1 foo"),
 
114
        ])
 
115
 
 
116
    def test_pip_post_requirements(self):
 
117
        config = dict(somebase={
 
118
            'pip': '-r requirements.txt'
 
119
        })
 
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"),
100
124
        ])
101
125
 
102
126
    def test_mixed_prev(self):
104
128
            'apt': {'bzr': None, 'apache2': '3.3-4'},
105
129
            'pip': {'foo': None, 'bar': None},
106
130
        })
107
 
        res = ns2df._get_depends_prev(config, pip_cache_dir="/tmp/pipcache")
 
131
        res = ns2df._get_depends_prev(config, **self.params)
108
132
        self.assertEqual(res, [
109
 
            "run apt-get -q -y install apache2=3.3-4",
110
 
            "run apt-get -q -y install bzr",
111
 
            "run pip install --download=/tmp/pipcache --no-install bar",
112
 
            "run pip install --download=/tmp/pipcache --no-install foo",
 
133
            "run apt-get -q -y install apache2=3.3-4 bzr",
 
134
            "run cd /srv/locolander/project && pip install --download=/tmp/pipcache --no-install bar foo",
113
135
        ])
114
136
 
115
137
    def test_mixed_post(self):
117
139
            'apt': {'bzr': None, 'apache2': '3.3-4'},
118
140
            'pip': {'foo': None, 'bar': None},
119
141
        })
120
 
        res = ns2df._get_depends_post(config, pip_cache_dir="/tmp/pipcache")
 
142
        res = ns2df._get_depends_post(config, **self.params)
121
143
        self.assertEqual(res, [
122
 
            "run pip install --find-links=file:///tmp/pipcache --no-index bar",
123
 
            "run pip install --find-links=file:///tmp/pipcache --no-index foo",
 
144
            ("run cd /srv/locolander/project && pip install --find-links=file:///tmp/pipcache --no-index "
 
145
             "bar foo"),
124
146
        ])
125
147
 
126
148
 
130
152
    def test_one_base(self):
131
153
        config = dict(precise={})
132
154
        res = ns2df._get_base(config)
133
 
        self.assertEqual(res, ["from ubuntu:precise"])
 
155
        self.assertEqual(res, ["from locolander:precise"])
134
156
 
135
157
    def test_several_bases(self):
136
158
        config = dict(base1={}, base2={})
141
163
        self.assertEqual(res, ["run ip link set dev eth0 down"])
142
164
 
143
165
    def test_rest(self):
144
 
        res = ns2df._get_rest({})
145
 
        self.assertEqual(res, [])
 
166
        res = ns2df._get_rest({},
 
167
                              target_path='/srv/locolander',
 
168
                              test_cmd='./run_tests.sh')
 
169
        self.assertEqual(res, ["cmd cd /srv/locolander && timeout 300 ./run_tests.sh"])
146
170
 
147
171
    def test_all_mixed(self):
148
172
        config_text = """
155
179
            metadata:
156
180
                test_script: foo
157
181
        """
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 "
167
 
                "--no-index foobar"
 
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"
168
194
        )