示例#1
0
 def test_get_raises_on_empty_name(self):
     """
     Test that it raises if an empty project name is specified
     """
     with self.assertRaises(KeyError):
         project = Project(self.gerrit_con)
         project.get_project('')
示例#2
0
    def test_get_raises_on_unknown(self):
        """
        Test that it raises if gerrit returns an unknown status code
        """
        self.req.status_code = 503

        with self.assertRaises(UnhandledError):
            project = Project(self.gerrit_con)
            project.get_project(self.PROJECT)
示例#3
0
    def test_get_raises_on_nonexist(self):
        """
        Test that it raises if the project doesn't exist
        """
        self.req.status_code = 404

        with self.assertRaises(ValueError):
            project = Project(self.gerrit_con)
            project.get_project(self.PROJECT)
示例#4
0
    def test_get_project_raises_on_unknown_error(self):
        req = mock.Mock()
        req.status_code = 503
        req.content = 'Internal server error'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        with self.assertRaises(UnhandledError):
            pjt = Project(gerrit_con)
            pjt.get_project('gerritproject')
示例#5
0
    def test_get_project_raises_on_nonexisting_project(self):
        req = mock.Mock()
        req.status_code = 404
        req.content = 'Project not found'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        with self.assertRaises(ValueError):
            pjt = Project(gerrit_con)
            pjt.get_project('gerritproject')
示例#6
0
    def test_get_project_raises_on_unknown_error(self):
        req = mock.Mock()
        req.status_code = 503
        req.content = 'Internal server error'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        with self.assertRaises(UnhandledError):
            pjt = Project(gerrit_con)
            pjt.get_project('gerritproject')
示例#7
0
    def test_get_project_raises_on_nonexisting_project(self):
        req = mock.Mock()
        req.status_code = 404
        req.content = 'Project not found'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        with self.assertRaises(ValueError):
            pjt = Project(gerrit_con)
            pjt.get_project('gerritproject')
示例#8
0
    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',
            )
示例#9
0
    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',
            )
示例#10
0
    def test_project_eq(self):
        """
        Test that projects can be compared
        """
        self.req.content = self.project_content

        project = Project(self.gerrit_con)
        project1 = project.get_project(self.PROJECT)
        project2 = project.get_project(self.PROJECT)
        self.assertEqual(project1, project2)
