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

Unified Diff: tools/auto_bisect/query_crbug_test.py

Issue 697713003: Aborting bisect early when the bug specified in the bisect config is closed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing type=str since it's the default and rebasing Created 6 years, 1 month 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 | « tools/auto_bisect/query_crbug.py ('k') | tools/auto_bisect/test_data/closed.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/auto_bisect/query_crbug_test.py
diff --git a/tools/auto_bisect/query_crbug_test.py b/tools/auto_bisect/query_crbug_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..40e6fa853eec8b588cfe0188daf6d95395cfb7f0
--- /dev/null
+++ b/tools/auto_bisect/query_crbug_test.py
@@ -0,0 +1,82 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+import sys
+import unittest
+import urllib2
+
+from query_crbug import CheckIssueClosed
+
+SRC = os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)
+sys.path.append(os.path.join(SRC, 'third_party', 'pymock'))
+
+import mock
+
+_current_directory = os.path.dirname(__file__)
+_test_data_directory = os.path.join(_current_directory, 'test_data')
+
+# These strings are simulated responses to various conditions when querying
+# the chromium issue tracker.
+CLOSED_ISSUE_DATA = open(os.path.join(_test_data_directory,
+ 'closed.json')).read()
+OPEN_ISSUE_DATA = open(os.path.join(_test_data_directory,
+ 'open.json')).read()
+UNEXPECTED_FORMAT_DATA = CLOSED_ISSUE_DATA.replace('issues$state', 'gibberish')
+BROKEN_ISSUE_DATA = "\n<HTML><HEAD><TITLE>Not a JSON Doc</TITLE></HEAD></HTML>"
+
+
+class mockResponse(object):
+ def __init__(self, result):
+ self._result = result
+
+ def read(self):
+ return self._result
+
+
+def mockUrlOpen(url):
+ # Note that these strings DO NOT represent http responses. They are just
+ # memorable numeric bug ids to use.
+ if '200' in url:
+ return mockResponse(CLOSED_ISSUE_DATA)
+ elif '201' in url:
+ return mockResponse(OPEN_ISSUE_DATA)
+ elif '300' in url:
+ return mockResponse(UNEXPECTED_FORMAT_DATA)
+ elif '403' in url:
+ raise urllib2.URLError('')
+ elif '404' in url:
+ return mockResponse('')
+ elif '500' in url:
+ return mockResponse(BROKEN_ISSUE_DATA)
+
+
+class crbugQueryTest(unittest.TestCase):
+ @mock.patch('urllib2.urlopen',mockUrlOpen)
+ def testClosedIssueIsClosed(self):
+ self.assertTrue(CheckIssueClosed(200))
+
+ @mock.patch('urllib2.urlopen',mockUrlOpen)
+ def testOpenIssueIsNotClosed(self):
+ self.assertFalse(CheckIssueClosed(201))
+
+ @mock.patch('urllib2.urlopen',mockUrlOpen)
+ def testUnexpectedFormat(self):
+ self.assertFalse(CheckIssueClosed(300))
+
+ @mock.patch('urllib2.urlopen',mockUrlOpen)
+ def testUrlError(self):
+ self.assertFalse(CheckIssueClosed(403))
+
+ @mock.patch('urllib2.urlopen',mockUrlOpen)
+ def testEmptyResponse(self):
+ self.assertFalse(CheckIssueClosed(404))
+
+ @mock.patch('urllib2.urlopen',mockUrlOpen)
+ def testBrokenResponse(self):
+ self.assertFalse(CheckIssueClosed(500))
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « tools/auto_bisect/query_crbug.py ('k') | tools/auto_bisect/test_data/closed.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698