~psivaa/uci-engine/lander-jenkins-with-proxy

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
# Ubuntu CI Engine
# Copyright 2014 Canonical Ltd.

# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License version 3, as
# published by the Free Software Foundation.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import mock
import unittest

import webtest

from tstrun import wsgi


class TestAPI(unittest.TestCase):
    '''Test to ensure the v1 API works.'''

    def setUp(self):
        super(TestAPI, self).setUp()
        self.app = webtest.TestApp(wsgi.appl, relative_to='.')

    # MISSINGTEST: We need a way to test against a test rabbit server in
    # addition to the mocks -- vila 2014-01-21
    @mock.patch('ci_utils.amqp_utils.send')
    def test_test_image(self, send):
        send.return_value = None
        params = {
            'ticket_id': 'ticket-001',
            'cancel_url': None,
            'image_id': 'foo',
            'package_list': ['bar'],
            'progress_trigger': 'test_run_1',
        }
        resp = self.app.post_json('/api/v1/test_image', params)
        self.assertEqual('', resp.body)
        self.assertEqual(204, resp.status_code)

    @mock.patch('ci_utils.amqp_utils.get_config')
    def test_status(self, get_config):
        get_config.return_value = None
        resp = self.app.get('/api/v1/status')
        self.assertEqual(200, resp.status_code)