Ejemplo n.º 1
0
    def test_list_success(self):
        """
        Test that listing reviewers returns the expected result
        """
        self.req.status_code = 200
        expected_result = [
            {
                "approvals": {
                    "Verified": "+1",
                    "Code-Review": "+2"
                },
                "_account_id": 1000096,
                "name": "John Doe",
                "email": "*****@*****.**"
            },
            {
                "approvals": {
                    "Verified": " 0",
                    "Code-Review": "-1"
                },
                "_account_id": 1000097,
                "name": "Jane Roe",
                "email": "*****@*****.**"
            }
        ]
        self.req.content = self.build_response(expected_result)

        reviewer = Reviewer(self.gerrit_con, self.CHANGE_ID)
        self.assertEqual(reviewer.list_reviewers(), expected_result)
Ejemplo n.º 2
0
    def test_delete_fail(self):
        """
        Test that it returns false if removing a reviewer fails
        """
        self.req.status_code = 404

        reviewer = Reviewer(self.gerrit_con, self.CHANGE_ID)
        self.assertFalse(reviewer.delete_reviewer(self.USER))
Ejemplo n.º 3
0
    def test_add_success(self):
        """
        Test that a user can be added as a reviewer
        """
        self.req.content = self.build_response({"reviewers": [self.USER]})

        reviewer = Reviewer(self.gerrit_con, self.CHANGE_ID)
        self.assertTrue(reviewer.add_reviewer(self.USER))
Ejemplo n.º 4
0
    def test_add_reviewer_user_added(self):
        req = mock.Mock()
        req.content = ')]}\'{"reviewers": ["my user"]}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        self.assertTrue(reviewer.add_reviewer('my user'))
Ejemplo n.º 5
0
    def test_add_reviewer_user_added(self):
        req = mock.Mock()
        req.content = ')]}\'{"reviewers": ["my user"]}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        self.assertTrue(reviewer.add_reviewer('my user'))
Ejemplo n.º 6
0
    def test_delete_unauthorized(self):
        """
        Test that it raises when deleting a reviewer is not permitted
        """
        self.req.content = self.build_response('delete not permitted')

        reviewer = Reviewer(self.gerrit_con, self.CHANGE_ID)
        with self.assertRaises(AuthorizationError):
            reviewer.delete_reviewer(self.USER)
Ejemplo n.º 7
0
    def test_add_unhandled(self):
        """
        Test that it raises if gerrit returns an unknown content
        """
        self.req.content = self.build_response({})

        reviewer = Reviewer(self.gerrit_con, self.CHANGE_ID)
        with self.assertRaises(UnhandledError):
            reviewer.add_reviewer(self.USER)
Ejemplo n.º 8
0
    def test_add_already_reviewer(self):
        """
        Test that it raises when trying to add a user that is already a reviewer
        """
        self.req.content = self.build_response({"reviewers": []})

        reviewer = Reviewer(self.gerrit_con, self.CHANGE_ID)
        with self.assertRaises(AlreadyExists):
            reviewer.add_reviewer(self.USER)
Ejemplo n.º 9
0
    def test_add_reviewer_unhandled_error(self):
        req = mock.Mock()
        req.content = ')]}\'{}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        with self.assertRaises(UnhandledError):
            reviewer.add_reviewer('my user')
Ejemplo n.º 10
0
 def list_reviewers(self):
     """
     List reviewers for the change
     :returns: The reviews for the specified change-id at init
     :rtype: dict
     :exception: ValueError, UnhandledError
     """
     reviewer = Reviewer(self._gerrit_con, self.change_id)
     return reviewer.list_reviewers()
Ejemplo n.º 11
0
 def list_reviewers(self):
     """
     List reviewers for the change
     :returns: The reviews for the specified change-id at init
     :rtype: dict
     :exception: ValueError, UnhandledError
     """
     reviewer = Reviewer(self._gerrit_con, self.change_id)
     return reviewer.list_reviewers()
Ejemplo n.º 12
0
    def test_delete_reviewer_unauthorized(self):
        req = mock.Mock()
        req.content = ')]}\'delete not permitted'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        with self.assertRaises(AuthorizationError):
            reviewer.delete_reviewer('my user')
Ejemplo n.º 13
0
    def test_add_reviewer_unhandled_error(self):
        req = mock.Mock()
        req.content = ')]}\'{}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        with self.assertRaises(UnhandledError):
            reviewer.add_reviewer('my user')
