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 |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 19 | |
| 20 | from six.moves import urllib |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 21 | |
| 22 | from tests.base import ZuulTestCase |
| 23 | |
| 24 | |
| 25 | class TestWebapp(ZuulTestCase): |
Paul Belanger | 6349d15 | 2016-10-30 16:21:17 -0400 | [diff] [blame] | 26 | tenant_config_file = 'config/single-tenant/main.yaml' |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 27 | |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 28 | def setUp(self): |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 29 | super(TestWebapp, self).setUp() |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame^] | 30 | self.executor_server.hold_jobs_in_build = True |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 31 | A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A') |
Paul Belanger | 6349d15 | 2016-10-30 16:21:17 -0400 | [diff] [blame] | 32 | A.addApproval('code-review', 2) |
| 33 | self.fake_gerrit.addEvent(A.addApproval('approved', 1)) |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 34 | B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B') |
Clint Byrum | 77c184a | 2016-12-20 12:27:21 -0800 | [diff] [blame] | 35 | B.addApproval('code-review', 2) |
Paul Belanger | 6349d15 | 2016-10-30 16:21:17 -0400 | [diff] [blame] | 36 | self.fake_gerrit.addEvent(B.addApproval('approved', 1)) |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 37 | self.waitUntilSettled() |
| 38 | self.port = self.webapp.server.socket.getsockname()[1] |
| 39 | |
James E. Blair | e18d460 | 2017-01-05 11:17:28 -0800 | [diff] [blame] | 40 | def tearDown(self): |
Paul Belanger | 174a827 | 2017-03-14 13:20:10 -0400 | [diff] [blame^] | 41 | self.executor_server.hold_jobs_in_build = False |
| 42 | self.executor_server.release() |
James E. Blair | e18d460 | 2017-01-05 11:17:28 -0800 | [diff] [blame] | 43 | self.waitUntilSettled() |
| 44 | super(TestWebapp, self).tearDown() |
| 45 | |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 46 | def test_webapp_status(self): |
| 47 | "Test that we can filter to only certain changes in the webapp." |
| 48 | |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 49 | req = urllib.request.Request( |
Paul Belanger | 6349d15 | 2016-10-30 16:21:17 -0400 | [diff] [blame] | 50 | "http://localhost:%s/tenant-one/status" % self.port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 51 | f = urllib.request.urlopen(req) |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 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 |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 58 | req = urllib.request.Request( |
Paul Belanger | 6349d15 | 2016-10-30 16:21:17 -0400 | [diff] [blame] | 59 | "http://localhost:%s/tenant-one/status.json" % self.port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 60 | f = urllib.request.urlopen(req) |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 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 |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 67 | req = urllib.request.Request( |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 68 | "http://localhost:%s/status/foo" % self.port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 69 | self.assertRaises(urllib.error.HTTPError, urllib.request.urlopen, req) |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 70 | |
| 71 | def test_webapp_find_change(self): |
| 72 | # can we filter by change id |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 73 | req = urllib.request.Request( |
Clint Byrum | 77c184a | 2016-12-20 12:27:21 -0800 | [diff] [blame] | 74 | "http://localhost:%s/tenant-one/status/change/1,1" % self.port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 75 | f = urllib.request.urlopen(req) |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 76 | data = json.loads(f.read()) |
| 77 | |
| 78 | self.assertEqual(1, len(data), data) |
| 79 | self.assertEqual("org/project", data[0]['project']) |
| 80 | |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 81 | req = urllib.request.Request( |
Clint Byrum | 77c184a | 2016-12-20 12:27:21 -0800 | [diff] [blame] | 82 | "http://localhost:%s/tenant-one/status/change/2,1" % self.port) |
Morgan Fainberg | 293f7f8 | 2016-05-30 14:01:22 -0700 | [diff] [blame] | 83 | f = urllib.request.urlopen(req) |
Sean Dague | a8311bf | 2014-09-30 06:28:26 -0400 | [diff] [blame] | 84 | data = json.loads(f.read()) |
| 85 | |
| 86 | self.assertEqual(1, len(data), data) |
| 87 | self.assertEqual("org/project1", data[0]['project'], data) |