def test_bump_meta_minor_release_from_patch_with_no_pulls(self, git_mock):
        self.useFixture(
            fake_meta.FakeMetaRepo(self.temp_dir,
                                   '0.15.1',
                                   terra_version='0.9.1'))
        meta_repo = unittest.mock.MagicMock()
        git_mock.get_latest_tag = unittest.mock.MagicMock(
            return_value='0.15.1'.encode('utf8'))
        meta_repo.gh_repo.get_pulls = unittest.mock.MagicMock(return_value=[])
        meta_repo.local_path = self.temp_dir.path
        repo = unittest.mock.MagicMock()
        repo.name = 'qiskit-terra'
        repo.repo_name = 'Qiskit/qiskit-terra'
        version_number = '0.10.0'

        release_process.bump_meta(meta_repo, repo, version_number)
        git_mock.create_branch.assert_called_once_with('bump_meta',
                                                       'origin/master',
                                                       meta_repo)
        commit_msg = """Bump version for qiskit-terra==0.10.0

Bump the meta repo version to include:

qiskit-terra==0.10.0

"""

        git_mock.create_git_commit_for_all.assert_called_once_with(
            meta_repo, commit_msg.encode('utf8'))
        with open(os.path.join(self.temp_dir.path, 'setup.py'), 'r') as fd:
            terra_bump = False
            meta_bump = False
            for line in fd:
                if 'qiskit-terra' in line:
                    self.assertEqual(line.strip(), '"qiskit-terra==0.10.0",')
                    terra_bump = True
                elif 'version=' in line:
                    self.assertEqual(line.strip(), 'version="0.16.0",')
                    meta_bump = True
                else:
                    continue
            self.assertTrue(terra_bump)
            self.assertTrue(meta_bump)
        with open(os.path.join(self.temp_dir.path, 'docs', 'conf.py'),
                  'r') as fd:
            for line in fd:
                if 'release = ' in line:
                    self.assertEqual(line.strip(), "release = '0.16.0'")
                    break
            else:
                self.fail('Release not updated in doc config')
        body = ("Bump the meta repo version to include:\n\n"
                "qiskit-terra==0.10.0\n\n")
        meta_repo.gh_repo.create_pull.assert_called_once_with('Bump Meta',
                                                              base='master',
                                                              head='bump_meta',
                                                              body=body)
        self.generate_mock.called_once_with(meta_repo)
    def test_bump_minor_release_from_pending_patch_release_pr(self, git_mock):
        self.useFixture(
            fake_meta.FakeMetaRepo(self.temp_dir,
                                   '0.20.1',
                                   terra_version='0.15.0'))
        meta_repo = unittest.mock.MagicMock()
        git_mock.get_latest_tag = unittest.mock.MagicMock(
            return_value='0.20.0'.encode('utf8'))
        pull_mock = unittest.mock.MagicMock()
        pull_mock.title = 'Fix docs'
        pull_mock_two = unittest.mock.MagicMock()
        pull_mock_two.title = 'More docs fixes and fun'
        existing_pull_mock = unittest.mock.MagicMock()
        existing_pull_mock.title = 'Bump Meta'
        existing_pull_mock.body = 'Fake old body'
        meta_repo.gh_repo.get_pulls = unittest.mock.MagicMock(
            return_value=[pull_mock, pull_mock_two, existing_pull_mock])
        meta_repo.local_path = self.temp_dir.path
        repo = unittest.mock.MagicMock()
        repo.name = 'qiskit-terra'
        repo.repo_name = 'Qiskit/qiskit-terra'
        version_number = '0.16.0'

        release_process.bump_meta(meta_repo, repo, version_number)
        git_mock.create_branch.assert_not_called()
        git_mock.checkout_ref.assert_called_once_with(meta_repo, 'bump_meta')
        git_mock.pull_remote_ref_to_local.assert_called_once_with(
            meta_repo, 'bump_meta')
        commit_msg = """Bump version for qiskit-terra==0.16.0

Bump the meta repo version to include:

qiskit-terra==0.16.0

"""
        git_mock.create_git_commit_for_all.assert_called_once_with(
            meta_repo, commit_msg.encode('utf8'))
        with open(os.path.join(self.temp_dir.path, 'setup.py'), 'r') as fd:
            terra_bump = False
            meta_bump = False
            for line in fd:
                if 'qiskit-terra' in line:
                    self.assertEqual(line.strip(), '"qiskit-terra==0.16.0",')
                    terra_bump = True
                elif 'version=' in line:
                    self.assertEqual(line.strip(), 'version="0.21.0",')
                    meta_bump = True
                else:
                    continue
            self.assertTrue(terra_bump)
            self.assertTrue(meta_bump)
        with open(os.path.join(self.temp_dir.path, 'docs', 'conf.py'),
                  'r') as fd:
            for line in fd:
                if 'release = ' in line:
                    self.assertEqual(line.strip(), "release = '0.21.0'")
                    break
            else:
                self.fail('Release not updated in doc config')
        meta_repo.gh_repo.create_pull.assert_not_called()
        existing_pull_mock.edit.assert_called_once_with(
            body='Fake old body\nqiskit-terra==0.16.0')
        self.generate_mock.called_once_with(meta_repo)