File tree Expand file tree Collapse file tree 4 files changed +16
-61
lines changed
src/apify/storage_clients/_apify
e2e/test_schema_storages/actor_source Expand file tree Collapse file tree 4 files changed +16
-61
lines changed Original file line number Diff line number Diff line change @@ -233,6 +233,16 @@ async def store_mapping(self, storage_id: str) -> None:
233233 except Exception as exc :
234234 logger .warning (f'Error storing alias mapping for { self ._alias } : { exc } ' )
235235
236+ @cached_property
237+ def _storage_key (self ) -> str :
238+ return self ._ALIAS_STORAGE_KEY_SEPARATOR .join (
239+ [
240+ self ._storage_type ,
241+ self ._alias ,
242+ hash_api_base_url_and_token (self ._configuration ),
243+ ]
244+ )
245+
236246 @staticmethod
237247 async def _get_default_kvs_client (configuration : Configuration ) -> KeyValueStoreClientAsync :
238248 """Get a client for the default key-value store."""
@@ -248,13 +258,3 @@ async def _get_default_kvs_client(configuration: Configuration) -> KeyValueStore
248258 raise ValueError ("'Configuration.default_key_value_store_id' must be set." )
249259
250260 return apify_client_async .key_value_store (key_value_store_id = configuration .default_key_value_store_id )
251-
252- @cached_property
253- def _storage_key (self ) -> str :
254- return self ._ALIAS_STORAGE_KEY_SEPARATOR .join (
255- [
256- self ._storage_type ,
257- self ._alias ,
258- hash_api_base_url_and_token (self ._configuration ),
259- ]
260- )
Original file line number Diff line number Diff line change 1111 }
1212 }
1313 },
14- "custom_d" : {
15- "actorSpecification" : 1 ,
16- "fields" : {
17- "properties" : {
18- "id" : { "type" : " string" }
19- }
20- }
21- }
22- },
23- "key_value_stores" : {
24- "default" : {
25- "actorSpecification" : 1 ,
26- "fields" : {
27- "properties" : {
28- "id" : { "type" : " string" }
29- }
30- }
31- },
32- "custom_kvs" : {
33- "actorSpecification" : 1 ,
34- "fields" : {
35- "properties" : {
36- "id" : { "type" : " string" }
37- }
38- }
39- }
40- },
41- "request_queues" : {
42- "default" : {
43- "actorSpecification" : 1 ,
44- "fields" : {
45- "properties" : {
46- "id" : { "type" : " string" }
47- }
48- }
49- },
50- "custom_rq" : {
14+ "custom" : {
5115 "actorSpecification" : 1 ,
5216 "fields" : {
5317 "properties" : {
Original file line number Diff line number Diff line change 44async def main () -> None :
55 async with Actor :
66 assert Actor .configuration .actor_storages
7- assert (await Actor .open_dataset (alias = 'custom_d' )).id == Actor .configuration .actor_storages .datasets [
8- 'custom_d'
9- ]
10- assert (await Actor .open_dataset (alias = 'custom_kvs' )).id == Actor .configuration .actor_storages .datasets [
11- 'custom_kvs'
12- ]
13- assert (await Actor .open_dataset (alias = 'custom_rq' )).id == Actor .configuration .actor_storages .datasets [
14- 'custom_rq'
15- ]
7+ assert (await Actor .open_dataset (alias = 'custom' )).id == Actor .configuration .actor_storages .datasets ['custom' ]
Original file line number Diff line number Diff line change @@ -78,23 +78,22 @@ async def test_get_alias_map_returns_in_memory_map() -> None:
7878 assert result == {}
7979
8080
81- async def test_actor_storages_alias_resolving () -> None :
82- """Test that `AliasResolver.register_aliases ` correctly updates default KVS with Actor storages ."""
81+ async def test_configuration_storages_alias_resolving () -> None :
82+ """Test that `AliasResolver` correctly resolves ids of storages registered in Configuration ."""
8383
8484 # Actor storages
8585 datasets = {'default' : 'default_dataset_id' , 'custom' : 'custom_Dataset_id' }
8686 request_queues = {'default' : 'default_request_queue_id' , 'custom' : 'custom_RequestQueue_id' }
8787 key_value_stores = {'default' : 'default_key_value_store_id' , 'custom' : 'custom_KeyValueStore_id' }
8888
89- # Set up the configuration and storage client for the test
89+ # Set up the configuration with the storage mapping
9090 configuration = Configuration (
91- default_key_value_store_id = 'default_kvs_id' ,
9291 actor_storages = ActorStorages (
9392 datasets = datasets , request_queues = request_queues , key_value_stores = key_value_stores
9493 ),
9594 )
9695
97- # Construct the expected mapping
96+ # Check that id of each non-default storage saved in the mapping is resolved
9897 for storage_type in ('Dataset' , 'KeyValueStore' , 'RequestQueue' ):
9998 assert (
10099 await AliasResolver (storage_type = storage_type , alias = 'custom' , configuration = configuration ).resolve_id ()
You can’t perform that action at this time.
0 commit comments