Skip to content

Commit

Permalink
Wrote a test...
Browse files Browse the repository at this point in the history
  • Loading branch information
grgilad committed Mar 14, 2022
1 parent ace2a17 commit 635b660
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ELASTICMOCK_VERSION='1.8.8'
ELASTICMOCK_VERSION='1.8.9'

install:
pip3 install -r requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion elasticmock/fake_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def _evaluate_for_range_query_type(self, document):
elif sign == 'lt' and value:
if doc_val >= value:
return False
else:
elif sign not in ['gte', 'gt', 'lte', 'lt']:
raise ValueError(f"Invalid comparison type {sign}")
return True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import setuptools

__version__ = '1.8.8'
__version__ = '1.8.9'

# read the contents of your readme file
from os import path
Expand Down
18 changes: 18 additions & 0 deletions tests/fake_elasticsearch/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,24 @@ def test_search_with_range_query(self, _, query_range, expected_ids):
hits = response['hits']['hits']
self.assertEqual(set(expected_ids), set(hit['_source']['id'] for hit in hits))

def test_search_with_range_query_with_null_lte(self):
body = {
'id': 5,
'timestamp': datetime.datetime(2009, 1, 1, 10, 0, 0),
'data_int': 10,
}
self.es.index(index='index_for_search', doc_type=DOC_TYPE, body=body)

response = self.es.search(
index='index_for_search',
doc_type=DOC_TYPE,
body={'query': {'range': {'data_int': {"gte": 10, "lte": None}}}},
)

self.assertEqual(1, response['hits']['total']['value'])
hits = response['hits']['hits']
self.assertEqual({5}, set(hit['_source']['id'] for hit in hits))

def test_search_with_sort_asc(self):
for i in range(0, 12):
body = {
Expand Down

0 comments on commit 635b660

Please sign in to comment.