2 # Copyright (c) 2012 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.
10 from branch_utility
import BranchUtility
, ChannelInfo
11 from fake_url_fetcher
import FakeUrlFetcher
12 from object_store_creator
import ObjectStoreCreator
15 class BranchUtilityTest(unittest
.TestCase
):
18 self
._branch
_util
= BranchUtility(
19 os
.path
.join('branch_utility', 'first.json'),
20 os
.path
.join('branch_utility', 'second.json'),
21 FakeUrlFetcher(os
.path
.join(sys
.path
[0], 'test_data')),
22 ObjectStoreCreator
.ForTest())
24 def testSplitChannelNameFromPath(self
):
25 self
.assertEquals(('stable', 'extensions/stuff.html'),
26 self
._branch
_util
.SplitChannelNameFromPath(
27 'stable/extensions/stuff.html'))
28 self
.assertEquals(('dev', 'extensions/stuff.html'),
29 self
._branch
_util
.SplitChannelNameFromPath(
30 'dev/extensions/stuff.html'))
31 self
.assertEquals(('beta', 'extensions/stuff.html'),
32 self
._branch
_util
.SplitChannelNameFromPath(
33 'beta/extensions/stuff.html'))
34 self
.assertEquals(('trunk', 'extensions/stuff.html'),
35 self
._branch
_util
.SplitChannelNameFromPath(
36 'trunk/extensions/stuff.html'))
37 self
.assertEquals((None, 'extensions/stuff.html'),
38 self
._branch
_util
.SplitChannelNameFromPath(
39 'extensions/stuff.html'))
40 self
.assertEquals((None, 'apps/stuff.html'),
41 self
._branch
_util
.SplitChannelNameFromPath(
43 self
.assertEquals((None, 'extensions/dev/stuff.html'),
44 self
._branch
_util
.SplitChannelNameFromPath(
45 'extensions/dev/stuff.html'))
46 self
.assertEquals((None, 'stuff.html'),
47 self
._branch
_util
.SplitChannelNameFromPath(
50 def testNewestChannel(self
):
51 self
.assertEquals('trunk',
52 self
._branch
_util
.NewestChannel(('trunk', 'dev', 'beta', 'stable')))
53 self
.assertEquals('trunk',
54 self
._branch
_util
.NewestChannel(('stable', 'beta', 'dev', 'trunk')))
55 self
.assertEquals('dev',
56 self
._branch
_util
.NewestChannel(('stable', 'beta', 'dev')))
57 self
.assertEquals('dev',
58 self
._branch
_util
.NewestChannel(('dev', 'beta', 'stable')))
59 self
.assertEquals('beta',
60 self
._branch
_util
.NewestChannel(('beta', 'stable')))
61 self
.assertEquals('beta',
62 self
._branch
_util
.NewestChannel(('stable', 'beta')))
63 self
.assertEquals('stable', self
._branch
_util
.NewestChannel(('stable',)))
64 self
.assertEquals('beta', self
._branch
_util
.NewestChannel(('beta',)))
65 self
.assertEquals('dev', self
._branch
_util
.NewestChannel(('dev',)))
66 self
.assertEquals('trunk', self
._branch
_util
.NewestChannel(('trunk',)))
69 oldest_stable_info
= ChannelInfo('stable', '963', 17)
70 older_stable_info
= ChannelInfo('stable', '1025', 18)
71 old_stable_info
= ChannelInfo('stable', '1084', 19)
72 sort_of_old_stable_info
= ChannelInfo('stable', '1364', 25)
73 stable_info
= ChannelInfo('stable', '1410', 26)
74 beta_info
= ChannelInfo('beta', '1453', 27)
75 dev_info
= ChannelInfo('dev', '1500', 28)
76 trunk_info
= ChannelInfo('trunk', 'trunk', 'trunk')
78 self
.assertEquals(older_stable_info
,
79 self
._branch
_util
.Newer(oldest_stable_info
))
80 self
.assertEquals(old_stable_info
,
81 self
._branch
_util
.Newer(older_stable_info
))
82 self
.assertEquals(stable_info
,
83 self
._branch
_util
.Newer(sort_of_old_stable_info
))
84 self
.assertEquals(beta_info
, self
._branch
_util
.Newer(stable_info
))
85 self
.assertEquals(dev_info
, self
._branch
_util
.Newer(beta_info
))
86 self
.assertEquals(trunk_info
, self
._branch
_util
.Newer(dev_info
))
87 # Test the upper limit.
88 self
.assertEquals(None, self
._branch
_util
.Newer(trunk_info
))
92 trunk_info
= ChannelInfo('trunk', 'trunk', 'trunk')
93 dev_info
= ChannelInfo('dev', '1500', 28)
94 beta_info
= ChannelInfo('beta', '1453', 27)
95 stable_info
= ChannelInfo('stable', '1410', 26)
96 old_stable_info
= ChannelInfo('stable', '1364', 25)
97 older_stable_info
= ChannelInfo('stable', '1312', 24)
98 oldest_stable_info
= ChannelInfo('stable', '396', 5)
100 self
.assertEquals(dev_info
, self
._branch
_util
.Older(trunk_info
))
101 self
.assertEquals(beta_info
, self
._branch
_util
.Older(dev_info
))
102 self
.assertEquals(stable_info
, self
._branch
_util
.Older(beta_info
))
103 self
.assertEquals(old_stable_info
, self
._branch
_util
.Older(stable_info
))
104 self
.assertEquals(older_stable_info
,
105 self
._branch
_util
.Older(old_stable_info
))
106 # Test the lower limit.
107 self
.assertEquals(None, self
._branch
_util
.Older(oldest_stable_info
))
109 def testGetChannelInfo(self
):
110 trunk_info
= ChannelInfo('trunk', 'trunk', 'trunk')
111 self
.assertEquals(trunk_info
, self
._branch
_util
.GetChannelInfo('trunk'))
113 dev_info
= ChannelInfo('dev', '1500', 28)
114 self
.assertEquals(dev_info
, self
._branch
_util
.GetChannelInfo('dev'))
116 beta_info
= ChannelInfo('beta', '1453', 27)
117 self
.assertEquals(beta_info
, self
._branch
_util
.GetChannelInfo('beta'))
119 stable_info
= ChannelInfo('stable', '1410', 26)
120 self
.assertEquals(stable_info
, self
._branch
_util
.GetChannelInfo('stable'))
122 def testGetLatestVersionNumber(self
):
123 self
.assertEquals(28, self
._branch
_util
.GetLatestVersionNumber())
125 def testGetBranchForVersion(self
):
126 self
.assertEquals('1500',
127 self
._branch
_util
.GetBranchForVersion(28))
128 self
.assertEquals('1453',
129 self
._branch
_util
.GetBranchForVersion(27))
130 self
.assertEquals('1410',
131 self
._branch
_util
.GetBranchForVersion(26))
132 self
.assertEquals('1364',
133 self
._branch
_util
.GetBranchForVersion(25))
134 self
.assertEquals('1312',
135 self
._branch
_util
.GetBranchForVersion(24))
136 self
.assertEquals('1271',
137 self
._branch
_util
.GetBranchForVersion(23))
138 self
.assertEquals('1229',
139 self
._branch
_util
.GetBranchForVersion(22))
140 self
.assertEquals('1180',
141 self
._branch
_util
.GetBranchForVersion(21))
142 self
.assertEquals('1132',
143 self
._branch
_util
.GetBranchForVersion(20))
144 self
.assertEquals('1084',
145 self
._branch
_util
.GetBranchForVersion(19))
146 self
.assertEquals('1025',
147 self
._branch
_util
.GetBranchForVersion(18))
148 self
.assertEquals('963',
149 self
._branch
_util
.GetBranchForVersion(17))
150 self
.assertEquals('696',
151 self
._branch
_util
.GetBranchForVersion(11))
152 self
.assertEquals('396',
153 self
._branch
_util
.GetBranchForVersion(5))
155 def testGetChannelForVersion(self
):
156 self
.assertEquals('trunk',
157 self
._branch
_util
.GetChannelForVersion('trunk'))
158 self
.assertEquals('dev',
159 self
._branch
_util
.GetChannelForVersion(28))
160 self
.assertEquals('beta',
161 self
._branch
_util
.GetChannelForVersion(27))
162 self
.assertEquals('stable',
163 self
._branch
_util
.GetChannelForVersion(26))
164 self
.assertEquals('stable',
165 self
._branch
_util
.GetChannelForVersion(22))
166 self
.assertEquals('stable',
167 self
._branch
_util
.GetChannelForVersion(18))
168 self
.assertEquals('stable',
169 self
._branch
_util
.GetChannelForVersion(14))
170 self
.assertEquals(None,
171 self
._branch
_util
.GetChannelForVersion(30))
172 self
.assertEquals(None,
173 self
._branch
_util
.GetChannelForVersion(42))
176 if __name__
== '__main__':