Skip to content

Commit 1097e5f

Browse files
authored
refactor: consolidate StorageOwnership to the generated StrEnum (#735)
## Summary - Removes the duplicate `StorageOwnership` `Literal` from `_types.py`. - Reuses the auto-generated `StorageOwnership` `StrEnum` from `_models.py` in the dataset, key-value store, and request queue collection clients. - Updates the unit tests to pass enum members (`StorageOwnership.OWNED_BY_ME` / `SHARED_WITH_ME`) instead of raw strings. Closes #700.
1 parent 3d4ce3f commit 1097e5f

5 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/apify_client/_resource_clients/dataset_collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from typing import TYPE_CHECKING, Any
44

55
from apify_client._docs import docs_group
6-
from apify_client._models import Dataset, DatasetResponse, ListOfDatasets, ListOfDatasetsResponse
6+
from apify_client._models import Dataset, DatasetResponse, ListOfDatasets, ListOfDatasetsResponse, StorageOwnership
77
from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync
88

99
if TYPE_CHECKING:
10-
from apify_client._types import StorageOwnership, Timeout
10+
from apify_client._types import Timeout
1111

1212

1313
@docs_group('Resource clients')

src/apify_client/_resource_clients/key_value_store_collection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
KeyValueStoreResponse,
99
ListOfKeyValueStores,
1010
ListOfKeyValueStoresResponse,
11+
StorageOwnership,
1112
)
1213
from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync
1314

1415
if TYPE_CHECKING:
15-
from apify_client._types import StorageOwnership, Timeout
16+
from apify_client._types import Timeout
1617

1718

1819
@docs_group('Resource clients')

src/apify_client/_resource_clients/request_queue_collection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
ListOfRequestQueuesResponse,
99
RequestQueue,
1010
RequestQueueResponse,
11+
StorageOwnership,
1112
)
1213
from apify_client._resource_clients._resource_client import ResourceClient, ResourceClientAsync
1314

1415
if TYPE_CHECKING:
15-
from apify_client._types import StorageOwnership, Timeout
16+
from apify_client._types import Timeout
1617

1718

1819
@docs_group('Resource clients')

src/apify_client/_types.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
from apify_client._models import ActorJobStatus, WebhookCreate # noqa: TC001
1111

12-
StorageOwnership = Literal['ownedByMe', 'sharedWithMe']
13-
"""Filter for storage listing methods to return only storages owned by the user or shared with the user."""
14-
1512
Timeout = timedelta | Literal['no_timeout', 'short', 'medium', 'long']
1613
"""Type for the `timeout` parameter on resource client methods.
1714

tests/unit/test_storage_collection_listing.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from werkzeug.wrappers import Response
88

99
from apify_client import ApifyClient, ApifyClientAsync
10+
from apify_client._models import StorageOwnership
1011

1112
if TYPE_CHECKING:
1213
from collections.abc import Callable
@@ -47,7 +48,7 @@ def test_dataset_collection_list_ownership_sync(httpserver: HTTPServer, client_u
4748
httpserver.expect_oneshot_request('/v2/datasets', method='GET').respond_with_handler(_make_handler(captured))
4849

4950
client = ApifyClient(token='placeholder_token', **client_urls)
50-
result = client.datasets().list(ownership='ownedByMe')
51+
result = client.datasets().list(ownership=StorageOwnership.OWNED_BY_ME)
5152

5253
assert result.total == 0
5354
assert captured['args']['ownership'] == 'ownedByMe'
@@ -58,7 +59,7 @@ async def test_dataset_collection_list_ownership_async(httpserver: HTTPServer, c
5859
httpserver.expect_oneshot_request('/v2/datasets', method='GET').respond_with_handler(_make_handler(captured))
5960

6061
client = ApifyClientAsync(token='placeholder_token', **client_urls)
61-
result = await client.datasets().list(ownership='sharedWithMe')
62+
result = await client.datasets().list(ownership=StorageOwnership.SHARED_WITH_ME)
6263

6364
assert result.total == 0
6465
assert captured['args']['ownership'] == 'sharedWithMe'
@@ -71,7 +72,7 @@ def test_key_value_store_collection_list_ownership_sync(httpserver: HTTPServer,
7172
)
7273

7374
client = ApifyClient(token='placeholder_token', **client_urls)
74-
result = client.key_value_stores().list(ownership='ownedByMe')
75+
result = client.key_value_stores().list(ownership=StorageOwnership.OWNED_BY_ME)
7576

7677
assert result.total == 0
7778
assert captured['args']['ownership'] == 'ownedByMe'
@@ -84,7 +85,7 @@ async def test_key_value_store_collection_list_ownership_async(httpserver: HTTPS
8485
)
8586

8687
client = ApifyClientAsync(token='placeholder_token', **client_urls)
87-
result = await client.key_value_stores().list(ownership='sharedWithMe')
88+
result = await client.key_value_stores().list(ownership=StorageOwnership.SHARED_WITH_ME)
8889

8990
assert result.total == 0
9091
assert captured['args']['ownership'] == 'sharedWithMe'
@@ -95,7 +96,7 @@ def test_request_queue_collection_list_ownership_sync(httpserver: HTTPServer, cl
9596
httpserver.expect_oneshot_request('/v2/request-queues', method='GET').respond_with_handler(_make_handler(captured))
9697

9798
client = ApifyClient(token='placeholder_token', **client_urls)
98-
result = client.request_queues().list(ownership='ownedByMe')
99+
result = client.request_queues().list(ownership=StorageOwnership.OWNED_BY_ME)
99100

100101
assert result.total == 0
101102
assert captured['args']['ownership'] == 'ownedByMe'
@@ -106,7 +107,7 @@ async def test_request_queue_collection_list_ownership_async(httpserver: HTTPSer
106107
httpserver.expect_oneshot_request('/v2/request-queues', method='GET').respond_with_handler(_make_handler(captured))
107108

108109
client = ApifyClientAsync(token='placeholder_token', **client_urls)
109-
result = await client.request_queues().list(ownership='sharedWithMe')
110+
result = await client.request_queues().list(ownership=StorageOwnership.SHARED_WITH_ME)
110111

111112
assert result.total == 0
112113
assert captured['args']['ownership'] == 'sharedWithMe'

0 commit comments

Comments
 (0)