blob: 8268ef7a08ff10a6f9c150f4e20537311c6a2ae8 [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
Paul Belanger6349d152016-10-30 16:21:17 -040019from unittest import skip
Morgan Fainberg293f7f82016-05-30 14:01:22 -070020
21from six.moves import urllib
Sean Daguea8311bf2014-09-30 06:28:26 -040022
23from tests.base import ZuulTestCase
24
25
26class TestWebapp(ZuulTestCase):
Paul Belanger6349d152016-10-30 16:21:17 -040027 tenant_config_file = 'config/single-tenant/main.yaml'
Sean Daguea8311bf2014-09-30 06:28:26 -040028
Sean Daguea8311bf2014-09-30 06:28:26 -040029 def setUp(self):
Sean Daguea8311bf2014-09-30 06:28:26 -040030 super(TestWebapp, self).setUp()
Paul Belanger6349d152016-10-30 16:21:17 -040031 self.launch_server.hold_jobs_in_build = True
Sean Daguea8311bf2014-09-30 06:28:26 -040032 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
Paul Belanger6349d152016-10-30 16:21:17 -040033 A.addApproval('code-review', 2)
34 self.fake_gerrit.addEvent(A.addApproval('approved', 1))
Sean Daguea8311bf2014-09-30 06:28:26 -040035 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
Paul Belanger6349d152016-10-30 16:21:17 -040036 A.addApproval('code-review', 2)
37 self.fake_gerrit.addEvent(B.addApproval('approved', 1))
Sean Daguea8311bf2014-09-30 06:28:26 -040038 self.waitUntilSettled()
39 self.port = self.webapp.server.socket.getsockname()[1]
40
James E. Blaire18d4602017-01-05 11:17:28 -080041 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 Daguea8311bf2014-09-30 06:28:26 -040047 def test_webapp_status(self):
48 "Test that we can filter to only certain changes in the webapp."
49
Morgan Fainberg293f7f82016-05-30 14:01:22 -070050 req = urllib.request.Request(
Paul Belanger6349d152016-10-30 16:21:17 -040051 "http://localhost:%s/tenant-one/status" % self.port)
Morgan Fainberg293f7f82016-05-30 14:01:22 -070052 f = urllib.request.urlopen(req)
Sean Daguea8311bf2014-09-30 06:28:26 -040053 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 Fainberg293f7f82016-05-30 14:01:22 -070059 req = urllib.request.Request(
Paul Belanger6349d152016-10-30 16:21:17 -040060 "http://localhost:%s/tenant-one/status.json" % self.port)
Morgan Fainberg293f7f82016-05-30 14:01:22 -070061 f = urllib.request.urlopen(req)
Sean Daguea8311bf2014-09-30 06:28:26 -040062 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 Fainberg293f7f82016-05-30 14:01:22 -070068 req = urllib.request.Request(
Sean Daguea8311bf2014-09-30 06:28:26 -040069 "http://localhost:%s/status/foo" % self.port)
Morgan Fainberg293f7f82016-05-30 14:01:22 -070070 self.assertRaises(urllib.error.HTTPError, urllib.request.urlopen, req)
Sean Daguea8311bf2014-09-30 06:28:26 -040071
Paul Belanger6349d152016-10-30 16:21:17 -040072 @skip("Disabled for early v3 development")
Sean Daguea8311bf2014-09-30 06:28:26 -040073 def test_webapp_find_change(self):
74 # can we filter by change id
Morgan Fainberg293f7f82016-05-30 14:01:22 -070075 req = urllib.request.Request(
Sean Daguea8311bf2014-09-30 06:28:26 -040076 "http://localhost:%s/status/change/1,1" % self.port)
Morgan Fainberg293f7f82016-05-30 14:01:22 -070077 f = urllib.request.urlopen(req)
Sean Daguea8311bf2014-09-30 06:28:26 -040078 data = json.loads(f.read())
79
80 self.assertEqual(1, len(data), data)
81 self.assertEqual("org/project", data[0]['project'])
82
Morgan Fainberg293f7f82016-05-30 14:01:22 -070083 req = urllib.request.Request(
Sean Daguea8311bf2014-09-30 06:28:26 -040084 "http://localhost:%s/status/change/2,1" % self.port)
Morgan Fainberg293f7f82016-05-30 14:01:22 -070085 f = urllib.request.urlopen(req)
Sean Daguea8311bf2014-09-30 06:28:26 -040086 data = json.loads(f.read())
87
88 self.assertEqual(1, len(data), data)
89 self.assertEqual("org/project1", data[0]['project'], data)