Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(378)

Unified Diff: scripts/slave/unittests/gatekeeper_ng_test.py

Issue 895633002: Gatekeeper: use same authentication for reading status as for writing. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « scripts/slave/gatekeeper_ng.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/slave/unittests/gatekeeper_ng_test.py
diff --git a/scripts/slave/unittests/gatekeeper_ng_test.py b/scripts/slave/unittests/gatekeeper_ng_test.py
index 0ccf2e0b03902829b4bc5d51adaa4199c50ab229..593f2f0cf205137cb45005d75f04adadc147d4f4 100755
--- a/scripts/slave/unittests/gatekeeper_ng_test.py
+++ b/scripts/slave/unittests/gatekeeper_ng_test.py
@@ -372,7 +372,7 @@ class GatekeeperTest(unittest.TestCase):
self.url_calls.append(call)
if url in self.urls:
- return copy.copy(self.urls[url])
+ return copy.copy(self.urls[url](params))
else:
raise urllib2.HTTPError(url, 404, 'Not Found: %s' % url,
None, StringIO.StringIO(''))
@@ -386,7 +386,11 @@ class GatekeeperTest(unittest.TestCase):
def handle_url_fp(self, url, fp):
"""Add a file object to handle a mocked URL."""
setattr(fp, 'getcode', lambda: 200)
- self.urls[url] = fp
+ self.urls[url] = lambda _: fp
+
+ def handle_url_custom(self, url, handler):
+ """Handler func will be called with params as first argument."""
+ self.urls[url] = handler
def handle_url_str(self, url, response):
"""Add a string to handle a mocked URL."""
@@ -781,6 +785,21 @@ class GatekeeperTest(unittest.TestCase):
self.assertTrue(status_data['message'][0].startswith(
"Tree is open (Automatic"))
+ # Same as above and get_status_url requires bot login.
+ json_handler = self.urls.pop(self.get_status_url)
+ def handler(params):
+ if params == None:
+ return StringIO.StringIO("<blabla>Login Required</blabla>")
+ else:
+ return json_handler(params)
+ self.handle_url_custom(self.get_status_url, handler)
+ self.call_gatekeeper(build_db=build_db)
+ self.assertEquals(self.url_calls[-2]['url'], self.get_status_url)
+ self.assertIsNotNone(self.url_calls[-2]['params'])
+ status_data = urlparse.parse_qs(self.url_calls[-1]['params'])
+ self.assertTrue(status_data['message'][0].startswith(
+ "Tree is open (Automatic"))
+
# However, don't touch the tree status if a human set it.
self.handle_url_json(self.get_status_url, {
'message': 'closed, world is on fire',
« no previous file with comments | « scripts/slave/gatekeeper_ng.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698