예제 #1
0
    def test_delete_synthetics_monitor_exceptions(self):
        """
        Check that the delete_synthetics_monitor function behaves correctly if DELETE request unsuccessful.

        We expect the function *not* to raise an exception if the monitor 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.
        """
        monitor_id = '2085b3d6-3689-4847-97cc-f7c91d86cd1d'

        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,
                                   '{0}/monitors/{1}'.format(newrelic.SYNTHETICS_API_URL,
                                                             monitor_id),
                                   status=error)
                try:
                    newrelic.delete_synthetics_monitor(monitor_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))
예제 #2
0
 def test_delete_synthetics_monitor(self):
     """
     Check that the delete_synthetics_monitor function deletes the monitor
     with the given id.
     """
     monitor_id = '3e442fa8-ec6c-4bf7-94ac-a0eccb817587'
     responses.add(responses.DELETE,
                   '{0}/monitors/{1}'.format(newrelic.SYNTHETICS_API_URL,
                                             monitor_id),
                   status=204)
     newrelic.delete_synthetics_monitor(monitor_id)
     self.assertEqual(len(responses.calls), 1)
     request_headers = responses.calls[0].request.headers
     self.assertEqual(request_headers['x-api-key'], 'admin-api-key')
예제 #3
0
 def delete(self, *args, **kwargs):
     """
     Disable this availability monitor on delete.
     """
     newrelic.delete_synthetics_monitor(self.pk)
     super().delete(*args, **kwargs)  # pylint: disable=no-member
예제 #4
0
 def delete(self, *args, **kwargs):  # pylint: disable=arguments-differ
     """
     Disable this availability monitor on delete.
     """
     newrelic.delete_synthetics_monitor(self.pk)
     super().delete(*args, **kwargs)
예제 #5
0
 def delete(self, *args, **kwargs):
     """
     Disable this availability monitor on delete.
     """
     newrelic.delete_synthetics_monitor(self.pk)
     super().delete(*args, **kwargs)