Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'FakeElasticsearch' object has no attribute 'indices' #22

Closed
armudgal opened this issue May 26, 2019 · 3 comments
Closed

'FakeElasticsearch' object has no attribute 'indices' #22

armudgal opened this issue May 26, 2019 · 3 comments

Comments

@armudgal
Copy link

Hi there,
I just wanted to know whether ElasticMock supports 'indices' or not, and if not how can I mock the same, I will send a PR if I find a solution

@adisunw
Copy link

adisunw commented Sep 23, 2019

I ran into the same issue. It looks like there is a lot of missing elasticmock support (i'm running v7.0.2) and I ended up having to fork and fill in the gaps where it was missing. For the indices problem you are facing, you can make a class property for the FakeElasticsearch class like so

@property
def indices(self):
    return Index()

and make a mocked Index class:

class Index:
    def __init__(self):
        pass

    @staticmethod
    def create(index: str, ignore: Union[int, List[int]]):
        if index in FakeElasticsearch.documents_dict:
            return
        FakeElasticsearch.documents_dict[index] = list()

    @staticmethod
    def refresh(index: str):
        pass

    @staticmethod
    def delete(index: str, ignore: Union[int, List[int]]):
        if index in FakeElasticsearch.documents_dict:
            del FakeElasticsearch.documents_dict[index]

    @staticmethod
    def exists(index: str):
        return index in FakeElasticsearch.documents_dict

The Index class is obviously incomplete, but it accomplishes my mocking tasks.

@vrcmarcos
Copy link
Owner

Hi @adisunw , awesome solution for this issue! Wdyt of merge your fork into this repo?

@vrcmarcos
Copy link
Owner

@armudgal , @adisunw

It will be available on next release (probably 1.5.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants