def test_create_change_fail(self):
        req = mock.Mock()
        req.status_code = 404
        req.content = ')]}\'{}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        with self.assertRaises(UnhandledError):
            cng = Change(gerrit_con)
            cng.create_change('gerritproject', 'My change', 'master',
                              {'status': 'DRAFT'})
    def test_create_change_fail(self):
        req = mock.Mock()
        req.status_code = 404
        req.content = ')]}\'{}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        with self.assertRaises(UnhandledError):
            cng = Change(gerrit_con)
            cng.create_change(
                'gerritproject',
                'My change',
                'master',
                {'status': 'DRAFT'}
            )
    def test_create_change_project_object(self):
        req = mock.Mock()
        req.status_code = 201
        req.content = ')]}\'{"change_id": "I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'.encode(
            'utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        req_project = mock.Mock()
        req_project.status_code = 200
        req_project.content = ')]}\'{"name": "gerritproject"}'.encode('utf-8')
        gerrit_con_project = mock.Mock()
        gerrit_con_project.call.return_value = req_project

        with mock.patch.object(Change, 'get_change') as mock_get_change:
            pjt = Project(gerrit_con_project)
            project = pjt.get_project('gerritproject')
            cng = Change(gerrit_con)
            change = cng.create_change(project, 'My change', 'master',
                                       {'status': 'DRAFT'})
            mock_get_change.assert_called_with(
                'gerritproject',
                'master',
                'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2',
            )
    def test_create_change_project_object(self):
        req = mock.Mock()
        req.status_code = 201
        req.content = ')]}\'{"change_id": "I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        req_project = mock.Mock()
        req_project.status_code = 200
        req_project.content = ')]}\'{"name": "gerritproject"}'.encode('utf-8')
        gerrit_con_project = mock.Mock()
        gerrit_con_project.call.return_value = req_project

        with mock.patch.object(Change, 'get_change') as mock_get_change:
            pjt = Project(gerrit_con_project)
            project = pjt.get_project('gerritproject')
            cng = Change(gerrit_con)
            change = cng.create_change(
                project,
                'My change',
                'master',
                {'status': 'DRAFT'}
            )
            mock_get_change.assert_called_with(
                'gerritproject',
                'master',
                'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2',
            )
    def test_create_change_success(self):
        req = mock.Mock()
        req.status_code = 201
        req.content = ')]}\'{"change_id": "I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        with mock.patch.object(Change, 'get_change') as mock_get_change:
            cng = Change(gerrit_con)
            cng.create_change(
                'gerritproject',
                'My change',
                'master',
                {'status': 'DRAFT'},
            )
            mock_get_change.assert_called_with(
                'gerritproject',
                'master',
                'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2',
            )
    def test_create_change_success(self):
        req = mock.Mock()
        req.status_code = 201
        req.content = ')]}\'{"change_id": "I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'.encode(
            'utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        with mock.patch.object(Change, 'get_change') as mock_get_change:
            cng = Change(gerrit_con)
            cng.create_change(
                'gerritproject',
                'My change',
                'master',
                {'status': 'DRAFT'},
            )
            mock_get_change.assert_called_with(
                'gerritproject',
                'master',
                'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2',
            )
Exemple #7
0
    def create_change(self, project, subject, branch='master', options=None):
        """
        Create a change
	:param project: Project to create change in
	:type project: str or gerrit.project.Project
	:param subject: Subject of the change
	:type subject: str
	:param branch: The name of the target branch
	:type branch: str
	:param options: Additional options
	:type options: dict
	"""

        change = Change(self)
        return change.create_change(project, subject, branch, options)
Exemple #8
0
    def create_change(self, project, subject, branch='master', options=None):
        """
        Create a change
	:param project: Project to create change in
	:type project: str or gerrit.project.Project
	:param subject: Subject of the change
	:type subject: str
	:param branch: The name of the target branch
	:type branch: str
	:param options: Additional options
	:type options: dict
	"""

        change = Change(self)
        return change.create_change(project, subject, branch, options)