1
1
from __future__ import annotations
2
2
3
+ from collections .abc import AsyncGenerator , Generator
3
4
from dataclasses import dataclass
4
5
from typing import TYPE_CHECKING
5
6
from unittest .mock import AsyncMock , Mock , patch
22
23
23
24
24
25
# Global variable to track the ids from the buckets created in the tests run
25
- temp_test_buckets_ids = []
26
+ temp_test_buckets_ids : list [ str ] = []
26
27
27
28
28
29
@pytest .fixture
@@ -56,14 +57,10 @@ async def afinalizer():
56
57
request .addfinalizer (AsyncFinalizerFactory (afinalizer ).finalizer )
57
58
58
59
59
- async def bucket_factory (
60
- storage : AsyncStorageClient , uuid_factory : Callable [[], str ], public : bool
61
- ) -> str :
62
- """Creates a test bucket which will be used in the whole storage tests run and deleted at the end"""
63
-
64
-
65
60
@pytest .fixture
66
- async def bucket (storage : AsyncStorageClient , uuid_factory : Callable [[], str ]) -> str :
61
+ async def bucket (
62
+ storage : AsyncStorageClient , uuid_factory : Callable [[], str ]
63
+ ) -> AsyncGenerator [str ]:
67
64
"""Creates a test bucket which will be used in the whole storage tests run and deleted at the end"""
68
65
bucket_id = uuid_factory ()
69
66
@@ -84,7 +81,7 @@ async def bucket(storage: AsyncStorageClient, uuid_factory: Callable[[], str]) -
84
81
@pytest .fixture
85
82
async def public_bucket (
86
83
storage : AsyncStorageClient , uuid_factory : Callable [[], str ]
87
- ) -> str :
84
+ ) -> AsyncGenerator [ str ] :
88
85
"""Creates a test public bucket which will be used in the whole storage tests run and deleted at the end"""
89
86
bucket_id = uuid_factory ()
90
87
@@ -103,15 +100,17 @@ async def public_bucket(
103
100
104
101
105
102
@pytest .fixture
106
- def storage_file_client (storage : AsyncStorageClient , bucket : str ) -> AsyncBucketProxy :
103
+ def storage_file_client (
104
+ storage : AsyncStorageClient , bucket : str
105
+ ) -> Generator [AsyncBucketProxy ]:
107
106
"""Creates the storage file client for the whole storage tests run"""
108
107
yield storage .from_ (bucket )
109
108
110
109
111
110
@pytest .fixture
112
111
def storage_file_client_public (
113
112
storage : AsyncStorageClient , public_bucket : str
114
- ) -> AsyncBucketProxy :
113
+ ) -> Generator [ AsyncBucketProxy ] :
115
114
"""Creates the storage file client for the whole storage tests run"""
116
115
yield storage .from_ (public_bucket )
117
116
@@ -281,6 +280,7 @@ async def test_client_upload(
281
280
image_info = next ((f for f in files if f .get ("name" ) == file .name ), None )
282
281
283
282
assert image == file .file_content
283
+ assert image_info is not None
284
284
assert image_info .get ("metadata" , {}).get ("mimetype" ) == file .mime_type
285
285
286
286
@@ -308,6 +308,7 @@ async def test_client_update(
308
308
)
309
309
310
310
assert image == two_files [1 ].file_content
311
+ assert image_info is not None
311
312
assert image_info .get ("metadata" , {}).get ("mimetype" ) == two_files [1 ].mime_type
312
313
313
314
@@ -339,6 +340,7 @@ async def test_client_upload_to_signed_url(
339
340
image_info = next ((f for f in files if f .get ("name" ) == file .name ), None )
340
341
341
342
assert image == file .file_content
343
+ assert image_info is not None
342
344
assert image_info .get ("metadata" , {}).get ("mimetype" ) == file .mime_type
343
345
344
346
# Test with file_options=None
@@ -586,6 +588,7 @@ async def test_client_copy(
586
588
copied_info = next (
587
589
(f for f in files if f .get ("name" ) == f"copied_{ file .name } " ), None
588
590
)
591
+ assert copied_info is not None
589
592
assert copied_info .get ("metadata" , {}).get ("mimetype" ) == file .mime_type
590
593
591
594
@@ -612,6 +615,7 @@ async def test_client_move(
612
615
# Verify metadata was preserved
613
616
files = await storage_file_client .list (file .bucket_folder )
614
617
moved_info = next ((f for f in files if f .get ("name" ) == f"moved_{ file .name } " ), None )
618
+ assert moved_info is not None
615
619
assert moved_info .get ("metadata" , {}).get ("mimetype" ) == file .mime_type
616
620
617
621
@@ -628,7 +632,7 @@ async def test_client_remove(
628
632
assert await storage_file_client .exists (file .bucket_path )
629
633
630
634
# Remove file
631
- await storage_file_client .remove (file .bucket_path )
635
+ await storage_file_client .remove ([ file .bucket_path ] )
632
636
633
637
# Verify file no longer exists
634
638
assert not await storage_file_client .exists (file .bucket_path )
0 commit comments