blob: 555c08f331816565326d82960ca00e280413d1a8 [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
Morgan Fainberg293f7f82016-05-30 14:01:22 -070019
20from six.moves import urllib
Sean Daguea8311bf2014-09-30 06:28:26 -040021
22from tests.base import ZuulTestCase
23
24
25class TestWebapp(ZuulTestCase):
26
27 def _cleanup(self):
28 self.worker.hold_jobs_in_build = False
29 self.worker.release()
30 self.waitUntilSettled()
31
32 def setUp(self):
James E. Blair509cada2015-12-08 16:31:16 -080033 self.skip("Disabled for early v3 development")
34
Sean Daguea8311bf2014-09-30 06:28:26 -040035 super(TestWebapp, self).setUp()
36 self.addCleanup(self._cleanup)
37 self.worker.hold_jobs_in_build = True
38 A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
39 A.addApproval('CRVW', 2)
40 self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
41 B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
42 B.addApproval('CRVW', 2)
43 self.fake_gerrit.addEvent(B.addApproval('APRV', 1))
44 self.waitUntilSettled()
45 self.port = self.webapp.server.socket.getsockname()[1]
46
47 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(
Sean Daguea8311bf2014-09-30 06:28:26 -040051 "http://localhost:%s/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(
Sean Daguea8311bf2014-09-30 06:28:26 -040060 "http://localhost:%s/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
72 def test_webapp_find_change(self):
73 # can we filter by change id
Morgan Fainberg293f7f82016-05-30 14:01:22 -070074 req = urllib.request.Request(
Sean Daguea8311bf2014-09-30 06:28:26 -040075 "http://localhost:%s/status/change/1,1" % self.port)
Morgan Fainberg293f7f82016-05-30 14:01:22 -070076 f = urllib.request.urlopen(req)
Sean Daguea8311bf2014-09-30 06:28:26 -040077 data = json.loads(f.read())
78
79 self.assertEqual(1, len(data), data)
80 self.assertEqual("org/project", data[0]['project'])
81
Morgan Fainberg293f7f82016-05-30 14:01:22 -070082 req = urllib.request.Request(
Sean Daguea8311bf2014-09-30 06:28:26 -040083 "http://localhost:%s/status/change/2,1" % self.port)
Morgan Fainberg293f7f82016-05-30 14:01:22 -070084 f = urllib.request.urlopen(req)
Sean Daguea8311bf2014-09-30 06:28:26 -040085 data = json.loads(f.read())
86
87 self.assertEqual(1, len(data), data)
88 self.assertEqual("org/project1", data[0]['project'], data)