Ejemplo n.º 1
0
    def test_delete_email_notification_channel(self):
        """
        Check that the delete_email_notification_channel function behaves correctly if DELETE request unsuccessful.

        We expect the function *not* to raise an exception if the notification channel to delete
        can not be found (i.e., if the DELETE request comes back with a 404).

        In all other cases the function should raise an exception.
        """
        channel_id = 1

        client_errors = [status_code for status_code in requests.status_codes._codes if 400 <= status_code < 500]
        server_errors = [status_code for status_code in requests.status_codes._codes if 500 <= status_code < 600]

        for error in client_errors + server_errors:
            with responses.RequestsMock() as mock_responses:
                mock_responses.add(
                    responses.DELETE,
                    '{}/{}.json'.format(newrelic.ALERTS_CHANNELS_API_URL, channel_id),
                    status=error
                )
                try:
                    newrelic.delete_email_notification_channel(channel_id)
                except requests.exceptions.HTTPError:
                    if error == requests.codes.not_found:
                        self.fail('Should not raise an exception for {} response.'.format(error))
                else:
                    if not error == requests.codes.not_found:
                        self.fail('Should raise an exception for {} response.'.format(error))
Ejemplo n.º 2
0
 def delete(self, *args, **kwargs):  # pylint: disable=arguments-differ
     """
     Delete this email notification channel.
     """
     if not self.shared:
         newrelic.delete_email_notification_channel(self.id)
         super().delete(*args, **kwargs)
     else:
         raise ProtectedError('Cannot delete a shared email notification channel', self)