-
Notifications
You must be signed in to change notification settings - Fork 95
Adding generate_tenant_token method #412
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
Changes from all commits
36e2161
1500c51
7d41151
f254aca
985db06
0ac90d7
5e214de
433966d
77294cb
7579c8f
5c81b20
09577a5
7f10221
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # pylint: disable=invalid-name | ||
|
|
||
| from re import search | ||
| import pytest | ||
| import meilisearch | ||
| from tests import BASE_URL, MASTER_KEY | ||
| from meilisearch.errors import MeiliSearchApiError | ||
| import datetime | ||
|
|
||
| def test_generate_tenant_token_with_search_rules(get_private_key, index_with_documents): | ||
| """Tests create a tenant token with only search rules.""" | ||
| index_with_documents() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you have a setup handler without documents or a simple index creation? Because it's good to avoid unnecessarily setup :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had documents to check the search return at least a few documents. I find that doing a search without results was less convincing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And same as above I just let this specific verification on the first one with search_rules |
||
| client = meilisearch.Client(BASE_URL, get_private_key['key']) | ||
|
|
||
| token = client.generate_tenant_token(search_rules=["*"]) | ||
|
|
||
| token_client = meilisearch.Client(BASE_URL, token) | ||
| response = token_client.index('indexUID').search('', { | ||
| 'limit': 5 | ||
| }) | ||
| assert isinstance(response, dict) | ||
| assert len(response['hits']) == 5 | ||
| assert response['query'] == '' | ||
|
|
||
| def test_generate_tenant_token_with_search_rules_on_one_index(get_private_key, empty_index): | ||
| """Tests create a tenant token with search rules set for one index.""" | ||
| empty_index() | ||
| empty_index('tenant_token') | ||
| client = meilisearch.Client(BASE_URL, get_private_key['key']) | ||
|
|
||
| token = client.generate_tenant_token(search_rules=['indexUID']) | ||
|
|
||
| token_client = meilisearch.Client(BASE_URL, token) | ||
| response = token_client.index('indexUID').search('') | ||
| assert isinstance(response, dict) | ||
| assert response['query'] == '' | ||
| with pytest.raises(MeiliSearchApiError): | ||
| response = token_client.index('tenant_token').search('') | ||
|
|
||
| def test_generate_tenant_token_with_api_key(client, get_private_key, empty_index): | ||
| """Tests create a tenant token with search rules and an api key.""" | ||
| empty_index() | ||
| token = client.generate_tenant_token(search_rules=["*"], api_key=get_private_key['key']) | ||
|
|
||
| token_client = meilisearch.Client(BASE_URL, token) | ||
| response = token_client.index('indexUID').search('') | ||
| assert isinstance(response, dict) | ||
| assert response['query'] == '' | ||
|
|
||
| def test_generate_tenant_token_with_expires_at(client, get_private_key, empty_index): | ||
| """Tests create a tenant token with search rules and expiration date.""" | ||
| empty_index() | ||
| client = meilisearch.Client(BASE_URL, get_private_key['key']) | ||
| tomorrow = datetime.datetime.now() + datetime.timedelta(days=1) | ||
|
|
||
| token = client.generate_tenant_token(search_rules=["*"], expires_at=tomorrow) | ||
|
|
||
| token_client = meilisearch.Client(BASE_URL, token) | ||
| response = token_client.index('indexUID').search('') | ||
| assert isinstance(response, dict) | ||
| assert response['query'] == '' | ||
|
|
||
| def test_generate_tenant_token_with_empty_search_rules_in_list(get_private_key): | ||
| """Tests create a tenant token without search rules.""" | ||
| client = meilisearch.Client(BASE_URL, get_private_key['key']) | ||
|
|
||
| with pytest.raises(Exception): | ||
| client.generate_tenant_token(search_rules=['']) | ||
|
|
||
| def test_generate_tenant_token_without_search_rules_in_list(get_private_key): | ||
| """Tests create a tenant token without search rules.""" | ||
| client = meilisearch.Client(BASE_URL, get_private_key['key']) | ||
|
|
||
| with pytest.raises(Exception): | ||
| client.generate_tenant_token(search_rules=[]) | ||
|
|
||
| def test_generate_tenant_token_without_search_rules_in_dict(get_private_key): | ||
| """Tests create a tenant token without search rules.""" | ||
| client = meilisearch.Client(BASE_URL, get_private_key['key']) | ||
|
|
||
| with pytest.raises(Exception): | ||
| client.generate_tenant_token(search_rules={}) | ||
|
|
||
| def test_generate_tenant_token_with_empty_search_rules_in_dict(get_private_key): | ||
| """Tests create a tenant token without search rules.""" | ||
alallema marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| client = meilisearch.Client(BASE_URL, get_private_key['key']) | ||
|
|
||
| with pytest.raises(Exception): | ||
| client.generate_tenant_token(search_rules={''}) | ||
|
|
||
| def test_generate_tenant_token_with_bad_expires_at(client, get_private_key): | ||
| """Tests create a tenant token with a bad expires at.""" | ||
| client = meilisearch.Client(BASE_URL, get_private_key['key']) | ||
|
|
||
| yesterday = datetime.datetime.utcnow() + datetime.timedelta(days=-1) | ||
|
|
||
| with pytest.raises(Exception): | ||
| client.generate_tenant_token(search_rules=["*"], expires_at=yesterday) | ||
|
|
||
| def test_generate_tenant_token_with_no_api_key(client): | ||
| """Tests create a tenant token with no api key.""" | ||
| client = meilisearch.Client(BASE_URL) | ||
|
|
||
| with pytest.raises(Exception): | ||
| client.generate_tenant_token(search_rules=["*"]) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.