Skip to content

Fix: uid in options does not overwrite the parameter in create_index #105

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

Merged
merged 1 commit into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion meilisearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def create(config, uid, options=None):
"""
if options is None:
options = {}
payload = {'uid': uid, **options}
payload = {**options, 'uid': uid}
return HttpRequests(config).post(config.paths.index, payload)

@staticmethod
Expand Down
21 changes: 20 additions & 1 deletion meilisearch/tests/index/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TestIndex:
client = meilisearch.Client(BASE_URL, MASTER_KEY)
index_uid = 'indexUID'
index_uid2 = 'indexUID2'
index_uid3 = 'indexUID3'

def setup_class(self):
clear_all_indexes(self.client)
Expand All @@ -27,11 +28,22 @@ def test_create_index_with_primary_key(self):
assert index.uid == self.index_uid2
assert index.get_primary_key() == 'book_id'

def test_create_index_with_uid_in_options(self):
"""Tests creating an index with a primary key"""
index = self.client.create_index(uid=self.index_uid3, options={'uid': 'wrong', 'primaryKey': 'book_id'})
assert isinstance(index, object)
assert index.uid == self.index_uid3
assert index.get_primary_key() == 'book_id'

def test_get_indexes(self):
"""Tests getting all indexes"""
response = self.client.get_indexes()
uids = [index['uid'] for index in response]
assert isinstance(response, list)
assert response[0]['uid'] == self.index_uid
assert self.index_uid in uids
assert self.index_uid2 in uids
assert self.index_uid3 in uids
assert len(response) == 3

def test_get_index_with_uid(self):
"""Tests getting one index with uid"""
Expand Down Expand Up @@ -84,3 +96,10 @@ def test_delete_index(self):
assert response.status_code == 204
with pytest.raises(Exception):
self.client.get_index(uid=self.index_uid2).info()
index = self.client.get_index(uid=self.index_uid3)
response = index.delete()
assert isinstance(response, object)
assert response.status_code == 204
with pytest.raises(Exception):
self.client.get_index(uid=self.index_uid3).info()
assert len(self.client.get_indexes()) == 0