示例#1
0
    def test_request_reviews_with_reviewers_config(self, mocked_requests,
                                                   mocked_get_response,
                                                   mocked_call_api,
                                                   mocked_filter_invited,
                                                   mocked_format_response):
        """Ensure _filter_invited is called when reviewers config is
        provided."""

        mocked_call_api.return_value = [
            {
                'id': 'change_id'
            },
        ]

        reviewers_config = {'excluded': []}

        service = GerritService()

        mocked_requests.session.assert_called()

        service.request_reviews('host',
                                'repo',
                                reviewers_config=reviewers_config)

        mocked_get_response.assert_called()
        mocked_filter_invited.assert_called_once_with([{
            'id': 'change_id'
        }],
                                                      excluded=[])
        mocked_format_response.assert_called()
示例#2
0
    def test_request_reviews_no_host(self, mock_format_response, mock_call_api,
                                     mock_check_repo_exists,
                                     mock_get_response):
        """
        Tests 'get_reviews' function where:
            * Self.url == host
            * Repos exist
        """
        # Set up mock return values and side effects
        mock_check_repo_exists.return_value = True
        mock_call_api.return_value = 'mock_review_response'
        mock_format_response.return_value = 'Successful Call!'
        service = GerritService()
        service.host_exists = True

        # Call function
        response = service.request_reviews(host=None, repo_name='mock_repo')

        # Validate function calls and response
        mock_get_response.assert_not_called()
        mock_check_repo_exists.assert_called_with('mock_repo', True)

        changes_url = ('None/changes/?q=project:mock_repo+status:open'
                       '&o=DETAILED_ACCOUNTS'
                       '&o=DETAILED_LABELS')

        mock_call_api.assert_called_with(url=changes_url, ssl_verify=True)
        mock_format_response.assert_called_with('mock_review_response', None,
                                                None)
        self.assertEqual('Successful Call!', response)
示例#3
0
 def test_gerrit_incorrect_repo_name(self):
     gerrit = GerritService()
     error_msg = self.config['incorrect_repo_name_msg']
     with self.assertRaises(Exception) as context:
         self.assertRaises(ValueError, gerrit.request_reviews(
             repo_name=self.config['incorrect_repo_name'],
             host=self.config['host']))
     self.assertTrue(error_msg in str(context.exception))
示例#4
0
 def test_gerrit_incorrect_host_url(self):
     gerrit = GerritService()
     error_msg = self.config["incorrect_host_msg"]
     with self.assertRaises(Exception) as context:
         self.assertRaises(
             ValueError,
             gerrit.request_reviews(
                 repo_name=self.config["repo_name"],
                 host=self.config["incorrect_host"],
             ),
         )
         self.assertTrue(error_msg in str(context.exception))
示例#5
0
    def test_request_reviews_without_reviewers_config(self, mocked_requests,
                                                      mocked_get_response,
                                                      mocked_call_api,
                                                      mocked_filter_invited,
                                                      mocked_format_response):
        """Ensure _filter_invited is not called if there is no reviewers
        config."""

        mocked_call_api.return_value = [{'id': 'change_id'}]

        reviewers_config = {}

        service = GerritService()

        mocked_requests.session.assert_called()

        service.request_reviews('host',
                                'repo',
                                reviewers_config=reviewers_config)

        mocked_get_response.assert_called()
        mocked_filter_invited.assert_not_called()
        mocked_format_response.assert_called()
示例#6
0
    def test_request_reviews_no_repos(self, mock_format_response,
                                      mock_call_api, mock_check_repo_exists,
                                      mock_get_response):
        """
        Tests 'get_reviews' function where:
            * Self.url == host
            * Repos don't exists
        """
        # Set up mock return values and side effects
        mock_check_repo_exists.return_value = None
        mock_call_api.return_value = 'mock_review_response'
        mock_format_response.return_value = 'Successful Call!'
        service = GerritService()
        service.host_exists = True

        # Call function
        response = service.request_reviews(host=None, repo_name='mock_repo')

        # Validate function calls and response
        mock_get_response.assert_not_called()
        mock_check_repo_exists.assert_called_with('mock_repo', True)
        mock_call_api.assert_not_called()
        mock_format_response.assert_not_called()
        self.assertEqual(None, response)
示例#7
0
 def test_gerrit_request_reviews(self):
     gerrit = GerritService()
     result = gerrit.request_reviews(repo_name=self.config['repo_name'],
                                     host=self.config['host'])
     self.assertTrue(result is not None)