summaryrefslogtreecommitdiff
path: root/tests/unit/test_webapp.py
diff options
context:
space:
mode:
authorJames E. Blair <jeblair@redhat.com>2017-01-24 10:18:38 -0800
committerJames E. Blair <jeblair@redhat.com>2017-01-24 10:18:38 -0800
commit2a8e0fa5f1b4621205e6794657fcd15b551ac10d (patch)
tree0e59b19c26ee427a2ef1560c130dd5e10df13193 /tests/unit/test_webapp.py
parentac8df45bc5ce5fc618825d3427d8c06e61af64bd (diff)
downloadzuul-2a8e0fa5f1b4621205e6794657fcd15b551ac10d.tar.gz
Move tests into test/unit
This makes room for a sibling directory for nodepool functional tests. Change-Id: Iace94d313edb04192ac23a533ed967f076410980
Diffstat (limited to 'tests/unit/test_webapp.py')
-rw-r--r--tests/unit/test_webapp.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py
new file mode 100644
index 000000000..2211d1be4
--- /dev/null
+++ b/tests/unit/test_webapp.py
@@ -0,0 +1,87 @@
+#!/usr/bin/env python
+
+# Copyright 2014 Hewlett-Packard Development Company, L.P.
+# Copyright 2014 Rackspace Australia
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import json
+
+from six.moves import urllib
+
+from tests.base import ZuulTestCase
+
+
+class TestWebapp(ZuulTestCase):
+ tenant_config_file = 'config/single-tenant/main.yaml'
+
+ def setUp(self):
+ super(TestWebapp, self).setUp()
+ self.launch_server.hold_jobs_in_build = True
+ A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
+ A.addApproval('code-review', 2)
+ self.fake_gerrit.addEvent(A.addApproval('approved', 1))
+ B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
+ B.addApproval('code-review', 2)
+ self.fake_gerrit.addEvent(B.addApproval('approved', 1))
+ self.waitUntilSettled()
+ self.port = self.webapp.server.socket.getsockname()[1]
+
+ def tearDown(self):
+ self.launch_server.hold_jobs_in_build = False
+ self.launch_server.release()
+ self.waitUntilSettled()
+ super(TestWebapp, self).tearDown()
+
+ def test_webapp_status(self):
+ "Test that we can filter to only certain changes in the webapp."
+
+ req = urllib.request.Request(
+ "http://localhost:%s/tenant-one/status" % self.port)
+ f = urllib.request.urlopen(req)
+ data = json.loads(f.read())
+
+ self.assertIn('pipelines', data)
+
+ def test_webapp_status_compat(self):
+ # testing compat with status.json
+ req = urllib.request.Request(
+ "http://localhost:%s/tenant-one/status.json" % self.port)
+ f = urllib.request.urlopen(req)
+ data = json.loads(f.read())
+
+ self.assertIn('pipelines', data)
+
+ def test_webapp_bad_url(self):
+ # do we 404 correctly
+ req = urllib.request.Request(
+ "http://localhost:%s/status/foo" % self.port)
+ self.assertRaises(urllib.error.HTTPError, urllib.request.urlopen, req)
+
+ def test_webapp_find_change(self):
+ # can we filter by change id
+ req = urllib.request.Request(
+ "http://localhost:%s/tenant-one/status/change/1,1" % self.port)
+ f = urllib.request.urlopen(req)
+ data = json.loads(f.read())
+
+ self.assertEqual(1, len(data), data)
+ self.assertEqual("org/project", data[0]['project'])
+
+ req = urllib.request.Request(
+ "http://localhost:%s/tenant-one/status/change/2,1" % self.port)
+ f = urllib.request.urlopen(req)
+ data = json.loads(f.read())
+
+ self.assertEqual(1, len(data), data)
+ self.assertEqual("org/project1", data[0]['project'], data)