-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add dataset.create_items_public_url and key_value_store.create_keys_public_url #453
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
12 commits
Select commit
Hold shift + click to select a range
c34b073
feat: add Dataset.create_items_public_url and KeyValueStore.create_ke…
danpoletaev 6402e2b
chore: updated tests to use httpx client
danpoletaev 77384c5
refactor: clean up
danpoletaev 1e8faf6
refactor: clean up
danpoletaev adbcb4d
fix: use create_storage_content_signature from shared package
danpoletaev c4b4ec7
refactor: add apify-shared version requirements
danpoletaev d1fe218
chore: upper bouynd apify-shared
danpoletaev 65b10c3
chore: upper bouynd apify-shared
danpoletaev eec0233
Merge branch 'master' into feat/storage-sign-content-url
danpoletaev d90ac9e
Merge branch 'master' into feat/storage-sign-content-url
danpoletaev 0ecbed2
refactor: clean up
danpoletaev 1c7c41b
refactor: rename expires_in_seconds to expires_in_secs
danpoletaev 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,10 @@ | ||
import secrets | ||
import string | ||
|
||
|
||
def random_string(length: int = 10) -> str: | ||
return ''.join(secrets.choice(string.ascii_letters) for _ in range(length)) | ||
|
||
|
||
def random_resource_name(resource: str) -> str: | ||
return f'python-client-test-{resource}-{random_string(5)}' |
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,90 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import impit | ||
|
||
from integration.integration_test_utils import random_resource_name | ||
|
||
if TYPE_CHECKING: | ||
from apify_client import ApifyClient, ApifyClientAsync | ||
|
||
|
||
class TestDatasetSync: | ||
def test_dataset_should_create_public_items_expiring_url_with_params(self, apify_client: ApifyClient) -> None: | ||
created_dataset = apify_client.datasets().get_or_create(name=random_resource_name('dataset')) | ||
|
||
dataset = apify_client.dataset(created_dataset['id']) | ||
items_public_url = dataset.create_items_public_url( | ||
expires_in_secs=2000, | ||
limit=10, | ||
offset=0, | ||
) | ||
|
||
assert 'signature=' in items_public_url | ||
assert 'limit=10' in items_public_url | ||
assert 'offset=0' in items_public_url | ||
|
||
impit_client = impit.Client() | ||
response = impit_client.get(items_public_url, timeout=5) | ||
assert response.status_code == 200 | ||
|
||
dataset.delete() | ||
assert apify_client.dataset(created_dataset['id']).get() is None | ||
|
||
def test_dataset_should_create_public_items_non_expiring_url(self, apify_client: ApifyClient) -> None: | ||
created_dataset = apify_client.datasets().get_or_create(name=random_resource_name('dataset')) | ||
|
||
dataset = apify_client.dataset(created_dataset['id']) | ||
items_public_url = dataset.create_items_public_url() | ||
|
||
assert 'signature=' in items_public_url | ||
|
||
impit_client = impit.Client() | ||
response = impit_client.get(items_public_url, timeout=5) | ||
assert response.status_code == 200 | ||
|
||
dataset.delete() | ||
assert apify_client.dataset(created_dataset['id']).get() is None | ||
|
||
|
||
class TestDatasetAsync: | ||
async def test_dataset_should_create_public_items_expiring_url_with_params( | ||
self, apify_client_async: ApifyClientAsync | ||
) -> None: | ||
created_dataset = await apify_client_async.datasets().get_or_create(name=random_resource_name('dataset')) | ||
|
||
dataset = apify_client_async.dataset(created_dataset['id']) | ||
items_public_url = await dataset.create_items_public_url( | ||
expires_in_secs=2000, | ||
limit=10, | ||
offset=0, | ||
) | ||
|
||
assert 'signature=' in items_public_url | ||
assert 'limit=10' in items_public_url | ||
assert 'offset=0' in items_public_url | ||
|
||
impit_async_client = impit.AsyncClient() | ||
response = await impit_async_client.get(items_public_url, timeout=5) | ||
assert response.status_code == 200 | ||
|
||
await dataset.delete() | ||
assert await apify_client_async.dataset(created_dataset['id']).get() is None | ||
|
||
async def test_dataset_should_create_public_items_non_expiring_url( | ||
self, apify_client_async: ApifyClientAsync | ||
) -> None: | ||
created_dataset = await apify_client_async.datasets().get_or_create(name=random_resource_name('dataset')) | ||
|
||
dataset = apify_client_async.dataset(created_dataset['id']) | ||
items_public_url = await dataset.create_items_public_url() | ||
|
||
assert 'signature=' in items_public_url | ||
|
||
impit_async_client = impit.AsyncClient() | ||
response = await impit_async_client.get(items_public_url, timeout=5) | ||
assert response.status_code == 200 | ||
|
||
await dataset.delete() | ||
assert await apify_client_async.dataset(created_dataset['id']).get() is None |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm starting here the rest of the function seems identical to the async variant. Now sure if there is a nice way to reuse the code? I guess this is how we do it here in the client? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about this, but this is how every other methods are written. WDYT @janbuchar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We sure do repeat stuff here, but no need to change that now. Perhaps one day we can generate the whole client lib from an OpenAPI spec. Until then, this will have to do