| OLD | NEW |
| 1 #!/usr/bin/env python2.7 | 1 #!/usr/bin/env python2.7 |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Unit test suite for common.cros_chromite.""" | 6 """Unit test suite for common.cros.chromite.""" |
| 7 | 7 |
| 8 import test_env | 8 import test_env |
| 9 | 9 |
| 10 import base64 | 10 import base64 |
| 11 import json | 11 import json |
| 12 import unittest | 12 import unittest |
| 13 | 13 |
| 14 from common import cros_chromite | 14 from common import cros_chromite |
| 15 | 15 |
| 16 | 16 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 base, suffix, category = cros_chromite.ChromiteTarget.Categorize( | 175 base, suffix, category = cros_chromite.ChromiteTarget.Categorize( |
| 176 name, | 176 name, |
| 177 build_type=build_type) | 177 build_type=build_type) |
| 178 self.assertEqual( | 178 self.assertEqual( |
| 179 (base, suffix, category), (exp_base, exp_suffix, exp_category)) | 179 (base, suffix, category), (exp_base, exp_suffix, exp_category)) |
| 180 | 180 |
| 181 | 181 |
| 182 class ChromitePinManagerTestCase(unittest.TestCase): | 182 class ChromitePinManagerTestCase(unittest.TestCase): |
| 183 | 183 |
| 184 def testGetPinnedBranch_PinnedBranchReturnsPinnedValue(self): | 184 def testGetPinnedBranch_PinnedBranchReturnsPinnedValue(self): |
| 185 pm = cros_chromite.ChromitePinManager(pinned={'a': 'b'}, require=True) | 185 pm = cros_chromite.ChromitePinManager( |
| 186 'test', |
| 187 pinned={'a': 'b'}, |
| 188 require=True) |
| 186 self.assertEqual(pm.GetPinnedBranch('a'), 'b') | 189 self.assertEqual(pm.GetPinnedBranch('a'), 'b') |
| 187 | 190 |
| 188 def testGetPinnedBranch_UnpinnedBranchReturnsBranch(self): | 191 def testGetPinnedBranch_UnpinnedBranchReturnsBranch(self): |
| 189 pm = cros_chromite.ChromitePinManager(pinned={'a': 'b'}, require=False) | 192 pm = cros_chromite.ChromitePinManager( |
| 193 'test', |
| 194 pinned={'a': 'b'}, |
| 195 require=False) |
| 190 self.assertEqual(pm.GetPinnedBranch('foo'), 'foo') | 196 self.assertEqual(pm.GetPinnedBranch('foo'), 'foo') |
| 191 | 197 |
| 192 def testGetPinnedBranch_UnpinnedBranchReturnsErrorWithRequiredPinning(self): | 198 def testGetPinnedBranch_UnpinnedBranchReturnsErrorWithRequiredPinning(self): |
| 193 pm = cros_chromite.ChromitePinManager(pinned={'a': 'b'}, require=True) | 199 pm = cros_chromite.ChromitePinManager( |
| 200 'test', |
| 201 pinned={'a': 'b'}, |
| 202 require=True) |
| 194 self.assertRaises(cros_chromite.ChromiteError, | 203 self.assertRaises(cros_chromite.ChromiteError, |
| 195 pm.GetPinnedBranch, 'foo') | 204 pm.GetPinnedBranch, 'foo') |
| 196 | 205 |
| 197 | 206 |
| 198 class ChromiteConfigManagerTestCase(unittest.TestCase): | 207 class ChromiteConfigManagerTestCase(unittest.TestCase): |
| 199 | 208 |
| 200 def setUp(self): | 209 def setUp(self): |
| 201 self.cache = MockConfigCache({ | 210 self.cache = MockConfigCache({ |
| 202 ('test', 'v1'): '{}', | 211 ('test', 'v1'): '{}', |
| 203 ('test', 'v_invalid'): '{NOT JSON}', | 212 ('test', 'v_invalid'): '{NOT JSON}', |
| 204 }) | 213 }) |
| 205 | 214 |
| 206 def testGetConfig_ValidSucceeds(self): | 215 def testGetConfig_ValidSucceeds(self): |
| 207 manager = cros_chromite.ChromiteConfigManager(self.cache, | 216 manager = cros_chromite.ChromiteConfigManager(self.cache, |
| 208 cros_chromite.ChromitePinManager({'test': 'v1'})) | 217 cros_chromite.ChromitePinManager( |
| 218 'test', |
| 219 {'test': 'v1'})) |
| 209 self.assertTrue(isinstance(manager.GetConfig('test'), | 220 self.assertTrue(isinstance(manager.GetConfig('test'), |
| 210 cros_chromite.ChromiteConfig)) | 221 cros_chromite.ChromiteConfig)) |
| 211 | 222 |
| 212 def testGetConfig_InvalidJsonRaises(self): | 223 def testGetConfig_InvalidJsonRaises(self): |
| 213 manager = cros_chromite.ChromiteConfigManager(self.cache, | 224 manager = cros_chromite.ChromiteConfigManager(self.cache, |
| 214 cros_chromite.ChromitePinManager({'test': 'v_invalid'})) | 225 cros_chromite.ChromitePinManager( |
| 226 'test', |
| 227 {'test': 'v_invalid'})) |
| 215 self.assertRaises(cros_chromite.ChromiteError, manager.GetConfig, 'test') | 228 self.assertRaises(cros_chromite.ChromiteError, manager.GetConfig, 'test') |
| 216 | 229 |
| 217 def testGetConfig_MissingRaises(self): | 230 def testGetConfig_MissingRaises(self): |
| 218 manager = cros_chromite.ChromiteConfigManager(self.cache) | 231 manager = cros_chromite.ChromiteConfigManager(self.cache) |
| 219 self.assertRaises(cros_chromite.ChromiteError, manager.GetConfig, 'foo') | 232 self.assertRaises(cros_chromite.ChromiteError, manager.GetConfig, 'foo') |
| 220 | 233 |
| 221 | 234 |
| 222 class ChromiteFetcherTestCase(unittest.TestCase): | 235 class ChromiteFetcherTestCase(unittest.TestCase): |
| 223 | 236 |
| 224 def setUp(self): | 237 def setUp(self): |
| 225 self.fetcher = cros_chromite.ChromiteFetcher( | 238 self.fetcher = cros_chromite.ChromiteFetcher( |
| 226 cros_chromite.ChromitePinManager({'test': 'v1'}) | 239 cros_chromite.ChromitePinManager( |
| 240 'test', |
| 241 {'test': 'v1'}) |
| 227 ) | 242 ) |
| 228 | 243 |
| 229 @staticmethod | 244 @staticmethod |
| 230 def _configUrlForBranch(branch): | 245 def _configUrlForBranch(branch): |
| 231 return '%s/+/%s/%s?format=text' % ( | 246 return '%s/+/%s/%s?format=text' % ( |
| 232 cros_chromite.ChromiteFetcher.CHROMITE_GITILES_BASE, | 247 cros_chromite.ChromiteFetcher.CHROMITE_GITILES_BASE, |
| 233 branch, | 248 branch, |
| 234 cros_chromite.ChromiteFetcher.CHROMITE_CONFIG_PATH, | 249 cros_chromite.ChromiteFetcher.CHROMITE_CONFIG_PATH, |
| 235 ) | 250 ) |
| 236 | 251 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 247 | 262 |
| 248 def testFetch_NotBase64(self): | 263 def testFetch_NotBase64(self): |
| 249 def _MockGetText(_url): | 264 def _MockGetText(_url): |
| 250 return 'Not Valid Base64' | 265 return 'Not Valid Base64' |
| 251 self.fetcher._GetText = _MockGetText | 266 self.fetcher._GetText = _MockGetText |
| 252 self.assertRaises(cros_chromite.GitilesError, self.fetcher, 'test', None) | 267 self.assertRaises(cros_chromite.GitilesError, self.fetcher, 'test', None) |
| 253 | 268 |
| 254 | 269 |
| 255 if __name__ == '__main__': | 270 if __name__ == '__main__': |
| 256 unittest.main() | 271 unittest.main() |
| OLD | NEW |