Exemple #1
0
 def setUp(self):
     logging.disable(logging.WARNING)
     collection = Collection.objects.get_by_natural_key(
         'elasticsearch', 'test_index', 'test_docs')
     with patch('warehouses.models.Collection.get_warehouse_name',
                return_value=INDEX):
         with patch('warehouses.models.Collection.in_time_series',
                    return_value=True):
             self.engine = ElasticsearchEngine(collection)
Exemple #2
0
class ElasticsearchWildcardTestCase(ElasticsearchBaseTestCase):
    """

    """
    def setUp(self):
        logging.disable(logging.WARNING)
        collection = Collection.objects.get_by_natural_key(
            'elasticsearch', 'test_index', 'test_docs')
        with patch('warehouses.models.Collection.get_warehouse_name',
                   return_value=INDEX):
            with patch('warehouses.models.Collection.in_time_series',
                       return_value=True):
                self.engine = ElasticsearchEngine(collection)

        # self.elasticsearch.indices.create(index=self.index, ignore=400)

    def tearDown(self):
        self.elasticsearch.indices.delete(index=self.engine._index_for_insert)
        logging.disable(logging.NOTSET)

    def test_find_by_id(self):
        """
        Tests the find_by_id method for a wildcard index name.
        """
        test_text = 'this is a find_by_id test post'

        doc_id = self.engine.insert({
            '_raw_data': {
                'backend': 'example_backend',
                'database': 'example_database',
                'collection': 'raw_data',
                'doc_id': 1
            },
            'text': test_text
        })

        results = self.engine.find_by_id([doc_id])
        expected_ids = [doc_id]
        self.assertEqual(len(results), 1)
        self.assertIn(self._get_id(results, 0), expected_ids)
        self.assertEqual(self._get_doc(results, 0)['text'], test_text)

    def test_remove_by_id(self):
        """
        Tests the remove_by_id method for a wildcard index name.
        """
        test_text = 'this is a find_by_id test post'

        doc_id = self.engine.insert({
            '_raw_data': {
                'backend': 'example_backend',
                'database': 'example_database',
                'collection': 'raw_data',
                'doc_id': 1
            },
            'text': test_text
        })

        results = self.engine.find_by_id([doc_id])
        self.assertEqual(len(results), 1)

        self.engine.remove_by_id(doc_id)
        results = self.engine.find_by_id(doc_id)
        self.assertEqual(results, None)

    def test_insert(self):
        """
        Tests the insert method for a wildcard index name.
        """
        test_text = 'this is a find_by_id test post'

        doc_id = self.engine.insert({
            '_raw_data': {
                'backend': 'example_backend',
                'database': 'example_database',
                'collection': 'raw_data',
                'doc_id': 1
            },
            'text': test_text
        })

        results = self.engine.find_by_id([doc_id])
        self.assertEqual(len(results), 1)

        self.engine.remove_by_id(doc_id)
        results = self.engine.find_by_id(doc_id)
        self.assertEqual(results, None)

    def test_malformed(self):
        """
        Tests the insert method for a malformed geopoint.
        """
        doc_id = self.engine.insert({'location': 'foobar'})

        results = self.engine.find_by_id([doc_id])
        self.assertEqual(len(results), 1)

        self.engine.remove_by_id(doc_id)
        results = self.engine.find_by_id(doc_id)
        self.assertEqual(results, None)