Skip to content

Commit

Permalink
Support changes in ES since version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
scorphus committed Apr 30, 2014
1 parent 6106d80 commit 53badd2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 38 deletions.
2 changes: 1 addition & 1 deletion tornadoes/__init__.py
Expand Up @@ -99,7 +99,7 @@ def count(self, index="_all", type=None, source='', parameters=None, callback=No
path += '?{}'.format(urlencode(parameters or {}))

if source:
source = json.dumps(source['query'])
source = json.dumps(source)

self.post_by_path(path=path, callback=callback, source=source)

Expand Down
49 changes: 12 additions & 37 deletions tornadoes/tests/unit/test_tornadoes.py
Expand Up @@ -27,18 +27,13 @@ def test_simple_search(self):

def test_search_for_specific_type_with_query(self):
self.es_connection.search(callback=self.stop,
source={"query": {"text": {"ID": "171171"}}},
source={"query": {"term": {"ID": "171171"}}},
type="materia", index="teste")

response = self._verify_status_code_and_return_response()
self.assertEqual(response["hits"]["total"], 1)
self.assertEqual(response["hits"]["hits"][0]["_id"], u'171171')

def test_search_all_entries(self):
self.es_connection.search(self.stop)
response = self._verify_status_code_and_return_response()
self.assertEqual(response["hits"]["total"], 28)

def test_search_specific_index(self):
self.es_connection.search(callback=self.stop, index="outroteste")
response = self._verify_status_code_and_return_response()
Expand Down Expand Up @@ -87,9 +82,9 @@ def test_should_clean_search_list_after_search(self):
self.assertListEqual([], self.es_connection.bulk.bulk_list)

def _make_multisearch(self):
source = {"query": {"text": {"_id": "171171"}}}
source = {"query": {"term": {"_id": "171171"}}}
self.es_connection.multi_search(index="teste", source=source)
source = {"query": {"text": {"_id": "101010"}}}
source = {"query": {"term": {"_id": "101010"}}}
self.es_connection.multi_search(index="neverEndIndex", source=source)

self.es_connection.apply_search(callback=self.stop)
Expand All @@ -116,7 +111,6 @@ def test_can_put_and_delete_document(self):
response_dict = self._verify_response_and_returns_dict(response)
self.assertEqual(response_dict['_index'], 'test')
self.assertEqual(response_dict['_type'], 'document')
self.assertTrue(response_dict['ok'])
self.assertEqual(response_dict['_id'], doc_id)
self.assertIn('refresh=True', response.request.url)
finally:
Expand All @@ -125,16 +119,10 @@ def test_can_put_and_delete_document(self):
response = self._verify_status_code_and_return_response()

self.assertTrue(response['found'])
self.assertTrue(response['ok'])
self.assertEqual(response['_index'], 'test')
self.assertEqual(response['_type'], 'document')
self.assertEqual(response['_id'], doc_id)

def test_count_all_entries(self):
self.es_connection.count(callback=self.stop)
response = self._verify_status_code_and_return_response()
self.assertEqual(response["count"], 28)

def test_count_specific_index(self):
self.es_connection.count(callback=self.stop, index="outroteste")
response = self._verify_status_code_and_return_response()
Expand All @@ -146,13 +134,13 @@ def test_count_specific_type(self):
self.assertEqual(response["count"], 2)

def test_count_specific_query(self):
source = {"query": {"text": {"_id": "171171"}}}
source = {"query": {"term": {"_id": "171171"}}}
self.es_connection.count(callback=self.stop, source=source)
response = self._verify_status_code_and_return_response()
self.assertEqual(response["count"], 1)

def test_count_specific_query_with_parameters(self):
source = {"query": {"text": {"_id": "171171"}}}
source = {"query": {"term": {"_id": "171171"}}}
parameters = {'refresh': True}
self.es_connection.count(callback=self.stop, source=source, parameters=parameters)
response = self.wait()
Expand All @@ -161,7 +149,7 @@ def test_count_specific_query_with_parameters(self):
self.assertTrue(response.request.url.endswith('_count?refresh=True'))

def test_count_specific_query_with_many_parameters(self):
source = {"query": {"text": {"_id": "171171"}}}
source = {"query": {"term": {"_id": "171171"}}}
parameters = {'df': '_id', 'test': True}
self.es_connection.count(callback=self.stop, source=source, parameters=parameters)
response = self.wait()
Expand Down Expand Up @@ -193,20 +181,14 @@ def test_simple_search(self):
@gen_test
def test_search_for_specific_type_with_query(self):
response = yield self.es_connection.search(
source={"query": {"text": {"ID": "171171"}}},
source={"query": {"term": {"ID": "171171"}}},
type="materia", index="teste"
)

response = self._verify_status_code_and_return_response(response)
self.assertEqual(response["hits"]["total"], 1)
self.assertEqual(response["hits"]["hits"][0]["_id"], u'171171')

@gen_test
def test_search_all_entries(self):
response = yield self.es_connection.search()
response = self._verify_status_code_and_return_response(response)
self.assertEqual(response["hits"]["total"], 28)

@gen_test
def test_search_specific_index(self):
response = yield self.es_connection.search(index="outroteste")
Expand Down Expand Up @@ -255,7 +237,6 @@ def test_can_put_and_delete_document(self):
response_dict = self._verify_status_code_and_return_response(response)
self.assertEqual(response_dict['_index'], 'test')
self.assertEqual(response_dict['_type'], 'document')
self.assertTrue(response_dict['ok'])
self.assertEqual(response_dict['_id'], doc_id)
self.assertIn('refresh=True', response.request.url)
finally:
Expand All @@ -264,16 +245,10 @@ def test_can_put_and_delete_document(self):
response = self._verify_status_code_and_return_response(response)

self.assertTrue(response['found'])
self.assertTrue(response['ok'])
self.assertEqual(response['_index'], 'test')
self.assertEqual(response['_type'], 'document')
self.assertEqual(response['_id'], doc_id)

@gen_test
def test_count_all_entries(self):
response = yield self.es_connection.count()
self.assertCount(response, 28)

@gen_test
def test_count_specific_index(self):
response = yield self.es_connection.count(index="outroteste")
Expand All @@ -286,21 +261,21 @@ def test_count_specific_type(self):

@gen_test
def test_count_specific_query(self):
source = {"query": {"text": {"_id": "171171"}}}
source = {"query": {"term": {"_id": "171171"}}}
response = yield self.es_connection.count(source=source)
self.assertCount(response, 1)

@gen_test
def test_count_specific_query_with_parameters(self):
source = {"query": {"text": {"_id": "171171"}}}
source = {"query": {"term": {"_id": "171171"}}}
parameters = {'refresh': True}
response = yield self.es_connection.count(callback=self.stop, source=source, parameters=parameters)
self.assertCount(response, 1)
self.assertTrue(response.request.url.endswith('_count?refresh=True'))

@gen_test
def test_count_specific_query_with_many_parameters(self):
source = {"query": {"text": {"_id": "171171"}}}
source = {"query": {"term": {"_id": "171171"}}}
parameters = {'df': '_id', 'test': True}
response = yield self.es_connection.count(callback=self.stop, source=source, parameters=parameters)
self.assertCount(response, 1)
Expand All @@ -311,9 +286,9 @@ def assertCount(self, response, count):
self.assertEqual(response_dict["count"], count)

def _make_multisearch(self):
source = {"query": {"text": {"_id": "171171"}}}
source = {"query": {"term": {"_id": "171171"}}}
self.es_connection.multi_search(index="teste", source=source)
source = {"query": {"text": {"_id": "101010"}}}
source = {"query": {"term": {"_id": "101010"}}}
self.es_connection.multi_search(index="neverEndIndex", source=source)

def _verify_status_code_and_return_response(self, response):
Expand Down

0 comments on commit 53badd2

Please sign in to comment.