예제 #1
0
    def test_safe_put_bulk(self):
        """Test whether items are correctly stored to the index"""

        items = json.loads(read_file('data/git.json'))
        data_json = items[0]
        bulk_json = '{{"index" : {{"_id" : "{}" }} }}\n'.format(data_json['uuid'])
        bulk_json += json.dumps(data_json) + "\n"

        elastic = ElasticSearch(self.es_con, self.target_index, GitOcean.mapping)
        bulk_url = elastic.get_bulk_url()
        inserted_items = elastic.safe_put_bulk(bulk_url, bulk_json)

        self.assertEqual(inserted_items, 1)
예제 #2
0
    def test_safe_put_bulk_errors(self):
        """Test whether an error message is logged when an item isn't inserted"""

        items = json.loads(read_file('data/git.json'))
        data_json = items[0]
        data_json['origin'] = ''.join(random.choice(string.ascii_letters) for x in range(66000))
        bulk_json = '{{"index" : {{"_id" : "{}" }} }}\n'.format(data_json['uuid'])
        bulk_json += json.dumps(data_json) + "\n"

        elastic = ElasticSearch(self.es_con, self.target_index, GitOcean.mapping)
        bulk_url = elastic.get_bulk_url()

        with self.assertLogs(logger, level='ERROR') as cm:
            inserted_items = elastic.safe_put_bulk(bulk_url, bulk_json)
            self.assertRegex(cm.output[0], "ERROR:grimoire_elk.elastic:Failed to insert data to ES*")

        self.assertEqual(inserted_items, 0)