def testUpdateProdBranchFailToParseCommitRange(self, run_cmd): """Test to grep the pushed commit range from the failed push log. @param run_cmd: Mock of infra.local_runner call used. """ run_cmd.side_effect = [self.GIT_LOG_FOR_COMMITS, None, 'Fail to push prod branch'] with self.assertRaises(ad.AutoDeployException): ad.update_prod_branch('test', 'test_dir', None)
def testUpdateProdBranchRebaseToCorrectHash(self, run_cmd): """Test whether update_prod_branch can rebase to the correct hash. @param run_cmd: Mock of infra.local_runner call used. """ run_cmd.side_effect = [self.GIT_LOG_FOR_COMMITS, None, self.PUSH_LOG] ad.update_prod_branch('test', 'test_dir', '123') expect_cmds = [ mock.call('git log prod..123 --oneline', stream_output=True), mock.call('git rebase 123 prod', stream_output=True), mock.call('git push origin prod', stream_output=True)] run_cmd.assert_has_calls(expect_cmds)
def testUpdateProdBranchRebaseToProdNext(self, run_cmd): """Test whether rebase to prod-next branch when the hash is not given. @param run_cmd: Mock of infra.local_runner call used. """ run_cmd.side_effect = [self.GIT_LOG_FOR_COMMITS, None, self.PUSH_LOG] ad.update_prod_branch('test', 'test_dir', None) expect_cmds = [ mock.call('git log prod..origin/prod-next --oneline', stream_output=True), mock.call('git rebase origin/prod-next prod', stream_output=True), mock.call('git push origin prod', stream_output=True) ] run_cmd.assert_has_calls(expect_cmds)
def testUpdateProdBranchParseCommitRange(self, run_cmd): """Test to grep the pushed commit range from the normal push log. @param run_cmd: Mock of infra.local_runner call used. """ run_cmd.side_effect = [self.GIT_LOG_FOR_COMMITS, None, self.PUSH_LOG] self.assertEqual(ad.update_prod_branch('test', 'test_dir', None), '123..456')
def testUpdateProdBranch(self, run_cmd): """Test automated_deploy.update_prod_branch. @param run_cmd: Mock of infra.local_runner call used. """ # Test whether rebase to the given hash when the hash is given. run_cmd.return_value = self.PUSH_LOG ad.update_prod_branch('test', 'test_dir', '123') expect_cmds = [ mock.call('git rebase 123 prod', stream_output=True), mock.call('git push origin prod', stream_output=True) ] run_cmd.assert_has_calls(expect_cmds) # Test whether rebase to prod-next branch when the hash is not given. run_cmd.return_value = self.PUSH_LOG ad.update_prod_branch('test', 'test_dir', None) expect_cmds = [ mock.call('git rebase origin/prod-next prod', stream_output=True), mock.call('git push origin prod', stream_output=True) ] run_cmd.assert_has_calls(expect_cmds) # Test to grep the pushed commit range from the normal push log. run_cmd.return_value = self.PUSH_LOG self.assertEqual(ad.update_prod_branch('test', 'test_dir', None), '123..456') # Test to grep the pushed commit range from the failed push log. run_cmd.return_value = 'Fail to push prod branch' with self.assertRaises(ad.AutoDeployException): ad.update_prod_branch('test', 'test_dir', None)
def testUpdateProdBranchWithNoNewChanges(self, run_cmd): """Test update_prod_branch when there exist no new changes. @param run_cmd: Mock of infra.local_runner call used. """ run_cmd.return_value = None self.assertEqual(ad.update_prod_branch('test', 'test_dir', '123'), None) expect_cmds = [ mock.call('git log prod..123 --oneline', stream_output=True)] run_cmd.assert_has_calls(expect_cmds)