Skip to content

Commit 76922a7

Browse files
author
Dani Reinón
committed
tests: ignore 404 when double-checking bucket deletion
1 parent 0b61397 commit 76922a7

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

Diff for: supabase/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
from supabase.client import Client, create_client
55
from supabase.lib.auth_client import SupabaseAuthClient
66
from supabase.lib.realtime_client import SupabaseRealtimeClient
7-
from supabase.lib.storage_client import StorageFileAPI, SupabaseStorageClient
7+
from supabase.lib.storage import StorageException, StorageFileAPI
8+
from supabase.lib.storage_client import SupabaseStorageClient

Diff for: supabase/lib/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from supabase.lib import auth_client, realtime_client, storage_client
1+
from supabase.lib import auth_client, realtime_client, storage, storage_client
22

3-
__all__ = ["auth_client", "realtime_client", "storage_client"]
3+
__all__ = ["auth_client", "realtime_client", "storage_client", "storage"]

Diff for: supabase/lib/storage/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .storage_bucket_api import StorageBucketAPI, StorageException
2+
from .storage_file_api import StorageFileAPI

Diff for: supabase/lib/storage/storage_bucket_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from httpx import AsyncClient, Client, HTTPError
99

10-
__all__ = ["Bucket", "StorageBucketAPI"]
10+
__all__ = ["Bucket", "StorageBucketAPI", "StorageException"]
1111

1212
_RequestMethod = str
1313

Diff for: tests/test_storage.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from __future__ import annotations
22

3-
from time import sleep
43
from typing import TYPE_CHECKING
54
from uuid import uuid4
65

76
import pytest
87

8+
from supabase import StorageException
9+
910
if TYPE_CHECKING:
1011
from pathlib import Path
1112
from typing import Any, Callable, Dict, List
@@ -39,16 +40,21 @@ def delete_left_buckets(
3940
"""Ensures no test buckets are left"""
4041

4142
def finalizer():
42-
# Sleep 15 seconds in order to let buckets be deleted before the double-check
43-
sleep(15)
4443
buckets_list = storage_client.list_buckets()
4544
if not buckets_list:
4645
return
4746

4847
for bucket in buckets_list:
4948
if bucket.id.startswith(UUID_PREFIX):
50-
storage_client.empty_bucket(bucket.id)
51-
storage_client.delete_bucket(bucket.id)
49+
try:
50+
storage_client.empty_bucket(bucket.id)
51+
storage_client.delete_bucket(bucket.id)
52+
except StorageException as e:
53+
# Ignore 404 responses since they mean the bucket was already deleted
54+
response = e.args[0]
55+
if response["status_code"] != 404:
56+
raise e
57+
continue
5258

5359
request.addfinalizer(finalizer)
5460

0 commit comments

Comments
 (0)