| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import base64 | 5 import base64 |
| 6 import collections | 6 import collections |
| 7 | 7 |
| 8 from testing_utils import testing | 8 from testing_utils import testing |
| 9 | 9 |
| 10 from common import chrome_dependency_fetcher | 10 from common import chrome_dependency_fetcher |
| 11 from common import deps_parser | 11 from common import deps_parser |
| 12 from common import git_repository | |
| 13 from common import repository | |
| 14 from common import retry_http_client | 12 from common import retry_http_client |
| 15 from common import http_client_appengine | 13 from common import http_client_appengine |
| 16 from common.dependency import Dependency, DependencyRoll | 14 from common.dependency import Dependency, DependencyRoll |
| 15 from lib.gitiles.git_repository import GitRepository |
| 16 from lib.gitiles import gitiles_repository |
| 17 | 17 |
| 18 | 18 |
| 19 class DummyGitRepository(repository.Repository): | 19 class MockGitilesRepository(GitRepository): |
| 20 """A class for mocking GitilesRepository. |
| 21 |
| 22 N.B., in order to use this class for mocking, every module we want to |
| 23 test with a mock GitilesRepository must not import that class directly. |
| 24 Instead they must import the gitiles_repository module and rely on |
| 25 dynamic dispatch to resolve the GitilesRepository attribute. Otherwise |
| 26 those modules will hold direct links to the real GitilesRepository |
| 27 class, and so won't dispatch into this mock class for our unit tests.""" |
| 28 |
| 20 RESPONSES = {} | 29 RESPONSES = {} |
| 21 | 30 |
| 22 def __init__(self, *_): | 31 def __init__(self, *_): |
| 23 pass | 32 pass |
| 24 | 33 |
| 25 def GetSource(self, path, revision): | 34 def GetSource(self, path, revision): |
| 26 return self.RESPONSES.get(path, {}).get(revision, None) | 35 return self.RESPONSES.get(path, {}).get(revision, None) |
| 27 | 36 |
| 28 | 37 |
| 29 class ChromiumDEPSTest(testing.AppengineTestCase): | 38 class ChromiumDEPSTest(testing.AppengineTestCase): |
| 30 DEPS_GIT = '.DEPS.git' | 39 DEPS_GIT = '.DEPS.git' |
| 31 DEPS = 'DEPS' | 40 DEPS = 'DEPS' |
| 32 deps_downloader = chrome_dependency_fetcher.DEPSDownloader( | 41 deps_downloader = chrome_dependency_fetcher.DEPSDownloader( |
| 33 DummyGitRepository()) | 42 MockGitilesRepository()) |
| 34 chrome_dep_fetcher = chrome_dependency_fetcher.ChromeDependencyFetcher( | 43 chrome_dep_fetcher = chrome_dependency_fetcher.ChromeDependencyFetcher( |
| 35 DummyGitRepository()) | 44 MockGitilesRepository()) |
| 36 | 45 |
| 37 def testUseDEPS_GIT(self): | 46 def testUseDEPS_GIT(self): |
| 38 revision = 'abc' | 47 revision = 'abc' |
| 39 expected_content = '.DEPS.git content' | 48 expected_content = '.DEPS.git content' |
| 40 | 49 |
| 41 DummyGitRepository.RESPONSES = { | 50 MockGitilesRepository.RESPONSES = { |
| 42 self.DEPS_GIT: { | 51 self.DEPS_GIT: { |
| 43 revision: expected_content | 52 revision: expected_content |
| 44 }, | 53 }, |
| 45 self.DEPS: { | 54 self.DEPS: { |
| 46 revision: 'DEPS test' | 55 revision: 'DEPS test' |
| 47 }, | 56 }, |
| 48 } | 57 } |
| 49 | 58 |
| 50 content = self.deps_downloader.Load( | 59 content = self.deps_downloader.Load( |
| 51 chrome_dependency_fetcher._CHROMIUM_REPO_MASTER, revision, 'DEPS') | 60 chrome_dependency_fetcher._CHROMIUM_REPO_MASTER, revision, 'DEPS') |
| 52 self.assertEqual(expected_content, content) | 61 self.assertEqual(expected_content, content) |
| 53 | 62 |
| 54 def testNotUseDEPS_GIT(self): | 63 def testNotUseDEPS_GIT(self): |
| 55 revision = 'abc' | 64 revision = 'abc' |
| 56 expected_content = 'DEPS test' | 65 expected_content = 'DEPS test' |
| 57 | 66 |
| 58 DummyGitRepository.RESPONSES = { | 67 MockGitilesRepository.RESPONSES = { |
| 59 self.DEPS_GIT: { | 68 self.DEPS_GIT: { |
| 60 revision: '.DEPS.git content' | 69 revision: '.DEPS.git content' |
| 61 }, | 70 }, |
| 62 self.DEPS: { | 71 self.DEPS: { |
| 63 revision: expected_content | 72 revision: expected_content |
| 64 }, | 73 }, |
| 65 } | 74 } |
| 66 | 75 |
| 67 self.mock(git_repository, 'GitRepository', DummyGitRepository) | 76 self.mock(gitiles_repository, 'GitilesRepository', MockGitilesRepository) |
| 68 | 77 |
| 69 content = self.deps_downloader.Load( | 78 content = self.deps_downloader.Load( |
| 70 'https://src.git', revision, 'DEPS') | 79 'https://src.git', revision, 'DEPS') |
| 71 self.assertEqual(expected_content, content) | 80 self.assertEqual(expected_content, content) |
| 72 | 81 |
| 73 def testUseFallbackDEPS(self): | 82 def testUseFallbackDEPS(self): |
| 74 revision = 'abc' | 83 revision = 'abc' |
| 75 expected_content = 'DEPS test' | 84 expected_content = 'DEPS test' |
| 76 | 85 |
| 77 DummyGitRepository.RESPONSES = { | 86 MockGitilesRepository.RESPONSES = { |
| 78 self.DEPS: { | 87 self.DEPS: { |
| 79 revision: expected_content | 88 revision: expected_content |
| 80 }, | 89 }, |
| 81 } | 90 } |
| 82 | 91 |
| 83 self.mock(git_repository, 'GitRepository', DummyGitRepository) | 92 self.mock(gitiles_repository, 'GitilesRepository', MockGitilesRepository) |
| 84 | 93 |
| 85 content = self.deps_downloader.Load( | 94 content = self.deps_downloader.Load( |
| 86 'https://src.git', revision, 'NONEXISTENT_DEPS') | 95 'https://src.git', revision, 'NONEXISTENT_DEPS') |
| 87 self.assertEqual(expected_content, content) | 96 self.assertEqual(expected_content, content) |
| 88 | 97 |
| 89 def testUseSlaveDEPS(self): | 98 def testUseSlaveDEPS(self): |
| 90 revision = 'abc' | 99 revision = 'abc' |
| 91 expected_content = 'slave DEPS content' | 100 expected_content = 'slave DEPS content' |
| 92 | 101 |
| 93 DummyGitRepository.RESPONSES = { | 102 MockGitilesRepository.RESPONSES = { |
| 94 self.DEPS_GIT: { | 103 self.DEPS_GIT: { |
| 95 revision: '.DEPS.git content' | 104 revision: '.DEPS.git content' |
| 96 }, | 105 }, |
| 97 'slave.DEPS': { | 106 'slave.DEPS': { |
| 98 revision: expected_content | 107 revision: expected_content |
| 99 }, | 108 }, |
| 100 } | 109 } |
| 101 | 110 |
| 102 self.mock(git_repository, 'GitRepository', DummyGitRepository) | 111 self.mock(gitiles_repository, 'GitilesRepository', MockGitilesRepository) |
| 103 | 112 |
| 104 content = self.deps_downloader.Load( | 113 content = self.deps_downloader.Load( |
| 105 'https://src.git', revision, 'slave.DEPS') | 114 'https://src.git', revision, 'slave.DEPS') |
| 106 self.assertEqual(expected_content, content) | 115 self.assertEqual(expected_content, content) |
| 107 | 116 |
| 108 def testFailedToPullDEPSFile(self): | 117 def testFailedToPullDEPSFile(self): |
| 109 DummyGitRepository.RESPONSES = {} | 118 MockGitilesRepository.RESPONSES = {} |
| 110 | 119 |
| 111 self.assertRaisesRegexp(Exception, 'Failed to pull DEPS file.', | 120 self.assertRaisesRegexp(Exception, 'Failed to pull DEPS file.', |
| 112 self.deps_downloader.Load, | 121 self.deps_downloader.Load, |
| 113 'https://src.git', 'abc', 'DEPS') | 122 'https://src.git', 'abc', 'DEPS') |
| 114 | 123 |
| 115 def testDEPSDownloaderForChromeVersion(self): | 124 def testDEPSDownloaderForChromeVersion(self): |
| 116 | 125 |
| 117 def _MockGet(*_): | 126 def _MockGet(*_): |
| 118 return 200, base64.b64encode('Dummy DEPS content') | 127 return 200, base64.b64encode('Dummy DEPS content') |
| 119 | 128 |
| 120 self.mock(http_client_appengine.HttpClientAppengine, '_Get', _MockGet) | 129 self.mock(http_client_appengine.HttpClientAppengine, '_Get', _MockGet) |
| 121 | 130 |
| 122 deps_downloader = chrome_dependency_fetcher.DEPSDownloader( | 131 deps_downloader = chrome_dependency_fetcher.DEPSDownloader( |
| 123 git_repository.GitRepository( | 132 gitiles_repository.GitilesRepository( |
| 124 http_client=http_client_appengine.HttpClientAppengine())) | 133 http_client=http_client_appengine.HttpClientAppengine())) |
| 125 content = deps_downloader.Load( | 134 content = deps_downloader.Load( |
| 126 'http://chrome-internal', '50.0.1234.0', 'DEPS') | 135 'http://chrome-internal', '50.0.1234.0', 'DEPS') |
| 127 self.assertEqual(content, 'Dummy DEPS content') | 136 self.assertEqual(content, 'Dummy DEPS content') |
| 128 | 137 |
| 129 self.assertRaisesRegexp( | 138 self.assertRaisesRegexp( |
| 130 Exception, | 139 Exception, |
| 131 'Failed to pull DEPS file from http://chrome, at revision 50.0.1234.1.', | 140 'Failed to pull DEPS file from http://chrome, at revision 50.0.1234.1.', |
| 132 self.deps_downloader.Load, | 141 self.deps_downloader.Load, |
| 133 'http://chrome', '50.0.1234.1', 'DEPS') | 142 'http://chrome', '50.0.1234.1', 'DEPS') |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 def DummyUpdateDependencyTree(root_dep, target_os_list, _): | 192 def DummyUpdateDependencyTree(root_dep, target_os_list, _): |
| 184 self.assertEqual(src_path, root_dep.path) | 193 self.assertEqual(src_path, root_dep.path) |
| 185 self.assertEqual(src_repo_url, root_dep.repo_url) | 194 self.assertEqual(src_repo_url, root_dep.repo_url) |
| 186 self.assertEqual([os_platform], target_os_list) | 195 self.assertEqual([os_platform], target_os_list) |
| 187 | 196 |
| 188 expected_dependency_dict[root_dep.path] = root_dep | 197 expected_dependency_dict[root_dep.path] = root_dep |
| 189 child1_dep.SetParent(root_dep) | 198 child1_dep.SetParent(root_dep) |
| 190 child2_dep.SetParent(root_dep) | 199 child2_dep.SetParent(root_dep) |
| 191 grand_child1.SetParent(child1_dep) | 200 grand_child1.SetParent(child1_dep) |
| 192 | 201 |
| 193 self.mock(git_repository, 'GitRepository', DummyGitRepository) | 202 self.mock(gitiles_repository, 'GitilesRepository', MockGitilesRepository) |
| 194 self.mock(deps_parser, 'UpdateDependencyTree', DummyUpdateDependencyTree) | 203 self.mock(deps_parser, 'UpdateDependencyTree', DummyUpdateDependencyTree) |
| 195 | 204 |
| 196 dependency_dict = self.chrome_dep_fetcher.GetDependency( | 205 dependency_dict = self.chrome_dep_fetcher.GetDependency( |
| 197 '50.0.1234.0', os_platform) | 206 '50.0.1234.0', os_platform) |
| 198 self.assertEqual(expected_dependency_dict, dependency_dict) | 207 self.assertEqual(expected_dependency_dict, dependency_dict) |
| 199 | 208 |
| 200 def testGetDependencyRolls(self): | 209 def testGetDependencyRolls(self): |
| 201 def MockGetDependency(revision, os_platform, _=False): | 210 def MockGetDependency(revision, os_platform, _=False): |
| 202 self.assertEqual('unix', os_platform) | 211 self.assertEqual('unix', os_platform) |
| 203 if revision == 'rev2': | 212 if revision == 'rev2': |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 'src/', | 287 'src/', |
| 279 'https://chromium.googlesource.com/chromium/src.git', '4', '5'), | 288 'https://chromium.googlesource.com/chromium/src.git', '4', '5'), |
| 280 } | 289 } |
| 281 self.assertEqual(self.chrome_dep_fetcher.GetDependencyRollsDict( | 290 self.assertEqual(self.chrome_dep_fetcher.GetDependencyRollsDict( |
| 282 '4', '5', 'all'), expected_deps_rolls_dict) | 291 '4', '5', 'all'), expected_deps_rolls_dict) |
| 283 | 292 |
| 284 def testIsChromeVersion(self): | 293 def testIsChromeVersion(self): |
| 285 self.assertTrue(chrome_dependency_fetcher.IsChromeVersion('50.0.1234.1')) | 294 self.assertTrue(chrome_dependency_fetcher.IsChromeVersion('50.0.1234.1')) |
| 286 self.assertFalse(chrome_dependency_fetcher.IsChromeVersion('a.b.c.e')) | 295 self.assertFalse(chrome_dependency_fetcher.IsChromeVersion('a.b.c.e')) |
| 287 self.assertFalse(chrome_dependency_fetcher.IsChromeVersion('5.021.2.0.123')) | 296 self.assertFalse(chrome_dependency_fetcher.IsChromeVersion('5.021.2.0.123')) |
| OLD | NEW |