Exemplo n.º 1
0
    def test__esp_add_query_dict(self):
        esp = ElasticsearchProcessor()

        page = 1
        page_size = 20

        query = {
            "query": {
                "match": {
                    "_all": "foobar"
                }
            }
        }

        # ElasticsearchProcessor internally sets the from/size parameters
        # on the query; we need to compare with those values included
        query_with_size = query.copy()
        query_with_size.update({
            'from': (page - 1) * page_size,
            'size': page_size
        })

        esp.add_search(query.copy())
        ddtools.assert_equal(esp.bulk_search_data[0], {})
        ddtools.assert_equal(esp.bulk_search_data[1], query_with_size)

        esp.reset()
        esp.add_search(query.copy(), index='blog')
        ddtools.assert_equal(esp.bulk_search_data[0], {'index': 'blog'})
        ddtools.assert_equal(esp.bulk_search_data[1], query_with_size)

        esp.reset()
        esp.add_search(query.copy(), index='blog', doc_type='posts')
        ddtools.assert_equal(esp.bulk_search_data[0], {'index': 'blog', 'type': 'posts'})
        ddtools.assert_equal(esp.bulk_search_data[1], query_with_size)
Exemplo n.º 2
0
    def test__esp_reset(self):
        esp = ElasticsearchProcessor()

        self.assertTrue(len(esp.bulk_search_data) == 0)
        self.assertTrue(len(esp.page_ranges) == 0)

        esp.add_search(self.form)

        self.assertFalse(len(esp.bulk_search_data) == 0)
        self.assertFalse(len(esp.page_ranges) == 0)

        esp.reset()

        self.assertTrue(len(esp.bulk_search_data) == 0)
        self.assertTrue(len(esp.page_ranges) == 0)