Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
snakeye committed Oct 7, 2018
2 parents bcc113a + 7ad1551 commit 2c08bbe
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ python setup.py test

## Changelog

#### 1.3.3

- [Search: doc_type can be a list](https://github.com/vrcmarcos/elasticmock/pull/16) (Thanks [@garncarz](https://github.com/garncarz))
- [Exclude tests package](https://github.com/vrcmarcos/elasticmock/pull/13) (Thanks [@jmlw](https://github.com/jmlw))
- [Make the FakeElasticsearch __init__ signature match the one from Elasticsearc]((https://github.com/vrcmarcos/elasticmock/pull/10) (Thanks [@xrmx](https://github.com/xrmx))
- [Improve search and count](https://github.com/vrcmarcos/elasticmock/pull/7) (Thanks [@frivoire](https://github.com/frivoire))

#### 1.3.2

- **elasticmock**: Python 3 fixes (Thanks [@barseghyanartur](https://github.com/barseghyanartur))
Expand Down
7 changes: 5 additions & 2 deletions elasticmock/fake_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ def search(self, index=None, doc_type=None, body=None, params=None):
matches = []
for searchable_index in searchable_indexes:
for document in self.__documents_dict[searchable_index]:
if doc_type is not None and document.get('_type') not in doc_type: # value in a list of allowed doc_types
continue
if doc_type:
if isinstance(doc_type, list) and document.get('_type') not in doc_type:
continue
if isinstance(doc_type, str) and document.get('_type') != doc_type:
continue
matches.append(document)

result = {
Expand Down
20 changes: 11 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# -*- coding: utf-8 -*-

from setuptools import setup, find_packages
import setuptools

__version__ = '1.3.3'

setup(
with open("README.md", "r") as fh:
long_description = fh.read()

setuptools.setup(
name='ElasticMock',
version=__version__,
url='https://github.com/snakeye/elasticmock',
license='MIT',
author='Marcos Cardoso',
author_email='[email protected]',
description='Python Elasticsearch Mock for test purposes',
packages=find_packages(exclude=('tests')),
zip_safe=False,
include_package_data=True,
platforms='any',
long_description=long_description,
long_description_content_type="text/markdown",
url='https://github.com/vrcmarcos/elasticmock',
packages=setuptools.find_packages(exclude=('tests')),
install_requires=[
'elasticsearch',
'mock'
Expand All @@ -24,7 +25,8 @@
'Environment :: Web Environment',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
"License :: OSI Approved :: MIT License",
'Topic :: Software Development :: Libraries :: Python Modules'
]
)
14 changes: 14 additions & 0 deletions tests/test_elasticmock.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,20 @@ def test_should_count_in_multiple_indexes(self):
result = self.es.count(index=['users', 'pcs'])
self.assertEqual(2, result.get('count'))

def test_doc_type_can_be_list(self):
doc_types = ['1_idx', '2_idx', '3_idx']
count_per_doc_type = 3

for doc_type in doc_types:
for _ in range(count_per_doc_type):
self.es.index(index=self.index_name, doc_type=doc_type, body={})

result = self.es.search(doc_type=[doc_types[0]])
self.assertEqual(count_per_doc_type, result.get('hits').get('total'))

result = self.es.search(doc_type=doc_types[:2])
self.assertEqual(count_per_doc_type * 2, result.get('hits').get('total'))


if __name__ == '__main__':
unittest.main()

0 comments on commit 2c08bbe

Please sign in to comment.