11from __future__ import annotations
22
3+ from collections .abc import AsyncGenerator , Generator
34from dataclasses import dataclass
45from typing import TYPE_CHECKING
56from unittest .mock import AsyncMock , Mock , patch
2223
2324
2425# 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 ] = []
2627
2728
2829@pytest .fixture
@@ -56,14 +57,10 @@ async def afinalizer():
5657 request .addfinalizer (AsyncFinalizerFactory (afinalizer ).finalizer )
5758
5859
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-
6560@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 ]:
6764 """Creates a test bucket which will be used in the whole storage tests run and deleted at the end"""
6865 bucket_id = uuid_factory ()
6966
@@ -84,7 +81,7 @@ async def bucket(storage: AsyncStorageClient, uuid_factory: Callable[[], str]) -
8481@pytest .fixture
8582async def public_bucket (
8683 storage : AsyncStorageClient , uuid_factory : Callable [[], str ]
87- ) -> str :
84+ ) -> AsyncGenerator [ str ] :
8885 """Creates a test public bucket which will be used in the whole storage tests run and deleted at the end"""
8986 bucket_id = uuid_factory ()
9087
@@ -103,15 +100,17 @@ async def public_bucket(
103100
104101
105102@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 ]:
107106 """Creates the storage file client for the whole storage tests run"""
108107 yield storage .from_ (bucket )
109108
110109
111110@pytest .fixture
112111def storage_file_client_public (
113112 storage : AsyncStorageClient , public_bucket : str
114- ) -> AsyncBucketProxy :
113+ ) -> Generator [ AsyncBucketProxy ] :
115114 """Creates the storage file client for the whole storage tests run"""
116115 yield storage .from_ (public_bucket )
117116
@@ -281,6 +280,7 @@ async def test_client_upload(
281280 image_info = next ((f for f in files if f .get ("name" ) == file .name ), None )
282281
283282 assert image == file .file_content
283+ assert image_info is not None
284284 assert image_info .get ("metadata" , {}).get ("mimetype" ) == file .mime_type
285285
286286
@@ -308,6 +308,7 @@ async def test_client_update(
308308 )
309309
310310 assert image == two_files [1 ].file_content
311+ assert image_info is not None
311312 assert image_info .get ("metadata" , {}).get ("mimetype" ) == two_files [1 ].mime_type
312313
313314
@@ -339,6 +340,7 @@ async def test_client_upload_to_signed_url(
339340 image_info = next ((f for f in files if f .get ("name" ) == file .name ), None )
340341
341342 assert image == file .file_content
343+ assert image_info is not None
342344 assert image_info .get ("metadata" , {}).get ("mimetype" ) == file .mime_type
343345
344346 # Test with file_options=None
@@ -586,6 +588,7 @@ async def test_client_copy(
586588 copied_info = next (
587589 (f for f in files if f .get ("name" ) == f"copied_{ file .name } " ), None
588590 )
591+ assert copied_info is not None
589592 assert copied_info .get ("metadata" , {}).get ("mimetype" ) == file .mime_type
590593
591594
@@ -612,6 +615,7 @@ async def test_client_move(
612615 # Verify metadata was preserved
613616 files = await storage_file_client .list (file .bucket_folder )
614617 moved_info = next ((f for f in files if f .get ("name" ) == f"moved_{ file .name } " ), None )
618+ assert moved_info is not None
615619 assert moved_info .get ("metadata" , {}).get ("mimetype" ) == file .mime_type
616620
617621
@@ -628,7 +632,7 @@ async def test_client_remove(
628632 assert await storage_file_client .exists (file .bucket_path )
629633
630634 # Remove file
631- await storage_file_client .remove (file .bucket_path )
635+ await storage_file_client .remove ([ file .bucket_path ] )
632636
633637 # Verify file no longer exists
634638 assert not await storage_file_client .exists (file .bucket_path )
0 commit comments