-
Notifications
You must be signed in to change notification settings - Fork 90
Addition related to API keys #382
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import pytest | ||
from tests import common | ||
from datetime import datetime | ||
from meilisearch.errors import MeiliSearchApiError | ||
|
||
def test_get_keys_default(client): | ||
"""Tests if public and private keys have been generated and can be retrieved.""" | ||
keys = client.get_keys() | ||
assert isinstance(keys, list) | ||
assert len(keys) == 2 | ||
assert 'actions' in keys[0] | ||
assert 'indexes' in keys[0] | ||
assert keys[0]['key'] is not None | ||
assert keys[1]['key'] is not None | ||
|
||
def test_get_key(client, test_key): | ||
"""Tests if a key can be retrieved.""" | ||
key = client.get_key(test_key['key']) | ||
assert isinstance(key, dict) | ||
assert 'actions' in key | ||
assert 'indexes' in key | ||
assert key['createdAt'] is not None | ||
|
||
def test_get_key_inexistent(client): | ||
"""Tests getting a key that does not exists.""" | ||
with pytest.raises(Exception): | ||
client.get_key('No existing key') | ||
|
||
def test_create_keys_default(client, test_key_info): | ||
"""Tests the creation of a key with no optional argument.""" | ||
key = client.create_key(test_key_info) | ||
assert isinstance(key, dict) | ||
assert 'key' in key | ||
assert 'actions' in key | ||
assert 'indexes' in key | ||
assert key['key'] is not None | ||
assert key['expiresAt'] is None | ||
assert key['createdAt'] is not None | ||
assert key['updatedAt'] is not None | ||
assert key['key'] is not None | ||
assert key['actions'] == test_key_info['actions'] | ||
assert key['indexes'] == test_key_info['indexes'] | ||
|
||
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' }) | ||
assert isinstance(key, dict) | ||
assert key['key'] is not None | ||
assert key['description'] == test_key_info['description'] | ||
assert key['expiresAt'] is not None | ||
assert key['createdAt'] is not None | ||
assert key['updatedAt'] is not None | ||
assert key['actions'] == test_key_info['actions'] | ||
assert key['indexes'] == test_key_info['indexes'] | ||
|
||
def test_create_keys_without_actions(client): | ||
"""Tests the creation of a key with missing arguments.""" | ||
with pytest.raises(MeiliSearchApiError): | ||
client.create_key(options={'indexes': [common.INDEX_UID]}) | ||
|
||
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.udpate_key(key=key['key'], options={ 'actions': ['search'] }) | ||
assert update_key['key'] is not None | ||
assert update_key['expiresAt'] is None | ||
assert update_key['actions'] == ['search'] | ||
|
||
def test_delete_key(client, test_key): | ||
"""Tests deleting a key.""" | ||
resp = client.delete_key(test_key['key']) | ||
assert resp.status_code == 204 | ||
with pytest.raises(MeiliSearchApiError): | ||
client.get_key(test_key['key']) | ||
|
||
def test_delete_key_inexisting(client): | ||
"""Tests deleting a key that does not exists.""" | ||
with pytest.raises(MeiliSearchApiError): | ||
client.delete_key('No existing key') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.