def test_absent(self):
        with patch("requests.get", mock_json_response([])):
            with patch("requests.delete") as rdelete:
                ret = grafana_datasource.absent("test", profile=profile)
                self.assertTrue(rdelete.call_count == 0)
                self.assertTrue(ret["result"])
                self.assertEqual(ret["comment"],
                                 "Data source test already absent")

        with patch("requests.get",
                   mock_json_response([{
                       "name": "test",
                       "id": 1
                   }])):
            with patch("requests.delete") as rdelete:
                ret = grafana_datasource.absent("test", profile=profile)
                rdelete.assert_called_once_with(
                    "http://grafana/api/datasources/1",
                    headers={
                        "Authorization": "Bearer token",
                        "Accept": "application/json",
                    },
                    timeout=3,
                )
                self.assertTrue(ret["result"])
                self.assertEqual(ret["comment"],
                                 "Data source test was deleted")
Exemplo n.º 2
0
    def test_absent(self):
        with patch('requests.get', mock_json_response([])):
            with patch('requests.delete') as rdelete:
                ret = grafana_datasource.absent('test', profile=profile)
                rdelete.assert_not_called()
                self.assertTrue(ret['result'])
                self.assertEqual(ret['comment'],
                                 'Data source test already absent')

        with patch('requests.get',
                   mock_json_response([{
                       'name': 'test',
                       'id': 1
                   }])):
            with patch('requests.delete') as rdelete:
                ret = grafana_datasource.absent('test', profile=profile)
                rdelete.assert_called_once_with(
                    'http://grafana/api/datasources/1',
                    headers={
                        'Authorization': 'Bearer token',
                        'Accept': 'application/json'
                    },
                    timeout=3)
                self.assertTrue(ret['result'])
                self.assertEqual(ret['comment'],
                                 'Data source test was deleted')
    def test_absent(self):
        with patch('requests.get', mock_json_response([])):
            with patch('requests.delete') as rdelete:
                ret = grafana_datasource.absent('test', profile=profile)
                rdelete.assert_not_called()
                self.assertTrue(ret['result'])
                self.assertEqual(ret['comment'], 'Data source test already absent')

        with patch('requests.get', mock_json_response([{'name': 'test', 'id': 1}])):
            with patch('requests.delete') as rdelete:
                ret = grafana_datasource.absent('test', profile=profile)
                rdelete.assert_called_once_with(
                    'http://grafana/api/datasources/1',
                    headers={'Authorization': 'Bearer token', 'Accept': 'application/json'},
                    timeout=3
                )
                self.assertTrue(ret['result'])
                self.assertEqual(ret['comment'], 'Data source test was deleted')