Ejemplo n.º 1
0
    def test_no_retry_on_credentials_api_not_found_errors(
        self,
        mock_get_completed_programs,
        mock_get_certified_programs,
        mock_award_program_certificate,
    ):
        mock_get_completed_programs.return_value = [1, 2]
        mock_get_certified_programs.side_effect = [[], [2]]
        mock_award_program_certificate.side_effect = self._make_side_effect(
            [exceptions.HttpClientError(), None])

        tasks.award_program_certificates.delay(self.student.username).get()

        self.assertEqual(mock_award_program_certificate.call_count, 2)
Ejemplo n.º 2
0
    def test_no_retry_on_credentials_api_4XX_error(
        self,
        mock_get_completed_programs,
        mock_get_certified_programs,  # pylint: disable=unused-argument
        mock_award_program_certificate,
    ):
        """
        Verify that other 4XX errors cause task to fail but there is no retry.
        """
        exception = exceptions.HttpClientError()
        exception.response = mock.Mock(status_code=418)
        mock_get_completed_programs.return_value = {1: 1, 2: 2}
        mock_award_program_certificate.side_effect = self._make_side_effect(
            [exception, None])

        tasks.award_program_certificates.delay(self.student.username).get()

        assert mock_award_program_certificate.call_count == 2
    def test_retry_on_credentials_api_429_error(
        self,
        mock_get_completed_programs,
        mock_get_certified_programs,  # pylint: disable=unused-argument
        mock_award_program_certificate,
    ):
        """
        Verify that a 429 error causes the task to fail and then retry.
        """
        exception = exceptions.HttpClientError()
        exception.response = mock.Mock(status_code=429)
        mock_get_completed_programs.return_value = [1, 2]
        mock_award_program_certificate.side_effect = self._make_side_effect(
            [exception, None])

        tasks.award_program_certificates.delay(self.student.username).get()

        self.assertEqual(mock_award_program_certificate.call_count, 3)
Ejemplo n.º 4
0
    def test_no_retry_on_credentials_api_4XX_error(
        self,
        mock_get_inverted_programs,
        mock_get_certified_programs,
        mock_revoke_program_certificate,
    ):
        """
        Verify that other 4XX errors cause task to fail but there is no retry.
        """
        exception = exceptions.HttpClientError()
        exception.response = mock.Mock(status_code=418)
        mock_get_inverted_programs.return_value = self.inverted_programs
        mock_get_certified_programs.return_value = [1, 2]
        mock_revoke_program_certificate.side_effect = self._make_side_effect(
            [exception, None])

        tasks.revoke_program_certificates.delay(self.student.username,
                                                self.course_key).get()

        assert mock_revoke_program_certificate.call_count == 2
Ejemplo n.º 5
0
    def test_retry_on_credentials_api_429_error(
        self,
        mock_get_inverted_programs,
        mock_get_certified_programs,
        mock_revoke_program_certificate,
    ):
        """
        Verify that a 429 error causes the task to fail and then retry.
        """
        exception = exceptions.HttpClientError()
        exception.response = mock.Mock(status_code=429)
        mock_get_inverted_programs.return_value = self.inverted_programs
        mock_get_certified_programs.return_value = [1, 2]
        mock_revoke_program_certificate.side_effect = self._make_side_effect(
            [exception, None])

        tasks.revoke_program_certificates.delay(self.student.username,
                                                self.course_key).get()

        self.assertEqual(mock_revoke_program_certificate.call_count, 3)