blob: b127c517e95d926e065127e7d3a61af7876b82c6 [file] [log] [blame]
Sean Daguea8311bf2014-09-30 06:28:26 -04001#!/usr/bin/env python
2
3# Copyright 2014 Hewlett-Packard Development Company, L.P.
4# Copyright 2014 Rackspace Australia
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
18import json
19import urllib2
20
21from tests.base import ZuulTestCase
22
23
24class TestWebapp(ZuulTestCase):
25
26 def _cleanup(self):
27 self.worker.hold_jobs_in_build = False
28 self.worker.release()
29 self.waitUntilSettled()
30
31 def setUp(self):
32 super(TestWebapp, self).setUp()
33 self.addCleanup(self._cleanup)
34 self.worker.hold_jobs_in_build = True
35 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
36 A.addApproval('CRVW', 2)
37 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
38 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
39 B.addApproval('CRVW', 2)
40 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
41 self.waitUntilSettled()
42 self.port = self.webapp.server.socket.getsockname()[1]
43
44 def test_webapp_status(self):
45 "Test that we can filter to only certain changes in the webapp."
46
47 req = urllib2.Request(
48 "http://localhost:%s/status" % self.port)
49 f = urllib2.urlopen(req)
50 data = json.loads(f.read())
51
52 self.assertIn('pipelines', data)
53
54 def test_webapp_status_compat(self):
55 # testing compat with status.json
56 req = urllib2.Request(
57 "http://localhost:%s/status.json" % self.port)
58 f = urllib2.urlopen(req)
59 data = json.loads(f.read())
60
61 self.assertIn('pipelines', data)
62
63 def test_webapp_bad_url(self):
64 # do we 404 correctly
65 req = urllib2.Request(
66 "http://localhost:%s/status/foo" % self.port)
67 self.assertRaises(urllib2.HTTPError, urllib2.urlopen, req)
68
69 def test_webapp_find_change(self):
70 # can we filter by change id
71 req = urllib2.Request(
72 "http://localhost:%s/status/change/1,1" % self.port)
73 f = urllib2.urlopen(req)
74 data = json.loads(f.read())
75
76 self.assertEqual(1, len(data), data)
77 self.assertEqual("org/project", data[0]['project'])
78
79 req = urllib2.Request(
80 "http://localhost:%s/status/change/2,1" % self.port)
81 f = urllib2.urlopen(req)
82 data = json.loads(f.read())
83
84 self.assertEqual(1, len(data), data)
85 self.assertEqual("org/project1", data[0]['project'], data)