Cancel on-going scan when change directory is requested.
[chromium-blink-merge.git] / tools / auto_bisect / query_crbug_test.py
blob5406487542f1e9ca239f8c15884c51e9815e140e
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 import os
6 import sys
7 import unittest
8 import urllib2
10 from query_crbug import CheckIssueClosed
12 SRC = os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)
13 sys.path.append(os.path.join(SRC, 'third_party', 'pymock'))
15 import mock
17 _current_directory = os.path.dirname(__file__)
18 _test_data_directory = os.path.join(_current_directory, 'test_data')
20 # These strings are simulated responses to various conditions when querying
21 # the chromium issue tracker.
22 CLOSED_ISSUE_DATA = open(os.path.join(_test_data_directory,
23 'closed.json')).read()
24 OPEN_ISSUE_DATA = open(os.path.join(_test_data_directory,
25 'open.json')).read()
26 UNEXPECTED_FORMAT_DATA = CLOSED_ISSUE_DATA.replace('issues$state', 'gibberish')
27 BROKEN_ISSUE_DATA = "\n<HTML><HEAD><TITLE>Not a JSON Doc</TITLE></HEAD></HTML>"
30 class MockResponse(object):
31 def __init__(self, result):
32 self._result = result
34 def read(self):
35 return self._result
38 def MockUrlOpen(url):
39 # Note that these strings DO NOT represent http responses. They are just
40 # memorable numeric bug ids to use.
41 if '200' in url:
42 return MockResponse(CLOSED_ISSUE_DATA)
43 elif '201' in url:
44 return MockResponse(OPEN_ISSUE_DATA)
45 elif '300' in url:
46 return MockResponse(UNEXPECTED_FORMAT_DATA)
47 elif '403' in url:
48 raise urllib2.URLError('')
49 elif '404' in url:
50 return MockResponse('')
51 elif '500' in url:
52 return MockResponse(BROKEN_ISSUE_DATA)
55 class crbugQueryTest(unittest.TestCase):
56 @mock.patch('urllib2.urlopen', MockUrlOpen)
57 def testClosedIssueIsClosed(self):
58 self.assertTrue(CheckIssueClosed(200))
60 @mock.patch('urllib2.urlopen', MockUrlOpen)
61 def testOpenIssueIsNotClosed(self):
62 self.assertFalse(CheckIssueClosed(201))
64 @mock.patch('urllib2.urlopen', MockUrlOpen)
65 def testUnexpectedFormat(self):
66 self.assertFalse(CheckIssueClosed(300))
68 @mock.patch('urllib2.urlopen', MockUrlOpen)
69 def testUrlError(self):
70 self.assertFalse(CheckIssueClosed(403))
72 @mock.patch('urllib2.urlopen', MockUrlOpen)
73 def testEmptyResponse(self):
74 self.assertFalse(CheckIssueClosed(404))
76 @mock.patch('urllib2.urlopen', MockUrlOpen)
77 def testBrokenResponse(self):
78 self.assertFalse(CheckIssueClosed(500))
81 if __name__ == '__main__':
82 unittest.main()