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
@@ -25,20 +29,15 @@ def _assert_authenticated_user(data: Dict[str, Any]):
25
29
@pytest .mark .xfail (reason = "None of these values should be able to instanciate a client object" )
26
30
@pytest .mark .parametrize ("url" , ["" , None , "valeefgpoqwjgpj" , 139 , - 1 , {}, []])
27
31
@pytest .mark .parametrize ("key" , ["" , None , "valeefgpoqwjgpj" , 139 , - 1 , {}, []])
28
- def test_incorrect_values_dont_instanciate_client (url : Any , key : Any ):
32
+ def test_incorrect_values_dont_instanciate_client (url : Any , key : Any ) -> None :
29
33
"""Ensure we can't instanciate client with nonesense values."""
30
- from supabase_py import create_client , Client
34
+ from supabase_py import Client , create_client
31
35
32
36
_ : Client = create_client (url , key )
33
37
34
38
35
- def test_client_auth () :
39
+ def test_client_auth (supabase : Client ) -> None :
36
40
"""Ensure we can create an auth user, and login with it."""
37
- from supabase_py import create_client , Client
38
-
39
- url : str = os .environ .get ("SUPABASE_TEST_URL" )
40
- key : str = os .environ .get ("SUPABASE_TEST_KEY" )
41
- supabase : Client = create_client (url , key )
42
41
# Create a random user login email and password.
43
42
random_email : str = f"{ _random_string (10 )} @supamail.com"
44
43
random_password : str = _random_string (20 )
@@ -54,27 +53,17 @@ def test_client_auth():
54
53
_assert_authenticated_user (user )
55
54
56
55
57
- def test_client_select () :
56
+ def test_client_select (supabase : Client ) -> None :
58
57
"""Ensure we can select data from a table."""
59
- from supabase_py import create_client , Client
60
-
61
- url : str = os .environ .get ("SUPABASE_TEST_URL" )
62
- key : str = os .environ .get ("SUPABASE_TEST_KEY" )
63
- supabase : Client = create_client (url , key )
64
58
# TODO(fedden): Add this set back in (and expand on it) when postgrest and
65
59
# realtime libs are working.
66
60
data = supabase .table ("countries" ).select ("*" ).execute ()
67
61
# Assert we pulled real data.
68
62
assert len (data .get ("data" , [])) > 0
69
63
70
64
71
- def test_client_insert () :
65
+ def test_client_insert (supabase : Client ) -> None :
72
66
"""Ensure we can select data from a table."""
73
- from supabase_py import create_client , Client
74
-
75
- url : str = os .environ .get ("SUPABASE_TEST_URL" )
76
- key : str = os .environ .get ("SUPABASE_TEST_KEY" )
77
- supabase : Client = create_client (url , key )
78
67
data = supabase .table ("countries" ).select ("*" ).execute ()
79
68
# Assert we pulled real data.
80
69
previous_length : int = len (data .get ("data" , []))
0 commit comments