1
- import os
1
+ from __future__ import annotations
2
+
2
3
import random
3
4
import string
4
- from typing import Any , Dict
5
+ from typing import TYPE_CHECKING , Any , Dict
5
6
6
7
import pytest
7
8
9
+ if TYPE_CHECKING :
10
+ from supabase_py import Client , create_client
11
+
8
12
9
13
def _random_string (length : int = 10 ) -> str :
10
14
"""Generate random string."""
11
15
return "" .join (random .choices (string .ascii_uppercase + string .digits , k = length ))
12
16
13
17
14
- def _assert_authenticated_user (data : Dict [str , Any ]):
18
+ def _assert_authenticated_user (data : Dict [str , Any ]) -> None :
15
19
"""Raise assertion error if user is not logged in correctly."""
16
20
assert "access_token" in data
17
21
assert "refresh_token" in data
@@ -27,20 +31,15 @@ def _assert_authenticated_user(data: Dict[str, Any]):
27
31
)
28
32
@pytest .mark .parametrize ("url" , ["" , None , "valeefgpoqwjgpj" , 139 , - 1 , {}, []])
29
33
@pytest .mark .parametrize ("key" , ["" , None , "valeefgpoqwjgpj" , 139 , - 1 , {}, []])
30
- def test_incorrect_values_dont_instanciate_client (url : Any , key : Any ):
34
+ def test_incorrect_values_dont_instanciate_client (url : Any , key : Any ) -> None :
31
35
"""Ensure we can't instanciate client with nonesense values."""
32
- from supabase_py import create_client , Client
36
+ from supabase_py import Client , create_client
33
37
34
38
_ : Client = create_client (url , key )
35
39
36
40
37
- def test_client_auth () :
41
+ def test_client_auth (supabase : Client ) -> None :
38
42
"""Ensure we can create an auth user, and login with it."""
39
- from supabase_py import create_client , Client
40
-
41
- url : str = os .environ .get ("SUPABASE_TEST_URL" )
42
- key : str = os .environ .get ("SUPABASE_TEST_KEY" )
43
- supabase : Client = create_client (url , key )
44
43
# Create a random user login email and password.
45
44
random_email : str = f"{ _random_string (10 )} @supamail.com"
46
45
random_password : str = _random_string (20 )
@@ -56,27 +55,17 @@ def test_client_auth():
56
55
_assert_authenticated_user (user )
57
56
58
57
59
- def test_client_select () :
58
+ def test_client_select (supabase : Client ) -> None :
60
59
"""Ensure we can select data from a table."""
61
- from supabase_py import create_client , Client
62
-
63
- url : str = os .environ .get ("SUPABASE_TEST_URL" )
64
- key : str = os .environ .get ("SUPABASE_TEST_KEY" )
65
- supabase : Client = create_client (url , key )
66
60
# TODO(fedden): Add this set back in (and expand on it) when postgrest and
67
61
# realtime libs are working.
68
62
data = supabase .table ("countries" ).select ("*" ).execute ()
69
63
# Assert we pulled real data.
70
64
assert len (data .get ("data" , [])) > 0
71
65
72
66
73
- def test_client_insert () :
67
+ def test_client_insert (supabase : Client ) -> None :
74
68
"""Ensure we can select data from a table."""
75
- from supabase_py import create_client , Client
76
-
77
- url : str = os .environ .get ("SUPABASE_TEST_URL" )
78
- key : str = os .environ .get ("SUPABASE_TEST_KEY" )
79
- supabase : Client = create_client (url , key )
80
69
data = supabase .table ("countries" ).select ("*" ).execute ()
81
70
# Assert we pulled real data.
82
71
previous_length : int = len (data .get ("data" , []))
0 commit comments