1 # Copyright 2013 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. 4 5 from branch_utility import BranchUtility, ChannelInfo 6 from test_data.canned_data import (CANNED_BRANCHES, CANNED_CHANNELS) 7 8 class TestBranchUtility(object): 9 '''Mimics BranchUtility to return valid-ish data without needing omahaproxy 10 data. 11 ''' 12 def __init__(self, branches, channels): 13 ''' Parameters: |branches| is a mapping of versions to branches, and 14 |channels| is a mapping of channels to versions. 15 ''' 16 self._branches = branches 17 self._channels = channels 18 19 @staticmethod 20 def CreateWithCannedData(): 21 '''Returns a TestBranchUtility that uses 'canned' test data pulled from 22 older branches of SVN data. 23 ''' 24 return TestBranchUtility(CANNED_BRANCHES, CANNED_CHANNELS) 25 26 def GetAllChannelInfo(self): 27 return [self.GetChannelInfo(channel) 28 for channel in BranchUtility.GetAllChannelNames()] 29 30 def GetChannelInfo(self, channel): 31 version = self._channels[channel] 32 return ChannelInfo(channel, self.GetBranchForVersion(version), version) 33 34 def GetBranchForVersion(self, version): 35 return self._branches[version] 36 37 def GetChannelForVersion(self, version): 38 for channel in self._channels.iterkeys(): 39 if self._channels[channel] == version: 40 return channel 41