Ejemplo n.º 14
0
    def test_list_unknown(self):
        """
        Test that it raises if gerrit returns an unknown status code
        """
        self.req.status_code = 403

        reviewer = Reviewer(self.gerrit_con, self.CHANGE_ID)
        with self.assertRaises(UnhandledError):
            reviewer.list_reviewers()
Ejemplo n.º 15
0
    def test_add_reviewer_user_is_already_reviewer(self):
        req = mock.Mock()
        req.content = ')]}\'{"reviewers": []}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        with self.assertRaises(AlreadyExists):
            reviewer.add_reviewer('my user')
Ejemplo n.º 16
0
    def test_delete_reviewer_fail(self):
        req = mock.Mock()
        req.content = ')]}\''.encode('utf-8')
        req.status_code = 404
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        self.assertFalse(reviewer.delete_reviewer('my user'))
Ejemplo n.º 17
0
    def test_add_reviewer_user_doesnt_exist(self):
        req = mock.Mock()
        req.content = ')]}\'my user does not identify a registered user or group'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        with self.assertRaises(LookupError):
            reviewer.add_reviewer('my user')
Ejemplo n.º 18
0
    def test_delete_reviewer_unauthorized(self):
        req = mock.Mock()
        req.content = ')]}\'delete not permitted'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        with self.assertRaises(AuthorizationError):
            reviewer.delete_reviewer('my user')
