Skip to content

Commit e306249

Browse files
authored
Merge branch 'develop' into j0_add_storage_bucket
2 parents c8c3176 + 873b85b commit e306249

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

tests/conftest.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from __future__ import annotations
2+
3+
import os
4+
5+
import pytest
6+
7+
from supabase_py import Client, create_client
8+
9+
10+
@pytest.fixture(scope="session")
11+
def supabase() -> Client:
12+
url: str = os.environ.get("SUPABASE_TEST_URL")
13+
key: str = os.environ.get("SUPABASE_TEST_KEY")
14+
supabase: Client = create_client(url, key)
15+
return supabase

tests/test_client.py

+12-23
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import os
1+
from __future__ import annotations
2+
23
import random
34
import string
4-
from typing import Any, Dict
5+
from typing import TYPE_CHECKING, Any, Dict
56

67
import pytest
78

9+
if TYPE_CHECKING:
10+
from supabase_py import Client, create_client
11+
812

913
def _random_string(length: int = 10) -> str:
1014
"""Generate random string."""
1115
return "".join(random.choices(string.ascii_uppercase + string.digits, k=length))
1216

1317

14-
def _assert_authenticated_user(data: Dict[str, Any]):
18+
def _assert_authenticated_user(data: Dict[str, Any]) -> None:
1519
"""Raise assertion error if user is not logged in correctly."""
1620
assert "access_token" in data
1721
assert "refresh_token" in data
@@ -25,20 +29,15 @@ def _assert_authenticated_user(data: Dict[str, Any]):
2529
@pytest.mark.xfail(reason="None of these values should be able to instanciate a client object")
2630
@pytest.mark.parametrize("url", ["", None, "valeefgpoqwjgpj", 139, -1, {}, []])
2731
@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:
2933
"""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
3135

3236
_: Client = create_client(url, key)
3337

3438

35-
def test_client_auth():
39+
def test_client_auth(supabase: Client) -> None:
3640
"""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)
4241
# Create a random user login email and password.
4342
random_email: str = f"{_random_string(10)}@supamail.com"
4443
random_password: str = _random_string(20)
@@ -54,27 +53,17 @@ def test_client_auth():
5453
_assert_authenticated_user(user)
5554

5655

57-
def test_client_select():
56+
def test_client_select(supabase: Client) -> None:
5857
"""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)
6458
# TODO(fedden): Add this set back in (and expand on it) when postgrest and
6559
# realtime libs are working.
6660
data = supabase.table("countries").select("*").execute()
6761
# Assert we pulled real data.
6862
assert len(data.get("data", [])) > 0
6963

7064

71-
def test_client_insert():
65+
def test_client_insert(supabase: Client) -> None:
7266
"""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)
7867
data = supabase.table("countries").select("*").execute()
7968
# Assert we pulled real data.
8069
previous_length: int = len(data.get("data", []))

tests/test_dummy.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import pytest
22

3-
import sys
4-
5-
print(sys.path)
63

74
import supabase_py
85

@@ -13,10 +10,12 @@
1310
"""
1411

1512

16-
def test_dummy():
13+
14+
def test_dummy() -> None:
1715
# Test auth component
1816
assert True == True
1917

2018

21-
def test_client_initialziation():
19+
20+
def test_client_initialziation() -> None:
2221
client = supabase_py.Client("http://testwebsite.com", "atestapi")

0 commit comments

Comments
 (0)