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.
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'))
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
,
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
):
39 # Note that these strings DO NOT represent http responses. They are just
40 # memorable numeric bug ids to use.
42 return MockResponse(CLOSED_ISSUE_DATA
)
44 return MockResponse(OPEN_ISSUE_DATA
)
46 return MockResponse(UNEXPECTED_FORMAT_DATA
)
48 raise urllib2
.URLError('')
50 return MockResponse('')
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__':