def testGitExistsForceOverwrite(self):
   """Verify behavior when git files exist, script options allow overwrite."""
   self.force = True
   os.path.exists(cb_constants.GITDIR).AndReturn(True)
   shutil.rmtree(cb_constants.GITDIR)
   os.mkdir(cb_constants.GITDIR)
   self.mox.ReplayAll()
   cb_command_lib.HandleGitExists(self.force)
 def testGitExistsNoForceUserConfirmsOverwrite(self):
   """Verify behavior when git files exist, user confirms overwrite."""
   os.path.exists(cb_constants.GITDIR).AndReturn(True)
   cb_command_lib.AskUserConfirmation(mox.IsA(str)).AndReturn(True)
   shutil.rmtree(cb_constants.GITDIR)
   os.mkdir(cb_constants.GITDIR)
   self.mox.ReplayAll()
   cb_command_lib.HandleGitExists(self.force)
 def testRecoveryNameNotResolved(self):
   """Verify error when recovery image url cannot be determined."""
   cb_command_lib.HandleSsdExists(self.ssd_name, self.force)
   cb_command_lib.HandleGitExists(self.force)
   cb_command_lib.RunCommand(mox.IsA(list))
   cb_command_lib.ResolveRecoveryUrl(
       self.board, self.recovery, alt_naming=0).AndReturn(
           (None, None))
   _AssertConvertRecoveryError(self)
 def testCannotDetermineBaseImageZipUrl(self):
   """Verify error when name of zip with base image cannot be determined."""
   cb_command_lib.HandleSsdExists(self.ssd_name, self.force)
   cb_command_lib.HandleGitExists(self.force)
   cb_command_lib.RunCommand(mox.IsA(list))
   cb_command_lib.ResolveRecoveryUrl(
       self.board, self.recovery, alt_naming=0).AndReturn(
           (self.rec_url, self.index_page))
   cb_command_lib.DetermineUrl(self.index_page, mox.IsA(list)).AndReturn(None)
   _AssertConvertRecoveryError(self)
 def testBaseImageZipDownloadFails(self):
   """Verify error when zip containing base image is not downloaded."""
   cb_command_lib.HandleSsdExists(self.ssd_name, self.force)
   cb_command_lib.HandleGitExists(self.force)
   cb_command_lib.RunCommand(mox.IsA(list))
   cb_command_lib.ResolveRecoveryUrl(
       self.board, self.recovery, alt_naming=0).AndReturn(
           (self.rec_url, self.index_page))
   cb_command_lib.DetermineUrl(self.index_page, mox.IsA(list)).AndReturn(
       self.zip_url)
   cb_command_lib.Download(self.zip_url).AndReturn(False)
   _AssertConvertRecoveryError(self)
 def testInstallCgptFails(self):
   """Verify error when installing cgpt utility fails."""
   cb_command_lib.HandleGitExists(self.force)
   cb_command_lib.RunCommand(mox.IsA(list))
   cb_command_lib.ResolveRecoveryUrl(
       self.board, self.recovery, alt_naming=0).AndReturn(
           (self.rec_url, self.index_page))
   cb_command_lib.DetermineUrl(self.index_page, mox.IsA(list)).AndReturn(
       self.zip_url)
   cb_command_lib.Download(self.zip_url).AndReturn(True)
   cb_command_lib.HandleSsdExists(self.ssd_name, self.force)
   cb_command_lib.InstallCgpt(self.index_page, self.force).AndRaise(
       cb_constants.BundlingError(''))
   _AssertConvertRecoveryError(self)
 def testConvertRecoveryToSsdSuccess(self):
   """Verify return value when recovery to full ssd conversion succeeds."""
   cb_command_lib.HandleGitExists(self.force)
   cb_command_lib.RunCommand(mox.IsA(list))
   cb_command_lib.ResolveRecoveryUrl(
       self.board, self.recovery, alt_naming=0).AndReturn(
           (self.rec_url, self.index_page))
   cb_command_lib.DetermineUrl(self.index_page,
                           mox.IsA(list)).AndReturn(self.zip_url)
   cb_command_lib.Download(self.zip_url).AndReturn(True)
   cb_command_lib.HandleSsdExists(self.ssd_name, self.force)
   cb_command_lib.InstallCgpt(self.index_page, self.force)
   cb_command_lib.RunCommand(mox.IsA(list))
   self.mox.ReplayAll()
   actual = cb_command_lib.ConvertRecoveryToSsd(self.image_name, self)
   self.assertEqual(self.ssd_name, actual)
 def testGitExistsNotHandled(self):
   """Verify error when git files exist, user does not confirm overwrite."""
   cb_command_lib.HandleSsdExists(self.ssd_name, self.force)
   cb_command_lib.HandleGitExists(self.force).AndRaise(
       cb_constants.BundlingError(''))
   _AssertConvertRecoveryError(self)
 def testGitDoesNotExist(self):
   """Verify behavior when no git directory exists."""
   os.path.exists(cb_constants.GITDIR).AndReturn(False)
   os.mkdir(cb_constants.GITDIR)
   self.mox.ReplayAll()
   cb_command_lib.HandleGitExists(self.force)