-
Notifications
You must be signed in to change notification settings - Fork 67
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
TypeError: index() got an unexpected keyword argument 'headers' with sample code #36
Comments
I run a similar experiment in my environment and it worked. Here's my step-by-step:
import elasticsearch
class FooService:
def __init__(self):
self.es = elasticsearch.Elasticsearch(hosts=[{'host': 'localhost', 'port': 9200}])
def create(self, index, body):
es_object = self.es.index(index, body)
return es_object.get('_id')
def read(self, index, id):
es_object = self.es.get(index, id)
return es_object.get('_source')
from unittest import TestCase
from elasticmock import elasticmock
from elasticmock.foo_service import FooService
class FooServiceTest(TestCase):
@elasticmock
def test_create_and_read_object(self):
# Variables used to test
index = 'test-index'
expected_document = {
'foo': 'bar'
}
# Instantiate service
service = FooService()
# Index document on ElasticSearch
id = service.create(index, expected_document)
assert id is not None
# Retrieve document from ElasticSearch
document = service.read(index, id)
assert expected_document == document
Testing started at 16:50 ...
C:\Users\Marcos\py_venv\elasticmock\Scripts\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\plugins\python-ce\helpers\pycharm\_jb_unittest_runner.py" --target foo_service_test.FooServiceTest
Launching unittests with arguments python -m unittest foo_service_test.FooServiceTest in C:\Users\Marcos\workspace\elasticmock\tests
Ran 1 test in 0.003s
OK
Process finished with exit code 0 Could you try it running your tests in a class OR using unittest instead of py.test? Don't know what's going on in your side, but let's figure out! |
Hey! I happened to stumble across the same issue. I believe the reason is that some methods have changed between elasticsearch-py 6.x and 7.x and now also accept an optional def ping(self, params=None): def ping(self, params=None, headers=None): So the methods in |
Based on the error shared by @wpm, which I could reproduce, the test passes when you add |
Awesome that you dove deep and found a workaround! Thanks for sharing that! I'll try to add more checks in the library to make syre it'll properly work even if you do not pass the additional parameters. |
@vrcmarcos is it plausible to add the I mean, I could do it in a PR, but I don't see any change other than adding that parameter to all operations. |
If it worth I have the same issue with
That solve my issue |
I have written a
pytest
version of the sample code.When I run it I get the following error
This is ElasticMock version 1.5.0 and elasticsearch version 7.6.0.
The text was updated successfully, but these errors were encountered: