Beispiel #1
0
 def test_get_change_empty_change_id(self):
     gerrit_con = mock.Mock()
     with self.assertRaises(KeyError):
         cng = Change(gerrit_con)
         cng.get_change(
             'gerritproject',
             'master',
             ''
         )
Beispiel #2
0
 def test_get_change_empty_branch(self):
     gerrit_con = mock.Mock()
     with self.assertRaises(KeyError):
         cng = Change(gerrit_con)
         cng.get_change(
             'gerritproject',
             '',
             'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2'
         )
Beispiel #3
0
    def test_get_change_doesnt_exist(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(ValueError):
            cng = Change(gerrit_con)
            cng.get_change('gerritproject', 'master',
                           'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2')
Beispiel #4
0
    def test_get_change_unhandled_error(self):
        req = mock.Mock()
        req.status_code = 503
        req.content = ')]}\'{}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        with self.assertRaises(UnhandledError):
            cng = Change(gerrit_con)
            cng.get_change(
                'gerritproject',
                'master',
                'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2'
            )
Beispiel #5
0
    def test_submit_change_success_with_options(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = (
            ')]}\''
            '{"id": "gerritproject~master~I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'
        ).encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        cng = Change(gerrit_con)
        change = cng.get_change(
            'gerritproject',
            'master',
            'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2',
        )
        req.content = ')]}\'{"status": "MERGED"}'.encode('utf-8')
        change.submit_change({'NOTIFY': 'NONE'})
        gerrit_con.call.assert_called_with(
            request='post',
            r_endpoint={
                'pre': '/a/changes/',
                'data': 'gerritproject~master~I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2',
                'post': '/submit/',
            },
            r_payload={'NOTIFY': 'NONE'}
        )
        self.assertEqual(change.status, 'MERGED')
Beispiel #6
0
    def test_submit_change_success_with_options(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = (
            ')]}\''
            '{"id": "gerritproject~master~I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'
        ).encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        cng = Change(gerrit_con)
        change = cng.get_change(
            'gerritproject',
            'master',
            'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2',
        )
        req.content = ')]}\'{"status": "MERGED"}'.encode('utf-8')
        change.submit_change({'NOTIFY': 'NONE'})
        gerrit_con.call.assert_called_with(
            request='post',
            r_endpoint={
                'pre': '/a/changes/',
                'data':
                'gerritproject~master~I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2',
                'post': '/submit/',
            },
            r_payload={'NOTIFY': 'NONE'})
        self.assertEqual(change.status, 'MERGED')
Beispiel #7
0
 def get_change(self, project, change_id, branch='master'):
     """
     Get a change
     :param project: Project that contains change
     :type project: str or gerrit.projects.Project
     :param change_id: ID of change
     :type change_id: str
     :param branch: Branch change exists in
     :type branch: str
     """
     change = Change(self)
     return change.get_change(project, branch, change_id)
Beispiel #8
0
 def get_change(self, project, change_id, branch='master'):
     """
     Get a change
     :param project: Project that contains change
     :type project: str or gerrit.projects.Project
     :param change_id: ID of change
     :type change_id: str
     :param branch: Branch change exists in
     :type branch: str
     """
     change = Change(self)
     return change.get_change(project, branch, change_id)
Beispiel #9
0
    def test_get_change_project_object(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = ')]}\'{"id": "gerritproject~master~I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'.encode(
            'utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        pjt = Project(gerrit_con)
        project = pjt.get_project('gerritproject')
        cng = Change(gerrit_con)
        change = cng.get_change(project, 'master',
                                'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2')
        self.assertEqual(
            change.full_id,
            'gerritproject~master~I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2')
Beispiel #10
0
    def test_get_change_project_object(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = ')]}\'{"id": "gerritproject~master~I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        pjt = Project(gerrit_con)
        project = pjt.get_project('gerritproject')
        cng = Change(gerrit_con)
        change = cng.get_change(
            project,
            'master',
            'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2'
        )
        self.assertEqual(change.full_id, 'gerritproject~master~I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2')
Beispiel #11
0
    def test_submit_change_fail(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = ')]}\'{}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        cng = Change(gerrit_con)
        change = cng.get_change(
            'gerritproject',
            'master',
            'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2',
        )
        req.status_code = 409
        req.content = ')]}\'blocked by Verify'.encode('utf-8')
        with self.assertRaises(UnhandledError):
            change.submit_change()
Beispiel #12
0
    def test_submit_change_fail(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = ')]}\'{}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        cng = Change(gerrit_con)
        change = cng.get_change(
            'gerritproject',
            'master',
            'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2',
        )
        req.status_code = 409
        req.content = ')]}\'blocked by Verify'.encode('utf-8')
        with self.assertRaises(UnhandledError):
            change.submit_change()
Beispiel #13
0
    def test_list_reviewer(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = (
            ')]}\''
            '{"change_id": "I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'
        ).encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        cng = Change(gerrit_con)
        change = cng.get_change('gerritproject', 'master',
                                'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2')
        req.status_code = 200
        change.list_reviewers()
        gerrit_con.call.assert_called_with(
            r_endpoint=
            '/a/changes/I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2/reviewers/',
        )
Beispiel #14
0
    def test_get_change_returns_change(self):
        req = mock.Mock()
        req.status_code = 200
        content_string = (
            ')]}\''
            '{"id": "gerritproject~master~I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2", '
            '"project": "gerritproject", '
            '"branch": "master", '
            '"change_id": "I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2", '
            '"subject": "My change", '
            '"status": "NEW", '
            '"created": "2013-02-01 09:59:32.126000000", '
            '"updated": "2013-02-21 11:16:36.775000000", '
            '"mergable": true, '
            '"insertions": 34, '
            '"deletions": 101, '
            '"number": 3965, '
            '"owner": {"name": "John Doe"}}'
        )
        req.content = content_string.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        cng = Change(gerrit_con)
        change = cng.get_change(
            'gerritproject',
            'master',
            'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2'
        )
        self.assertEqual(change.full_id, 'gerritproject~master~I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2')
        self.assertEqual(change.project, 'gerritproject')
        self.assertEqual(change.branch, 'master')
        self.assertEqual(change.change_id, 'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2')
        self.assertEqual(change.subject, 'My change')
        self.assertEqual(change.status, 'NEW')
        self.assertEqual(change.created, '2013-02-01 09:59:32.126000000')
        self.assertEqual(change.updated, '2013-02-21 11:16:36.775000000')
        self.assertTrue(change.mergable)
        self.assertEqual(change.insertions, 34)
        self.assertEqual(change.deletions, 101)
        self.assertEqual(change.number, 3965)
        self.assertEqual(change.owner, {'name': 'John Doe'})
Beispiel #15
0
    def test_get_change_returns_change(self):
        req = mock.Mock()
        req.status_code = 200
        content_string = (
            ')]}\''
            '{"id": "gerritproject~master~I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2", '
            '"project": "gerritproject", '
            '"branch": "master", '
            '"change_id": "I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2", '
            '"subject": "My change", '
            '"status": "NEW", '
            '"created": "2013-02-01 09:59:32.126000000", '
            '"updated": "2013-02-21 11:16:36.775000000", '
            '"mergable": true, '
            '"insertions": 34, '
            '"deletions": 101, '
            '"number": 3965, '
            '"owner": {"name": "John Doe"}}')
        req.content = content_string.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        cng = Change(gerrit_con)
        change = cng.get_change('gerritproject', 'master',
                                'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2')
        self.assertEqual(
            change.full_id,
            'gerritproject~master~I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2')
        self.assertEqual(change.project, 'gerritproject')
        self.assertEqual(change.branch, 'master')
        self.assertEqual(change.change_id,
                         'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2')
        self.assertEqual(change.subject, 'My change')
        self.assertEqual(change.status, 'NEW')
        self.assertEqual(change.created, '2013-02-01 09:59:32.126000000')
        self.assertEqual(change.updated, '2013-02-21 11:16:36.775000000')
        self.assertTrue(change.mergable)
        self.assertEqual(change.insertions, 34)
        self.assertEqual(change.deletions, 101)
        self.assertEqual(change.number, 3965)
        self.assertEqual(change.owner, {'name': 'John Doe'})
Beispiel #16
0
    def test_delete_reviewer(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = (
            ')]}\''
            '{"change_id": "I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'
        ).encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        cng = Change(gerrit_con)
        change = cng.get_change('gerritproject', 'master',
                                'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2')
        req.status_code = 204
        self.assertTrue(change.delete_reviewer('my user'))
        gerrit_con.call.assert_called_with(
            request='delete',
            r_endpoint=
            '/a/changes/I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2/reviewers/my user',
            r_headers={},
        )
Beispiel #17
0
    def test_add_reviewer(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = (
            ')]}\''
            '{"change_id": "I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'
        ).encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        cng = Change(gerrit_con)
        change = cng.get_change('gerritproject', 'master',
                                'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2')
        req.content = ')]}\'{"reviewers": ["my user"]}'.encode('utf-8')
        self.assertTrue(change.add_reviewer('my user'))
        gerrit_con.call.assert_called_with(
            request='post',
            r_endpoint=
            '/a/changes/I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2/reviewers',
            r_payload={'reviewer': 'my user'},
        )
Beispiel #18
0
    def test_list_reviewer(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = (
            ')]}\''
            '{"change_id": "I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'
        ).encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        cng = Change(gerrit_con)
        change = cng.get_change(
            'gerritproject',
            'master',
            'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2'
        )
        req.status_code = 200
        change.list_reviewers()
        gerrit_con.call.assert_called_with(
            r_endpoint='/a/changes/I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2/reviewers/',
        )
Beispiel #19
0
    def test_add_reviewer(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = (
            ')]}\''
            '{"change_id": "I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'
        ).encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        cng = Change(gerrit_con)
        change = cng.get_change(
            'gerritproject',
            'master',
            'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2'
        )
        req.content = ')]}\'{"reviewers": ["my user"]}'.encode('utf-8')
        self.assertTrue(change.add_reviewer('my user'))
        gerrit_con.call.assert_called_with(
            request='post',
            r_endpoint='/a/changes/I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2/reviewers',
            r_payload={'reviewer': 'my user'},
        )
Beispiel #20
0
    def test_delete_reviewer(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = (
            ')]}\''
            '{"change_id": "I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2"}'
        ).encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        cng = Change(gerrit_con)
        change = cng.get_change(
            'gerritproject',
            'master',
            'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2'
        )
        req.status_code = 204
        self.assertTrue(change.delete_reviewer('my user'))
        gerrit_con.call.assert_called_with(
            request='delete',
            r_endpoint='/a/changes/I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2/reviewers/my user',
            r_headers={},
        )
Beispiel #21
0
 def test_get_change_empty_change_id(self):
     gerrit_con = mock.Mock()
     with self.assertRaises(KeyError):
         cng = Change(gerrit_con)
         cng.get_change('gerritproject', 'master', '')
Beispiel #22
0
 def test_get_change_empty_branch(self):
     gerrit_con = mock.Mock()
     with self.assertRaises(KeyError):
         cng = Change(gerrit_con)
         cng.get_change('gerritproject', '',
                        'I01440b5fd46a67ee38c9ef2c22eb145b8547cbb2')