Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from __future__ import annotations

import os

import pytest

from supabase_py import Client, create_client


@pytest.fixture(scope="session")
def supabase() -> Client:
url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
return supabase
35 changes: 12 additions & 23 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import os
from __future__ import annotations

import random
import string
from typing import Any, Dict
from typing import TYPE_CHECKING, Any, Dict

import pytest

if TYPE_CHECKING:
from supabase_py import Client, create_client


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


def _assert_authenticated_user(data: Dict[str, Any]):
def _assert_authenticated_user(data: Dict[str, Any]) -> None:
"""Raise assertion error if user is not logged in correctly."""
assert "access_token" in data
assert "refresh_token" in data
Expand All @@ -27,20 +31,15 @@ def _assert_authenticated_user(data: Dict[str, Any]):
)
@pytest.mark.parametrize("url", ["", None, "valeefgpoqwjgpj", 139, -1, {}, []])
@pytest.mark.parametrize("key", ["", None, "valeefgpoqwjgpj", 139, -1, {}, []])
def test_incorrect_values_dont_instanciate_client(url: Any, key: Any):
def test_incorrect_values_dont_instanciate_client(url: Any, key: Any) -> None:
"""Ensure we can't instanciate client with nonesense values."""
from supabase_py import create_client, Client
from supabase_py import Client, create_client

_: Client = create_client(url, key)


def test_client_auth():
def test_client_auth(supabase: Client) -> None:
"""Ensure we can create an auth user, and login with it."""
from supabase_py import create_client, Client

url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
# Create a random user login email and password.
random_email: str = f"{_random_string(10)}@supamail.com"
random_password: str = _random_string(20)
Expand All @@ -56,27 +55,17 @@ def test_client_auth():
_assert_authenticated_user(user)


def test_client_select():
def test_client_select(supabase: Client) -> None:
"""Ensure we can select data from a table."""
from supabase_py import create_client, Client

url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
# TODO(fedden): Add this set back in (and expand on it) when postgrest and
# realtime libs are working.
data = supabase.table("countries").select("*").execute()
# Assert we pulled real data.
assert len(data.get("data", [])) > 0


def test_client_insert():
def test_client_insert(supabase: Client) -> None:
"""Ensure we can select data from a table."""
from supabase_py import create_client, Client

url: str = os.environ.get("SUPABASE_TEST_URL")
key: str = os.environ.get("SUPABASE_TEST_KEY")
supabase: Client = create_client(url, key)
data = supabase.table("countries").select("*").execute()
# Assert we pulled real data.
previous_length: int = len(data.get("data", []))
Expand Down
10 changes: 4 additions & 6 deletions tests/test_dummy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import pytest

import sys
print(sys.path)

import supabase_py

"""
Expand All @@ -11,10 +8,11 @@
client.auth.sign_up({"email": "[email protected]", "password": "apassword"})
"""

def test_dummy():

def test_dummy() -> None:
# Test auth component
assert True == True

def test_client_initialziation():
client = supabase_py.Client("http://testwebsite.com", "atestapi")

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