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