Coder Social home page Coder Social logo

yanzchen / elasticmock Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vrcmarcos/elasticmock

0.0 2.0 0.0 28 KB

Python Elasticsearch Mock for test purposes

Home Page: https://pypi.python.org/pypi/ElasticMock

License: MIT License

Makefile 1.15% Python 98.85%

elasticmock's Introduction

ElasticMock

Python Elasticsearch Mock for test purposes

Build Status Coverage Status PyPI version Code Health GitHub license

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 as python {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

1.3.1

  • elasticmock: Allow the same arguments to the mock that elasticsearch.Elasticsearch allows (Thanks @mattbreeden)

1.3.0:

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

elasticmock's People

Contributors

vrcmarcos avatar barseghyanartur avatar

Watchers

James Cloos avatar Yan Z Chen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.