def test_create_object_http_error(self):
        """Test whether an exception is thrown if create_object fails"""

        obj_data = read_file('data/object_index-pattern')
        attributes = json.loads(obj_data)['attributes']
        httpretty.register_uri(httpretty.POST,
                               OBJECT_URL,
                               body=obj_data,
                               status=500)

        client = SavedObjects(KIBANA_URL)
        with self.assertRaises(requests.exceptions.HTTPError):
            _ = client.create_object(OBJECT_TYPE, OBJECT_ID, attributes)
示例#2
0
def set_kibiter_config(kibiter_url,
                       kibiter_time_from='now-90d',
                       kibiter_index_pattern='git',
                       kibiter_version='6.8.6',
                       overwrite=True):
    """Set the configuration of the Kibiter instance via the Kibana API

    :param kibiter_url: Kibiter URL
    :param kibiter_time_from: The value of the time picker
    :param kibiter_index_pattern: The value of the default index pattern
    :param kibiter_version: The value of the Kibiter version
    :param overwrite: If True, force the overwrite of existing dashboards
    """
    attributes = {}
    time_picker = {"from": kibiter_time_from, "to": "now", "mode": "quick"}
    attributes["timepicker:timeDefaults"] = json.dumps(time_picker)
    attributes["defaultIndex"] = kibiter_index_pattern

    saved_objects = SavedObjects(kibiter_url)
    saved_objects.create_object('config',
                                kibiter_version,
                                attributes,
                                overwrite=overwrite)
    def test_create_object(self):
        """Test the method create_object"""

        obj_data = read_file('data/object_index-pattern')
        attributes = json.loads(obj_data)['attributes']
        httpretty.register_uri(httpretty.POST,
                               OBJECT_URL,
                               body=obj_data,
                               status=200)

        client = SavedObjects(KIBANA_URL)
        with self.assertLogs(logger, level='INFO') as cm:
            obj = client.create_object(OBJECT_TYPE, OBJECT_ID, attributes)
            self.assertEqual(
                cm.output[0], 'INFO:archimedes.clients.saved_objects:'
                'Object ' + OBJECT_TYPE + ' with id ' + OBJECT_ID + ' create')
            self.assertDictEqual(obj, json.loads(obj_data))