Re-enable test_webapp_find_change

This makes the tenant name required in the URL, which I believe is desired
for now, but maybe there will be an all-tenant view or a default tenant
in the future.

Note that the setUp method for this test suite actually had a bug that
was only approving change A twice, rather than approving B.

Change-Id: I25bd11088719e8b3465563863123d93eff16030e
Story: 2000773
Task: 3433
This commit is contained in:
Clint Byrum 2016-12-20 12:27:21 -08:00
parent 93573e5e42
commit 77c184aa3a
2 changed files with 8 additions and 10 deletions

View File

@ -16,7 +16,6 @@
# under the License.
import json
from unittest import skip
from six.moves import urllib
@ -39,7 +38,7 @@ class TestWebapp(ZuulTestCase):
A.addApproval('code-review', 2)
self.fake_gerrit.addEvent(A.addApproval('approved', 1))
B = self.fake_gerrit.addFakeChange('org/project1', 'master', 'B')
A.addApproval('code-review', 2)
B.addApproval('code-review', 2)
self.fake_gerrit.addEvent(B.addApproval('approved', 1))
self.waitUntilSettled()
self.port = self.webapp.server.socket.getsockname()[1]
@ -69,11 +68,10 @@ class TestWebapp(ZuulTestCase):
"http://localhost:%s/status/foo" % self.port)
self.assertRaises(urllib.error.HTTPError, urllib.request.urlopen, req)
@skip("Disabled for early v3 development")
def test_webapp_find_change(self):
# can we filter by change id
req = urllib.request.Request(
"http://localhost:%s/status/change/1,1" % self.port)
"http://localhost:%s/tenant-one/status/change/1,1" % self.port)
f = urllib.request.urlopen(req)
data = json.loads(f.read())
@ -81,7 +79,7 @@ class TestWebapp(ZuulTestCase):
self.assertEqual("org/project", data[0]['project'])
req = urllib.request.Request(
"http://localhost:%s/status/change/2,1" % self.port)
"http://localhost:%s/tenant-one/status/change/2,1" % self.port)
f = urllib.request.urlopen(req)
data = json.loads(f.read())

View File

@ -63,7 +63,7 @@ class WebApp(threading.Thread):
def stop(self):
self.server.server_close()
def _changes_by_func(self, func):
def _changes_by_func(self, func, tenant_name):
"""Filter changes by a user provided function.
In order to support arbitrary collection of subsets of changes
@ -72,7 +72,7 @@ class WebApp(threading.Thread):
is a flattened list of those collected changes.
"""
status = []
jsonstruct = json.loads(self.cache)
jsonstruct = json.loads(self.cache[tenant_name])
for pipeline in jsonstruct['pipelines']:
for change_queue in pipeline['change_queues']:
for head in change_queue['heads']:
@ -81,11 +81,11 @@ class WebApp(threading.Thread):
status.append(copy.deepcopy(change))
return json.dumps(status)
def _status_for_change(self, rev):
def _status_for_change(self, rev, tenant_name):
"""Return the statuses for a particular change id X,Y."""
def func(change):
return change['id'] == rev
return self._changes_by_func(func)
return self._changes_by_func(func, tenant_name)
def _normalize_path(self, path):
# support legacy status.json as well as new /status
@ -119,7 +119,7 @@ class WebApp(threading.Thread):
response = webob.Response(body=self.cache[tenant_name],
content_type='application/json')
else:
status = self._status_for_change(path)
status = self._status_for_change(path, tenant_name)
if status:
response = webob.Response(body=status,
content_type='application/json')