Python Elasticsearch Mock for test purposes
Project description
ElasticMock
Python Elasticsearch Mock for test purposes
Installation
pip install ElasticMock
Usage
To use ElasticMock, decorate your test method with @elasticmock decorator:
from unittest import TestCase
from elasticmock import elasticmock
class TestClass(TestCase):
@elasticmock
def test_should_return_something_from_elasticsearch(self):
self.assertIsNotNone(some_function_that_uses_elasticsearch())
Notes:
- The mocked search method returns all available documents indexed on the index with the requested document type.
- The mocked suggest method returns the exactly suggestions dictionary passed as body serialized in Elasticsearch.suggest response. Atention: If the term is an int, the suggestion will be
python term + 1
. If not, the suggestion will be formatted aspython {0}_suggestion.format(term)
. Example:- Suggestion Body:
suggestion_body = { 'suggestion-string': { 'text': 'test_text', 'term': { 'field': 'string' } }, 'suggestion-id': { 'text': 1234567, 'term': { 'field': 'id' } } }
- Suggestion Response:
{ 'suggestion-string': [ { 'text': 'test_text', 'length': 1, 'options': [ { 'text': 'test_text_suggestion', 'freq': 1, 'score': 1.0 } ], 'offset': 0 } ], 'suggestion-id': [ { 'text': 1234567, 'length': 1, 'options': [ { 'text': 1234568, 'freq': 1, 'score': 1.0 } ], 'offset': 0 } ], }
Testing
python setup.py test
Changelog
1.3.2
- elasticmock: Python 3 fixes (Thanks @barseghyanartur)
- test: Add information on testing (Thanks @barseghyanartur)
- README.md: Fixed typo (Thanks @bowlofstew)
1.3.1
- elasticmock: Allow the same arguments to the mock that elasticsearch.Elasticsearch allows (Thanks @mattbreeden)
1.3.0:
- FakeElasticSearch: Mocked count method (Thanks @TheoResources)
1.2.0:
- FakeElasticSearch: Mocked suggest method
1.1.1:
- elasticmock: Changing the cleanup older FakeElasticSearch's instances order
- FakeElasticSearch.index: Changing the method signature to correctly overrides the Elasticsearch.index method
1.1.0:
- FakeElasticSearch: Mocked delete method
1.0.1:
- setup.py: Fixed GitHub link
1.0.0:
- elasticmock: Created @elasticmock decorator
- FakeElasticSearch: Mocked exists, get, get_source, index, info, search and ping method
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ElasticMock-1.3.3.tar.gz
(6.6 kB
view hashes)
Built Distribution
Close
Hashes for ElasticMock-1.3.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbcc00b82f26da18bed609ea35a63d359cfc71744d69640fc9534736f3d3cd73 |
|
MD5 | 929aa8a2aab104621f18f37381a22ef0 |
|
BLAKE2b-256 | a3db98d5cb6756295cf32f7659da7d1ed84add475c66af986075c0611c69e6c1 |