Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 1 | #!/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 | |
| 18 | import json |
| 19 | import urllib2 |
| 20 | |
| 21 | from tests.base import ZuulTestCase |
| 22 | |
| 23 | |
| 24 | class 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): |
James E. Blair | 509cada | 2015-12-08 16:31:16 -0800 | [diff] [blame] | 32 | self.skip("Disabled for early v3 development") |
| 33 | |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 34 | super(TestWebapp, self).setUp() |
| 35 | self.addCleanup(self._cleanup) |
| 36 | self.worker.hold_jobs_in_build = True |
| 37 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
| 38 | A.addApproval('CRVW', 2) |
| 39 | self.fake_gerrit.addEvent(A.addApproval('APRV', 1)) |
| 40 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
| 41 | B.addApproval('CRVW', 2) |
| 42 | self.fake_gerrit.addEvent(B.addApproval('APRV', 1)) |
| 43 | self.waitUntilSettled() |
| 44 | self.port = self.webapp.server.socket.getsockname()[1] |
| 45 | |
| 46 | def test_webapp_status(self): |
| 47 | "Test that we can filter to only certain changes in the webapp." |
| 48 | |
| 49 | req = urllib2.Request( |
| 50 | "http://localhost:%s/status" % self.port) |
| 51 | f = urllib2.urlopen(req) |
| 52 | data = json.loads(f.read()) |
| 53 | |
| 54 | self.assertIn('pipelines', data) |
| 55 | |
| 56 | def test_webapp_status_compat(self): |
| 57 | # testing compat with status.json |
| 58 | req = urllib2.Request( |
| 59 | "http://localhost:%s/status.json" % self.port) |
| 60 | f = urllib2.urlopen(req) |
| 61 | data = json.loads(f.read()) |
| 62 | |
| 63 | self.assertIn('pipelines', data) |
| 64 | |
| 65 | def test_webapp_bad_url(self): |
| 66 | # do we 404 correctly |
| 67 | req = urllib2.Request( |
| 68 | "http://localhost:%s/status/foo" % self.port) |
| 69 | self.assertRaises(urllib2.HTTPError, urllib2.urlopen, req) |
| 70 | |
| 71 | def test_webapp_find_change(self): |
| 72 | # can we filter by change id |
| 73 | req = urllib2.Request( |
| 74 | "http://localhost:%s/status/change/1,1" % self.port) |
| 75 | f = urllib2.urlopen(req) |
| 76 | data = json.loads(f.read()) |
| 77 | |
| 78 | self.assertEqual(1, len(data), data) |
| 79 | self.assertEqual("org/project", data[0]['project']) |
| 80 | |
| 81 | req = urllib2.Request( |
| 82 | "http://localhost:%s/status/change/2,1" % self.port) |
| 83 | f = urllib2.urlopen(req) |
| 84 | data = json.loads(f.read()) |
| 85 | |
| 86 | self.assertEqual(1, len(data), data) |
| 87 | self.assertEqual("org/project1", data[0]['project'], data) |