Ejemplo n.º 19
0
    def test_delete_reviewer_fail(self):
        req = mock.Mock()
        req.content = ')]}\''.encode('utf-8')
        req.status_code = 404
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        self.assertFalse(reviewer.delete_reviewer('my user'))
Ejemplo n.º 20
0
    def test_add_reviewer_user_is_already_reviewer(self):
        req = mock.Mock()
        req.content = ')]}\'{"reviewers": []}'.encode('utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        with self.assertRaises(AlreadyExists):
            reviewer.add_reviewer('my user')
Ejemplo n.º 21
0
 def delete_reviewer(self, account_id):
     """
     Delete a reviewer from the change
     :param account_id: Remove a user with account-id as reviewer.
     :type account_id: str
     :rtype: bool
     :exception: error.AuthorizationError
     """
     reviewer = Reviewer(self._gerrit_con, self.change_id)
     return reviewer.delete_reviewer(account_id)
Ejemplo n.º 22
0
    def test_list_reviewers_unknown_error(self):
        req = mock.Mock()
        req.content = ')]}\''.encode('utf-8')
        req.status_code = 403
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        with self.assertRaises(UnhandledError):
            reviewer.list_reviewers()
Ejemplo n.º 23
0
    def test_list_reviewers_unknown_error(self):
        req = mock.Mock()
        req.content = ')]}\''.encode('utf-8')
        req.status_code = 403
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        with self.assertRaises(UnhandledError):
            reviewer.list_reviewers()
Ejemplo n.º 24
0
    def test_list_fail(self):
        """
        Test that it raises if listing reviewers fails
        :return:
        """
        self.req.status_code = 404

        reviewer = Reviewer(self.gerrit_con, self.CHANGE_ID)
        with self.assertRaises(ValueError):
            reviewer.list_reviewers()
Ejemplo n.º 25
0
    def test_add_reviewer_user_doesnt_exist(self):
        req = mock.Mock()
        req.content = ')]}\'my user does not identify a registered user or group'.encode(
            'utf-8')
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        with self.assertRaises(LookupError):
            reviewer.add_reviewer('my user')
Ejemplo n.º 26
0
 def delete_reviewer(self, account_id):
     """
     Delete a reviewer from the change
     :param account_id: Remove a user with account-id as reviewer.
     :type account_id: str
     :rtype: bool
     :exception: error.AuthorizationError
     """
     reviewer = Reviewer(self._gerrit_con, self.change_id)
     return reviewer.delete_reviewer(account_id)
Ejemplo n.º 27
0
    def test_add_doesnt_exist(self):
        """
        Test that it raises when trying to add a user as reviewer that doesn't exist
        """
        self.req.content = self.build_response(
            'my user does not identify a registered user or group'
        )

        reviewer = Reviewer(self.gerrit_con, self.CHANGE_ID)
        with self.assertRaises(LookupError):
            reviewer.add_reviewer(self.USER)
Ejemplo n.º 28
0
 def add_reviewer(self, account_id):
     """
     Add a reviewer to the change
     :param account_id: The user account that should be added as a reviewer
     :type account_id: str
     :return: You get a True boolean type if the addition of this user was successful
     :rtype: bool
     :except: LookupError, AlreadyExists, UnhandledError
     """
     reviewer = Reviewer(self._gerrit_con, self.change_id)
     return reviewer.add_reviewer(account_id)
Ejemplo n.º 29
0
 def add_reviewer(self, account_id):
     """
     Add a reviewer to the change
     :param account_id: The user account that should be added as a reviewer
     :type account_id: str
     :return: You get a True boolean type if the addition of this user was successful
     :rtype: bool
     :except: LookupError, AlreadyExists, UnhandledError
     """
     reviewer = Reviewer(self._gerrit_con, self.change_id)
     return reviewer.add_reviewer(account_id)
Ejemplo n.º 30
0
    def test_delete_success(self):
        """
        Test that a reviewer can be deleted
        """
        self.req.status_code = 204

        reviewer = Reviewer(self.gerrit_con, self.CHANGE_ID)
        self.assertTrue(reviewer.delete_reviewer(self.USER))
        self.gerrit_con.call.assert_called_with(
            request='delete',
            r_endpoint='/a/changes/{}/reviewers/{}'.format(self.CHANGE_ID, self.USER),
            r_headers={},
        )
Ejemplo n.º 31
0
    def test_delete_reviewer_success(self):
        req = mock.Mock()
        req.content = ')]}\''.encode('utf-8')
        req.status_code = 204
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        self.assertTrue(reviewer.delete_reviewer('my user'))
        gerrit_con.call.assert_called_with(
            request='delete',
            r_endpoint='/a/changes/my change id/reviewers/my user',
            r_headers={},
        )
Ejemplo n.º 32
0
    def test_delete_reviewer_success(self):
        req = mock.Mock()
        req.content = ')]}\''.encode('utf-8')
        req.status_code = 204
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req

        reviewer = Reviewer(gerrit_con, 'my change id')
        self.assertTrue(reviewer.delete_reviewer('my user'))
        gerrit_con.call.assert_called_with(
            request='delete',
            r_endpoint='/a/changes/my change id/reviewers/my user',
            r_headers={},
        )
Ejemplo n.º 33
0
    def test_list_reviewers_success(self):
        req = mock.Mock()
        req.content = ''')]}\'[
  {
    "approvals": {
      "Verified": "+1",
      "Code-Review": "+2"
    },
    "_account_id": 1000096,
    "name": "John Doe",
    "email": "*****@*****.**"
  },
  {
    "approvals": {
      "Verified": " 0",
      "Code-Review": "-1"
    },
    "_account_id": 1000097,
    "name": "Jane Roe",
    "email": "*****@*****.**"
  }
]
'''.encode('utf-8')
        req.status_code = 200
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req
        expected_result = [
                              {
                                  "approvals": {
                                      "Verified": "+1",
                                      "Code-Review": "+2"
                                  },
                                  "_account_id": 1000096,
                                  "name": "John Doe",
                                  "email": "*****@*****.**"
                              },
                              {
                                  "approvals": {
                                      "Verified": " 0",
                                      "Code-Review": "-1"
                                  },
                                  "_account_id": 1000097,
                                  "name": "Jane Roe",
                                  "email": "*****@*****.**"
                              }
                          ]

        reviewer = Reviewer(gerrit_con, 'my change id')
        self.assertEqual(reviewer.list_reviewers(), expected_result)
Ejemplo n.º 34
0
    def test_list_reviewers_success(self):
        req = mock.Mock()
        req.content = ''')]}\'[
  {
    "approvals": {
      "Verified": "+1",
      "Code-Review": "+2"
    },
    "_account_id": 1000096,
    "name": "John Doe",
    "email": "*****@*****.**"
  },
  {
    "approvals": {
      "Verified": " 0",
      "Code-Review": "-1"
    },
    "_account_id": 1000097,
    "name": "Jane Roe",
    "email": "*****@*****.**"
  }
]
'''.encode('utf-8')
        req.status_code = 200
        gerrit_con = mock.Mock()
        gerrit_con.call.return_value = req
        expected_result = [{
            "approvals": {
                "Verified": "+1",
                "Code-Review": "+2"
            },
            "_account_id": 1000096,
            "name": "John Doe",
            "email": "*****@*****.**"
        }, {
            "approvals": {
                "Verified": " 0",
                "Code-Review": "-1"
            },
            "_account_id": 1000097,
            "name": "Jane Roe",
            "email": "*****@*****.**"
        }]

        reviewer = Reviewer(gerrit_con, 'my change id')
        self.assertEqual(reviewer.list_reviewers(), expected_result)