OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from branch_utility import BranchUtility, ChannelInfo | 5 from branch_utility import BranchUtility, ChannelInfo |
| 6 from test_data.canned_data import (CANNED_BRANCHES, CANNED_CHANNELS) |
6 | 7 |
7 class TestBranchUtility(object): | 8 class TestBranchUtility(object): |
8 '''Mimics BranchUtility to return valid-ish data without needing omahaproxy | 9 '''Mimics BranchUtility to return valid-ish data without needing omahaproxy |
9 data. | 10 data. |
10 ''' | 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 |
11 def GetAllChannelInfo(self): | 26 def GetAllChannelInfo(self): |
12 return [self.GetChannelInfo(channel) | 27 return [self.GetChannelInfo(channel) |
13 for channel in BranchUtility.GetAllChannelNames()] | 28 for channel in BranchUtility.GetAllChannelNames()] |
14 | 29 |
15 def GetChannelInfo(self, channel): | 30 def GetChannelInfo(self, channel): |
16 return ChannelInfo(channel, | 31 version = self._channels[channel] |
17 'fakebranch-%s' % channel, | 32 return ChannelInfo(channel, self.GetBranchForVersion(version), version) |
18 'fakeversion-%s' % channel) | |
19 | 33 |
20 def GetBranchForVersion(self, version): | 34 def GetBranchForVersion(self, version): |
21 return 'fakebranch-%s' % 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 |
OLD | NEW |