def testDownloadCIPD(self, run_mock): with tempfile_ext.NamedTemporaryDirectory() as workDir,\ tempfile_ext.NamedTemporaryDirectory() as repoRoot,\ cts_utils.chdir(workDir): cts_utils_test.setup_fake_repo(repoRoot) fake_cipd = cts_utils_test.FakeCIPD() fake_cipd.add_package( os.path.join(repoRoot, cts_utils.TOOLS_DIR, cts_utils.CIPD_FILE), DEPS_DATA['revision']) fake_run_cmd = cts_utils_test.FakeRunCmd(fake_cipd) run_mock.side_effect = fake_run_cmd.run_cmd cts_updater = update_cts.UpdateCTS('.', repoRoot) cts_updater.download_cipd() self.assertTrue(os.path.isdir('cipd')) for i in [str(x) for x in range(1, 5)]: self.assertEqual( CIPD_DATA['file' + i], cts_utils_test.readfile( os.path.join(workDir, 'cipd', CIPD_DATA['file' + i])))
def testCompleteUpdate(self, retrieve_mock, update_json_mock, cmd_mock, run_mock): with tempfile_ext.NamedTemporaryDirectory() as workDir,\ tempfile_ext.NamedTemporaryDirectory() as repoRoot,\ cts_utils.chdir(workDir): cts_utils_test.setup_fake_repo(repoRoot) fake_cipd = cts_utils_test.FakeCIPD() fake_cipd.add_package( os.path.join(repoRoot, cts_utils.TOOLS_DIR, cts_utils.CIPD_FILE), DEPS_DATA['revision']) fake_download = FakeDownload() fake_download.add_fake_zip_files(CONFIG_DATA['json']) fake_run_cmd = cts_utils_test.FakeRunCmd(fake_cipd) retrieve_mock.side_effect = fake_download.download run_mock.side_effect = fake_run_cmd.run_cmd update_json_mock.return_value = 0 cmd_mock.return_value = '' cts_updater = update_cts.UpdateCTS('.', repoRoot) cts_updater.download_cts_cmd() cts_updater.create_cipd_cmd() cts_updater.update_repository_cmd() latest_version = fake_cipd.get_latest_version( 'chromium/android_webview/tools/cts_archive') self.assertNotEqual(DEPS_DATA['revision'], latest_version) self._assertCIPDVersionUpdated(repoRoot, latest_version) repo_cipd_yaml = os.path.join(repoRoot, cts_utils.TOOLS_DIR, cts_utils.CIPD_FILE) run_mock.assert_any_call([ 'cp', os.path.join(workDir, 'staged', 'cipd.yaml'), repo_cipd_yaml ]) run_mock.assert_any_call([ 'cipd', 'ensure', '-root', os.path.dirname(repo_cipd_yaml), '-ensure-file', mock.ANY ]) update_json_mock.assert_called_with()