Index: tools/auto_bisect/crbug_query_test.py |
diff --git a/tools/auto_bisect/crbug_query_test.py b/tools/auto_bisect/crbug_query_test.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c23fd57064004842522cc587b570a7679e25f148 |
--- /dev/null |
+++ b/tools/auto_bisect/crbug_query_test.py |
@@ -0,0 +1,70 @@ |
+# 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 crbug_query import checkIssueClosed |
+import crbug_query_test_data as data |
+ |
+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 |
+ |
+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(data.CLOSED_ISSUE_DATA) |
+ elif '201' in url: |
+ return mockResponse(data.OPEN_ISSUE_DATA) |
+ elif '300' in url: |
+ return mockResponse(data.UNEXPECTED_FORMAT_DATA) |
+ elif '403' in url: |
+ raise urllib2.URLError('') |
+ elif '404' in url: |
+ return mockResponse('') |
+ elif '500' in url: |
+ return mockResponse(data.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() |