示例#11
0
    def test_project_eq(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = ')]}\'{"name": "gerritproject"}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        pjt = Project(gerrit_con)
        project1 = pjt.get_project('gerritproject')
        project2 = pjt.get_project('gerritproject')
        self.assertEqual(project1, project2)
示例#12
0
    def test_project_eq(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = ')]}\'{"name": "gerritproject"}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        pjt = Project(gerrit_con)
        project1 = pjt.get_project('gerritproject')
        project2 = pjt.get_project('gerritproject')
        self.assertEqual(project1, project2)
示例#13
0
    def test_delete_fails(self):
        """
        Test that failing to delete a project raises
        """
        self.req_delete.status_code = 400
        self.req.content = self.project_content
        self.gerrit_con.call.side_effect = [self.req, self.req_delete]

        project = Project(self.gerrit_con)
        project = project.get_project(self.PROJECT)
        with self.assertRaises(UnhandledError):
            project.delete()
示例#14
0
    def get_project(self, name):
        """
        Get a project
        :param name: Project name to get
        :type name: str

        :return: Project object
        :rtype: gerrit.projects.Project
        """

        project = Project(self)
        return project.get_project(name)
示例#15
0
    def get_project(self, name):
        """
        Get a project
        :param name: Project name to get
        :type name: str

        :return: Project object
        :rtype: gerrit.projects.Project
        """

        project = Project(self)
        return project.get_project(name)
示例#16
0
    def test_delete_fails(self):
        get = mock.Mock()
        get.status_code = 200
        get.content = ')]}\'{"name": "gerritproject", "parent": "All-Projects", "description": "My gerrit project", "state": "ACTIVE"}'.encode('utf-8')
        delete = mock.Mock()
        delete.status_code = 400
        gerrit_con = mock.Mock()
        gerrit_con.call.side_effect = [get, delete]

        pjt = Project(gerrit_con)
        project = pjt.get_project('gerritproject')
        with self.assertRaises(UnhandledError):
            project.delete()
示例#17
0
    def test_delete_fails(self):
        get = mock.Mock()
        get.status_code = 200
        get.content = ')]}\'{"name": "gerritproject", "parent": "All-Projects", "description": "My gerrit project", "state": "ACTIVE"}'.encode(
            'utf-8')
        delete = mock.Mock()
        delete.status_code = 400
        gerrit_con = mock.Mock()
        gerrit_con.call.side_effect = [get, delete]

        pjt = Project(gerrit_con)
        project = pjt.get_project('gerritproject')
        with self.assertRaises(UnhandledError):
            project.delete()
示例#18
0
    def test_get_returns_project(self):
        """
        Test that a project can be fetched
        """
        self.req.content = self.project_content

        project = Project(self.gerrit_con)
        project = project.get_project(self.PROJECT)
        self.assertEqual(project.name, self.PROJECT)
        self.assertEqual(project.parent, self.PARENT)
        self.assertEqual(project.description, self.DESCRIPTION)
        self.assertEqual(project.state, self.STATE)
        self.assertEqual(project.branches, None)
        self.assertEqual(project.web_links, None)
示例#19
0
    def test_get_project_returns_project(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = ')]}\'{"name": "gerritproject", "parent": "All-Projects", "description": "My gerrit project", "state": "ACTIVE"}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        pjt = Project(gerrit_con)
        project = pjt.get_project('gerritproject')
        self.assertEqual(project.name, 'gerritproject')
        self.assertEqual(project.parent, 'All-Projects')
        self.assertEqual(project.description, 'My gerrit project')
        self.assertEqual(project.state, 'ACTIVE')
        self.assertEqual(project.branches, None)
        self.assertEqual(project.web_links, None)
示例#20
0
    def test_get_project_returns_project(self):
        req = mock.Mock()
        req.status_code = 200
        req.content = ')]}\'{"name": "gerritproject", "parent": "All-Projects", "description": "My gerrit project", "state": "ACTIVE"}'.encode(
            'utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        pjt = Project(gerrit_con)
        project = pjt.get_project('gerritproject')
        self.assertEqual(project.name, 'gerritproject')
        self.assertEqual(project.parent, 'All-Projects')
        self.assertEqual(project.description, 'My gerrit project')
        self.assertEqual(project.state, 'ACTIVE')
        self.assertEqual(project.branches, None)
        self.assertEqual(project.web_links, None)
示例#21
0
    def test_delete_success_options(self):
        """
        Test that it is possible to delete a project with options
        """
        self.req.content = self.project_content
        self.gerrit_con.call.side_effect = [self.req, self.req_delete]

        project = Project(self.gerrit_con)
        project = project.get_project(self.PROJECT)
        self.assertTrue(project.delete({'force': True}))
        self.gerrit_con.call.assert_called_with(
            request='delete',
            r_endpoint='/a/projects/{}'.format(self.PROJECT),
            r_headers={},
            r_payload={'force': True},
        )
示例#22
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')
示例#23
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')
示例#24
0
    def test_delete_success_with_options(self):
        get = mock.Mock()
        get.status_code = 200
        get.content = ')]}\'{"name": "gerritproject", "parent": "All-Projects", "description": "My gerrit project", "state": "ACTIVE"}'.encode('utf-8')
        delete = mock.Mock()
        delete.status_code = 204
        gerrit_con = mock.Mock()
        gerrit_con.call.side_effect = [get, delete]

        pjt = Project(gerrit_con)
        project = pjt.get_project('gerritproject')
        self.assertTrue(project.delete({'force': True}))
        gerrit_con.call.assert_called_with(
            request='delete',
            r_endpoint='/a/projects/gerritproject',
            r_headers={},
            r_payload={'force': True},
        )
示例#25
0
    def test_delete_success_with_options(self):
        get = mock.Mock()
        get.status_code = 200
        get.content = ')]}\'{"name": "gerritproject", "parent": "All-Projects", "description": "My gerrit project", "state": "ACTIVE"}'.encode(
            'utf-8')
        delete = mock.Mock()
        delete.status_code = 204
        gerrit_con = mock.Mock()
        gerrit_con.call.side_effect = [get, delete]

        pjt = Project(gerrit_con)
        project = pjt.get_project('gerritproject')
        self.assertTrue(project.delete({'force': True}))
        gerrit_con.call.assert_called_with(
            request='delete',
            r_endpoint='/a/projects/gerritproject',
            r_headers={},
            r_payload={'force': True},
        )
示例#26
0
    def test_get_project_raises_on_empty_name(self):
        gerrit_con = mock.Mock()

        with self.assertRaises(KeyError):
            pjt = Project(gerrit_con)
            pjt.get_project('')
示例#27
0
    def test_get_project_raises_on_empty_name(self):
        gerrit_con = mock.Mock()

        with self.assertRaises(KeyError):
            pjt = Project(gerrit_con)
            pjt.get_project('')