Home | History | Annotate | Download | only in bisect_lib
      1 #!/usr/bin/env python
      2 # Copyright 2015 The Chromium Authors. All rights reserved.
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 
      6 import os
      7 import sys
      8 import unittest
      9 
     10 _CATAPULT_PATH = os.path.abspath(os.path.join(
     11     os.path.dirname(__file__), os.path.pardir, os.path.pardir))
     12 sys.path.insert(0, os.path.join(_CATAPULT_PATH, 'third_party', 'mock'))
     13 
     14 import mock
     15 
     16 from bisect_lib import fetch_intervening_revisions
     17 
     18 _TEST_DATA = os.path.join(os.path.dirname(__file__), 'test_data')
     19 
     20 
     21 class FetchInterveningRevisionsTest(unittest.TestCase):
     22 
     23   def testFetchInterveningRevisions(self):
     24     response = open(os.path.join(_TEST_DATA, 'MOCK_RANGE_RESPONSE_1'))
     25     with mock.patch('urllib2.urlopen', mock.MagicMock(return_value=response)):
     26       revs = fetch_intervening_revisions.FetchInterveningRevisions(
     27           '53fc07eb478520a80af6bf8b62be259bb55db0f1',
     28           'c89130e28fd01062104e1be7f3a6fc3abbb80ca9',
     29           depot_name='chromium')
     30     self.assertEqual(
     31         revs, [
     32             ('32ce3b13924d84004a3e05c35942626cbe93cbbd', '356382'),
     33             ('07a6d9854efab6677b880defa924758334cfd47d', '356383'),
     34             ('22e49fb496d6ffa122c470f6071d47ccb4ccb672', '356384'),
     35             ('5dbc149bebecea186b693b3d780b6965eeffed0f', '356385'),
     36             ('ebd5f102ee89a4be5c98815c02c444fbf2b6b040', '356386'),
     37             ('84f6037e951c21a3b00bd3ddd034f258da6839b5', '356387'),
     38             ('48c1471f1f503246dd66753a4c7588d77282d2df', '356388'),
     39             ('66aeb2b7084850d09f3fccc7d7467b57e4da1882', '356389'),
     40             ('01542ac6d0fbec6aa78e33e6c7ec49a582072ea9', '356390'),
     41             ('8414732168a8867a5d6bd45eaade68a5820a9e34', '356391'),
     42             ('4f81be50501fbc02d7e44df0d56032e5885e19b6', '356392'),
     43             ('7bd1741893bd4e233b5562a6926d7e395d558343', '356393'),
     44             ('ee261f306c3c66e96339aa1026d62a6d953302fe', '356394'),
     45             ('f1c777e3f97a16cc6a3aa922a23602fa59412989', '356395'),
     46             ('8fcc8af20a3d41b0512e3b1486e4dc7de528a72b', '356396'),
     47             ('3861789af25e2d3502f0fb7080da5785d31308aa', '356397'),
     48             ('6feaa73a54d0515ad2940709161ca0a5ad91d1f8', '356398'),
     49             ('2e93263dc74f0496100435e1fd7232e9e8323af0', '356399')
     50         ])
     51 
     52   def testFetchInterveningRevisionsPagination(self):
     53 
     54     def MockUrlopen(url):
     55       if 's=' not in url:
     56         return open(os.path.join(_TEST_DATA, 'MOCK_RANGE_RESPONSE_2_PAGE_1'))
     57       return open(os.path.join(_TEST_DATA, 'MOCK_RANGE_RESPONSE_2_PAGE_2'))
     58 
     59     with mock.patch('urllib2.urlopen', MockUrlopen):
     60       revs = fetch_intervening_revisions.FetchInterveningRevisions(
     61           '7bd1741893bd4e233b5562a6926d7e395d558343',
     62           '3861789af25e2d3502f0fb7080da5785d31308aa',
     63           depot_name='chromium')
     64     self.assertEqual(
     65         revs, [
     66             ('ee261f306c3c66e96339aa1026d62a6d953302fe', '356394'),
     67             ('f1c777e3f97a16cc6a3aa922a23602fa59412989', '356395'),
     68             ('8fcc8af20a3d41b0512e3b1486e4dc7de528a72b', '356396'),
     69         ])
     70 
     71 
     72 if __name__ == '__main__':
     73   unittest.main()
     74