-
-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy pathtest_client.py
86 lines (57 loc) · 2.63 KB
/
test_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import os
from unittest.mock import AsyncMock, MagicMock
from supabase import AClient, ASupabaseException, create_async_client
async def test_incorrect_values_dont_instantiate_client() -> None:
"""Ensure we can't instantiate client with invalid values."""
try:
client: AClient = create_async_client(None, None)
except ASupabaseException:
pass
async def test_supabase_exception() -> None:
try:
raise ASupabaseException("err")
except ASupabaseException:
pass
async def test_postgrest_client() -> None:
url = os.environ.get("SUPABASE_TEST_URL")
key = os.environ.get("SUPABASE_TEST_KEY")
client = await create_async_client(url, key)
assert client.table("sample")
async def test_rpc_client() -> None:
url = os.environ.get("SUPABASE_TEST_URL")
key = os.environ.get("SUPABASE_TEST_KEY")
client = await create_async_client(url, key)
assert client.rpc("test_fn")
async def test_function_initialization() -> None:
url = os.environ.get("SUPABASE_TEST_URL")
key = os.environ.get("SUPABASE_TEST_KEY")
client = await create_async_client(url, key)
assert client.functions
async def test_schema_update() -> None:
url = os.environ.get("SUPABASE_TEST_URL")
key = os.environ.get("SUPABASE_TEST_KEY")
client = await create_async_client(url, key)
assert client.postgrest
assert client.schema("new_schema")
async def test_updates_the_authorization_header_on_auth_events() -> None:
url = os.environ.get("SUPABASE_TEST_URL")
key = os.environ.get("SUPABASE_TEST_KEY")
client = await create_async_client(url, key)
assert client.options.headers.get("apiKey") == key
assert client.options.headers.get("Authorization") == f"Bearer {key}"
mock_session = MagicMock(access_token="secretuserjwt")
realtime_mock = AsyncMock()
client.realtime = realtime_mock
client._listen_to_auth_events("SIGNED_IN", mock_session)
updated_authorization = f"Bearer {mock_session.access_token}"
assert client.options.headers.get("apiKey") == key
assert client.options.headers.get("Authorization") == updated_authorization
assert client.postgrest.session.headers.get("apiKey") == key
assert (
client.postgrest.session.headers.get("Authorization") == updated_authorization
)
assert client.auth._headers.get("apiKey") == key
assert client.auth._headers.get("Authorization") == updated_authorization
assert client.storage.session.headers.get("apiKey") == key
assert client.storage.session.headers.get("Authorization") == updated_authorization
realtime_mock.set_auth.assert_called_once_with(mock_session.access_token)