From c1b640a16d34badd74cc2a4d8f0c038d31a9c6f8 Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 15 Jun 2022 15:17:59 +0200 Subject: [PATCH 1/3] Apply key changes --- tests/client/test_client_key_meilisearch.py | 11 +++++++---- tests/conftest.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/client/test_client_key_meilisearch.py b/tests/client/test_client_key_meilisearch.py index 39d320c8..38f27d91 100644 --- a/tests/client/test_client_key_meilisearch.py +++ b/tests/client/test_client_key_meilisearch.py @@ -31,9 +31,11 @@ def test_create_keys_default(client, test_key_info): key = client.create_key(test_key_info) assert isinstance(key, dict) assert 'key' in key + assert 'name' in key assert 'actions' in key assert 'indexes' in key assert key['key'] is not None + assert key['name'] is not None assert key['expiresAt'] is None assert key['createdAt'] is not None assert key['updatedAt'] is not None @@ -43,9 +45,10 @@ def test_create_keys_default(client, test_key_info): def test_create_keys_with_options(client, test_key_info): """Tests the creation of a key with arguments.""" - 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' }) + 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' }) assert isinstance(key, dict) assert key['key'] is not None + assert key['name'] is None assert key['description'] == test_key_info['description'] assert key['expiresAt'] is not None assert key['createdAt'] is not None @@ -61,11 +64,11 @@ def test_create_keys_without_actions(client): def test_update_keys(client, test_key_info): """Tests updating a key.""" key = client.create_key(test_key_info) - assert key['actions'] == test_key_info['actions'] - update_key = client.update_key(key=key['key'], options={ 'actions': ['search'] }) + assert key['name'] == test_key_info['name'] + update_key = client.update_key(key=key['key'], options={ 'name': 'keyTest' }) assert update_key['key'] is not None assert update_key['expiresAt'] is None - assert update_key['actions'] == ['search'] + assert update_key['name'] == 'keyTest' def test_delete_key(client, test_key): """Tests deleting a key.""" diff --git a/tests/conftest.py b/tests/conftest.py index 6607919c..749fcd6f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -109,7 +109,7 @@ def test_key(client): @fixture(scope='function') def test_key_info(client): - key_info = {'description': 'test', 'actions': ['search'], 'indexes': [common.INDEX_UID], 'expiresAt': None} + key_info = {'name': 'testKeyName', 'description': 'test', 'actions': ['search'], 'indexes': [common.INDEX_UID], 'expiresAt': None} yield key_info From ece7430fb63855d9770a64a79522c467c2e42afd Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 23 Jun 2022 15:18:42 +0200 Subject: [PATCH 2/3] Modify param and return information for get_key(s) --- meilisearch/client.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meilisearch/client.py b/meilisearch/client.py index 0354bdac..7bca6188 100644 --- a/meilisearch/client.py +++ b/meilisearch/client.py @@ -240,13 +240,13 @@ def is_healthy(self) -> bool: return False return True - def get_key(self, key: str) -> Dict[str, Any]: + def get_key(self, key_or_uid: str) -> Dict[str, Any]: """Gets information about a specific API key. Parameters ---------- - key: - The key for which to retrieve the information. + key_or_uid: + The key or the uid for which to retrieve the information. Returns ------- @@ -259,7 +259,7 @@ def get_key(self, key: str) -> Dict[str, Any]: MeiliSearchApiError 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 """ - return self.http.get(f'{self.config.paths.keys}/{key}') + return self.http.get(f'{self.config.paths.keys}/{key_or_uid}') def get_keys(self) -> Dict[str, Any]: """Gets the Meilisearch API keys. @@ -267,7 +267,7 @@ def get_keys(self) -> Dict[str, Any]: Returns ------- keys: - API keys. + Dictionary with limit, offset, total and results a list of dictionaries containing the key information. https://docs.meilisearch.com/reference/api/keys.html#get-keys Raises From 80947ac82d72fd31026e1d813947ffca179ebb15 Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 23 Jun 2022 16:04:34 +0200 Subject: [PATCH 3/3] Fix tests --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 749fcd6f..314d92cb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -123,5 +123,5 @@ def test_key_info(client): @fixture(scope='function') def get_private_key(client): keys = client.get_keys()['results'] - key = next(x for x in keys if 'Default Search API' in x['description']) + key = next(x for x in keys if 'Default Search API' in x['name']) return key