def test_delete_failure(self, mock_delete):
        """
        Tests dashboards .delete() failure
        """
        mock_response = Mock(name='response')
        mock_response.json.side_effect = NewRelicAPIServerException(
            "New Relic API Exception")
        mock_delete.return_value = mock_response

        with self.assertRaises(NewRelicAPIServerException):
            self.dashboards.delete(123456)
    def test_update_failure(self, mock_put):
        """
        Test dashboards .update() failure
        """
        mock_update_response = Mock(name='response')
        mock_update_response.json.side_effect = NewRelicAPIServerException(
            'No JSON object could be decoded')
        mock_put.return_value = mock_update_response

        with self.assertRaises(NewRelicAPIServerException):
            self.dashboards.update(
                123456, {
                    "dashboard": {
                        "title":
                        "test-dashboard",
                        "description":
                        "Test Dashboard",
                        "icon":
                        "line-chart",
                        "visibility":
                        "owner",
                        "metadata": {
                            "version": 1
                        },
                        "widgets": [{
                            "visualization":
                            "faceted_line_chart",
                            "layout": {
                                "width": 1,
                                "height": 1,
                                "row": 1,
                                "column": 1
                            },
                            "account_id":
                            234567,
                            "data": [{
                                "nrql":
                                "SELECT average(cpuPercent) FROM SystemSample FACET role"
                            }],
                            "presentation": {
                                "title": "CPU Utilization",
                                "notes": ""
                            }
                        }],
                        "filter": {
                            "event_types": ["SystemSample"],
                            "attributes": ["environment"]
                        }
                    }
                })
Beispiel #3
0
    def _delete(self, *args, **kwargs):
        """
        A wrapper for deleting things

        :returns: The response of your delete
        :rtype: dict

        :raises: This will raise a
            :class:`NewRelicAPIServerException<newrelic_api.exceptions.NewRelicAPIServerException>`
            if there is an error from New Relic
        """
        response = requests.delete(*args, **kwargs)
        if not response.ok:
            raise NewRelicAPIServerException('{}: {}'.format(response.status_code, response.text))
        return response.json()
Beispiel #4
0
    def _post(self, *args, **kwargs):
        """
        A wrapper for posting things. It will also json encode your 'data' parameter

        :returns: The response of your post
        :rtype: dict

        :raises: This will raise a
            :class:`NewRelicAPIServerException<newrelic_api.exceptions.NewRelicAPIServerException>`
            if there is an error from New Relic
        """
        if 'data' in kwargs:
            kwargs['data'] = json.dumps(kwargs['data'])
        response = requests.post(*args, **kwargs)
        if not response.ok:
            raise NewRelicAPIServerException('{}: {}'.format(response.status_code, response.text))
        return response.json()
    def _put(self, *args, **kwargs):
        """
        A wrapper for putting things. It will also json encode your 'data' parameter

        :returns: The response of your put
        :rtype: dict

        :raises: This will raise a
            :class:`NewRelicAPIServerException<newrelic_api.exceptions.NewRelicAPIServerException>`
            if there is an error from New Relic
        """
        if 'data' in kwargs:
            kwargs['data'] = json.dumps(kwargs['data'])
        response = requests.put(*args, **kwargs)
        if not response.ok:
            raise NewRelicAPIServerException(message=response.text,
                                             status_code=response.status_code)
        if response.status_code == 304:
            return {'status_code': 304}
        else:
            return response.json()
Beispiel #6
0
    def _get(self, *args, **kwargs):
        """
        A wrapper for getting things

        :returns: The response of your get
        :rtype: dict

        :raises: This will raise a
            :class:`NewRelicAPIServerException<newrelic_api.exceptions.NewRelicAPIServerException>`
            if there is an error from New Relic
        """
        response = requests.get(*args, **kwargs)
        if not response.ok:
            raise NewRelicAPIServerException('{}: {}'.format(response.status_code, response.text))

        json_response = response.json()

        if response.links:
            json_response['pages'] = response.links

        return json_response