Skip to content

Commit 8015bf8

Browse files
authored
Merge pull request #477 from meilisearch/key_changes
Apply key changes
2 parents d0d0120 + 80947ac commit 8015bf8

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

meilisearch/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,13 @@ def is_healthy(self) -> bool:
240240
return False
241241
return True
242242

243-
def get_key(self, key: str) -> Dict[str, Any]:
243+
def get_key(self, key_or_uid: str) -> Dict[str, Any]:
244244
"""Gets information about a specific API key.
245245
246246
Parameters
247247
----------
248-
key:
249-
The key for which to retrieve the information.
248+
key_or_uid:
249+
The key or the uid for which to retrieve the information.
250250
251251
Returns
252252
-------
@@ -259,15 +259,15 @@ def get_key(self, key: str) -> Dict[str, Any]:
259259
MeiliSearchApiError
260260
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
261261
"""
262-
return self.http.get(f'{self.config.paths.keys}/{key}')
262+
return self.http.get(f'{self.config.paths.keys}/{key_or_uid}')
263263

264264
def get_keys(self) -> Dict[str, Any]:
265265
"""Gets the Meilisearch API keys.
266266
267267
Returns
268268
-------
269269
keys:
270-
API keys.
270+
Dictionary with limit, offset, total and results a list of dictionaries containing the key information.
271271
https://docs.meilisearch.com/reference/api/keys.html#get-keys
272272
273273
Raises

tests/client/test_client_key_meilisearch.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ def test_create_keys_default(client, test_key_info):
3131
key = client.create_key(test_key_info)
3232
assert isinstance(key, dict)
3333
assert 'key' in key
34+
assert 'name' in key
3435
assert 'actions' in key
3536
assert 'indexes' in key
3637
assert key['key'] is not None
38+
assert key['name'] is not None
3739
assert key['expiresAt'] is None
3840
assert key['createdAt'] is not None
3941
assert key['updatedAt'] is not None
@@ -43,9 +45,10 @@ def test_create_keys_default(client, test_key_info):
4345

4446
def test_create_keys_with_options(client, test_key_info):
4547
"""Tests the creation of a key with arguments."""
46-
key = client.create_key(options={'description': test_key_info['description'], 'actions': test_key_info['actions'], 'indexes': test_key_info['indexes'], 'expiresAt': datetime(2030, 6, 4, 21, 8, 12, 32).isoformat()[:-3]+'Z' })
48+
key = client.create_key(options={'description': test_key_info['description'], 'actions': test_key_info['actions'], 'indexes': test_key_info['indexes'], 'uid': '82acc342-d2df-4291-84bd-8400d3f05f06', 'expiresAt': datetime(2030, 6, 4, 21, 8, 12, 32).isoformat()[:-3]+'Z' })
4749
assert isinstance(key, dict)
4850
assert key['key'] is not None
51+
assert key['name'] is None
4952
assert key['description'] == test_key_info['description']
5053
assert key['expiresAt'] is not None
5154
assert key['createdAt'] is not None
@@ -61,11 +64,11 @@ def test_create_keys_without_actions(client):
6164
def test_update_keys(client, test_key_info):
6265
"""Tests updating a key."""
6366
key = client.create_key(test_key_info)
64-
assert key['actions'] == test_key_info['actions']
65-
update_key = client.update_key(key=key['key'], options={ 'actions': ['search'] })
67+
assert key['name'] == test_key_info['name']
68+
update_key = client.update_key(key=key['key'], options={ 'name': 'keyTest' })
6669
assert update_key['key'] is not None
6770
assert update_key['expiresAt'] is None
68-
assert update_key['actions'] == ['search']
71+
assert update_key['name'] == 'keyTest'
6972

7073
def test_delete_key(client, test_key):
7174
"""Tests deleting a key."""

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_key(client):
109109

110110
@fixture(scope='function')
111111
def test_key_info(client):
112-
key_info = {'description': 'test', 'actions': ['search'], 'indexes': [common.INDEX_UID], 'expiresAt': None}
112+
key_info = {'name': 'testKeyName', 'description': 'test', 'actions': ['search'], 'indexes': [common.INDEX_UID], 'expiresAt': None}
113113

114114
yield key_info
115115

@@ -123,5 +123,5 @@ def test_key_info(client):
123123
@fixture(scope='function')
124124
def get_private_key(client):
125125
keys = client.get_keys()['results']
126-
key = next(x for x in keys if 'Default Search API' in x['description'])
126+
key = next(x for x in keys if 'Default Search API' in x['name'])
127127
return key

0 commit comments

Comments
 (0)