Skip to content

Commit 614cacc

Browse files
chore(tests): increase coverage (#1053)
1 parent 29fed38 commit 614cacc

File tree

4 files changed

+112
-6
lines changed

4 files changed

+112
-6
lines changed

supabase/__init__.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
from ._async.client import AsyncClient
2020
from ._async.client import AsyncClient as AClient
2121
from ._async.client import AsyncStorageClient as ASupabaseStorageClient
22+
from ._async.client import SupabaseException as ASupabaseException
2223
from ._async.client import create_client as acreate_client
2324
from ._async.client import create_client as create_async_client
2425

2526
# Sync Client
2627
from ._sync.auth_client import SyncSupabaseAuthClient as SupabaseAuthClient
28+
from ._sync.client import SupabaseException
2729
from ._sync.client import SyncClient as Client
2830
from ._sync.client import SyncStorageClient as SupabaseStorageClient
2931
from ._sync.client import create_client
@@ -36,7 +38,7 @@
3638
# Version
3739
from .version import __version__
3840

39-
__all__ = [
41+
__all__ = (
4042
"acreate_client",
4143
"create_async_client",
4244
"AClient",
@@ -67,4 +69,6 @@
6769
"FunctionsError",
6870
"AuthorizationError",
6971
"NotConnectedError",
70-
]
72+
"SupabaseException",
73+
"ASupabaseException",
74+
)

tests/_async/test_client.py

+49-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,55 @@
11
import os
22
from unittest.mock import AsyncMock, MagicMock
33

4-
from supabase import create_async_client
4+
from supabase import AClient, ASupabaseException, create_async_client
5+
6+
7+
async def test_incorrect_values_dont_instantiate_client() -> None:
8+
"""Ensure we can't instantiate client with invalid values."""
9+
try:
10+
client: AClient = create_async_client(None, None)
11+
except ASupabaseException:
12+
pass
13+
14+
15+
async def test_supabase_exception() -> None:
16+
try:
17+
raise ASupabaseException("err")
18+
except ASupabaseException:
19+
pass
20+
21+
22+
async def test_postgrest_client() -> None:
23+
url = os.environ.get("SUPABASE_TEST_URL")
24+
key = os.environ.get("SUPABASE_TEST_KEY")
25+
26+
client = await create_async_client(url, key)
27+
assert client.table("sample")
28+
29+
30+
async def test_rpc_client() -> None:
31+
url = os.environ.get("SUPABASE_TEST_URL")
32+
key = os.environ.get("SUPABASE_TEST_KEY")
33+
34+
client = await create_async_client(url, key)
35+
assert client.rpc("test_fn")
36+
37+
38+
async def test_function_initialization() -> None:
39+
url = os.environ.get("SUPABASE_TEST_URL")
40+
key = os.environ.get("SUPABASE_TEST_KEY")
41+
42+
client = await create_async_client(url, key)
43+
assert client.functions
44+
45+
46+
async def test_schema_update() -> None:
47+
url = os.environ.get("SUPABASE_TEST_URL")
48+
key = os.environ.get("SUPABASE_TEST_KEY")
49+
50+
client = await create_async_client(url, key)
51+
assert client.postgrest
52+
assert client.schema("new_schema")
553

654

755
async def test_updates_the_authorization_header_on_auth_events() -> None:

tests/test_client.py

+30-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytest
88

9-
from supabase import Client, ClientOptions, create_client
9+
from supabase import Client, ClientOptions, SupabaseException, create_client
1010

1111

1212
@pytest.mark.xfail(
@@ -16,7 +16,35 @@
1616
@pytest.mark.parametrize("key", ["", None, "valeefgpoqwjgpj", 139, -1, {}, []])
1717
def test_incorrect_values_dont_instantiate_client(url: Any, key: Any) -> None:
1818
"""Ensure we can't instantiate client with invalid values."""
19-
_: Client = create_client(url, key)
19+
try:
20+
_: Client = create_client(url, key)
21+
except SupabaseException as e:
22+
pass
23+
24+
25+
def test_function_initialization() -> None:
26+
url = os.environ.get("SUPABASE_TEST_URL")
27+
key = os.environ.get("SUPABASE_TEST_KEY")
28+
29+
client = create_client(url, key)
30+
assert client.functions
31+
32+
33+
def test_postgrest_schema() -> None:
34+
url = os.environ.get("SUPABASE_TEST_URL")
35+
key = os.environ.get("SUPABASE_TEST_KEY")
36+
37+
client = create_client(url, key)
38+
assert client.postgrest
39+
assert client.postgrest.schema("new_schema")
40+
41+
42+
def test_rpc_client() -> None:
43+
url = os.environ.get("SUPABASE_TEST_URL")
44+
key = os.environ.get("SUPABASE_TEST_KEY")
45+
46+
client = create_client(url, key)
47+
assert client.rpc("test_fn")
2048

2149

2250
def test_uses_key_as_authorization_header_by_default() -> None:

tests/test_client_options.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
11
from gotrue import SyncMemoryStorage
22

3-
from supabase import ClientOptions
3+
from supabase import AClientOptions, ClientOptions
44

55

66
class TestClientOptions:
7+
8+
def test_replace_returns_updated_aclient_options(self):
9+
storage = SyncMemoryStorage()
10+
storage.set_item("key", "value")
11+
options = AClientOptions(
12+
schema="schema",
13+
headers={"key": "value"},
14+
auto_refresh_token=False,
15+
persist_session=False,
16+
storage=storage,
17+
realtime={"key": "value"},
18+
)
19+
20+
actual = options.replace(schema="new schema")
21+
expected = AClientOptions(
22+
schema="new schema",
23+
headers={"key": "value"},
24+
auto_refresh_token=False,
25+
persist_session=False,
26+
storage=storage,
27+
realtime={"key": "value"},
28+
)
29+
30+
assert actual == expected
31+
732
def test_replace_returns_updated_options(self):
833
storage = SyncMemoryStorage()
934
storage.set_item("key", "value")
@@ -17,6 +42,7 @@ def test_replace_returns_updated_options(self):
1742
)
1843

1944
actual = options.replace(schema="new schema")
45+
assert actual
2046
expected = ClientOptions(
2147
schema="new schema",
2248
headers={"key": "value"},

0 commit comments

Comments
 (0)