Skip to content

Commit

Permalink
add for working tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fedden committed Feb 13, 2021
1 parent 8b3dc48 commit c970dfe
Showing 1 changed file with 50 additions and 22 deletions.
72 changes: 50 additions & 22 deletions tests/test_gotrue.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,68 @@
import pytest
import os
import random
import string
from typing import Any, Dict

import pytest

@pytest.fixture
def client():
from gotrue import client

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


def test_settings(client):
res = client.settings()
assert res.status_code == 200
def _assert_authenticated_user(data: Dict[str, Any]):
"""Raise assertion error if user is not logged in correctly."""
assert "access_token" in data
assert "refresh_token" in data
assert data.get("status_code") == 200
user = data.get("user")
assert user is not None
assert user.get("id") is not None
assert user.get("aud") == "authenticated"


def test_refresh_access_token():
pass
@pytest.fixture
def client():
from gotrue import Client

supabase_url: str = os.environ.get("SUPABASE_TEST_URL")
supabase_key: str = os.environ.get("SUPABASE_TEST_KEY")
url: str = f"{supabase_url}/auth/v1"
return Client(
url=url,
headers={"apiKey": supabase_key, "Authorization": f"Bearer {supabase_key}"},
)

@pytest.mark.incremental
class TestUserHandling:
def test_signup(client):
pass

def test_login(client):
pass
def test_refresh_access_token():
pass

def test_verify(client):
pass

def test_logout(self):
pass
def test_user_auth_flow(client):
"""Ensures user can sign up, log out and log into their account."""
random_email: str = f"{_random_string(10)}@supamail.com"
random_password: str = _random_string(20)
user = client.sign_up(email=random_email, password=random_password)
_assert_authenticated_user(user)
assert client.current_user is not None
assert client.current_session is not None
# Sign user out.
client.sign_out()
assert client.current_user is None
assert client.current_session is None
user = client.sign_in(email=random_email, password=random_password)
_assert_authenticated_user(user)
assert client.current_user is not None
assert client.current_session is not None


def test_send_magic_link(client):
res = client.send_magic_link("someemail@gmail.com")
assert res.status_code == 200 or res.status_code == 429
"""Tests client can send a magic link to email address."""
random_email: str = f"{_random_string(10)}@supamail.com"
# We send a magic link if no password is supplied with the email.
data = client.sign_in(email=random_email)
assert data.get("status_code") == 200


def test_recover_email(client):
Expand Down

0 comments on commit c970dfe

Please sign in to comment.