Skip to content

Commit

Permalink
chore: add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
leynier committed Oct 19, 2021
1 parent b758dba commit 068fe0d
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 97 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ run_infra:
docker-compose down &&\
docker-compose up -d

build_and_tests: build_sync tests
build_run_tests: build_sync run_infra tests
echo "Done"
4 changes: 4 additions & 0 deletions tests/_async/test_client_with_auto_confirm_enabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async def test_sign_up(client: AsyncGoTrueClient):
provider = response.user.app_metadata.get("provider")
assert provider
assert isinstance(provider, list)
print(f"Provider: {provider}")
assert "email" in provider
assert response.user.user_metadata
assert response.user.user_metadata.get("status") == "alpha"
Expand Down Expand Up @@ -156,6 +157,7 @@ async def test_sign_in(client: AsyncGoTrueClient):
provider = response.user.app_metadata.get("provider")
assert provider
assert isinstance(provider, list)
print(f"Provider: {provider}")
assert "email" in provider
except Exception as e:
assert False, str(e)
Expand Down Expand Up @@ -189,6 +191,7 @@ async def test_sign_in_with_refresh_token(client_with_session: AsyncGoTrueClient
provider = response2.user.app_metadata.get("provider")
assert provider
assert isinstance(provider, list)
print(f"Provider: {provider}")
assert "email" in provider
except Exception as e:
assert False, str(e)
Expand All @@ -211,6 +214,7 @@ async def test_get_user(client: AsyncGoTrueClient):
provider = response.app_metadata.get("provider")
assert provider
assert isinstance(provider, list)
print(f"Provider: {provider}")
assert "email" in provider
except Exception as e:
assert False, str(e)
Expand Down
4 changes: 4 additions & 0 deletions tests/_sync/test_client_with_auto_confirm_enabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def test_sign_up(client: SyncGoTrueClient):
provider = response.user.app_metadata.get("provider")
assert provider
assert isinstance(provider, list)
print(f"Provider: {provider}")
assert "email" in provider
assert response.user.user_metadata
assert response.user.user_metadata.get("status") == "alpha"
Expand Down Expand Up @@ -154,6 +155,7 @@ def test_sign_in(client: SyncGoTrueClient):
provider = response.user.app_metadata.get("provider")
assert provider
assert isinstance(provider, list)
print(f"Provider: {provider}")
assert "email" in provider
except Exception as e:
assert False, str(e)
Expand Down Expand Up @@ -185,6 +187,7 @@ def test_sign_in_with_refresh_token(client_with_session: SyncGoTrueClient):
provider = response2.user.app_metadata.get("provider")
assert provider
assert isinstance(provider, list)
print(f"Provider: {provider}")
assert "email" in provider
except Exception as e:
assert False, str(e)
Expand All @@ -207,6 +210,7 @@ def test_get_user(client: SyncGoTrueClient):
provider = response.app_metadata.get("provider")
assert provider
assert isinstance(provider, list)
print(f"Provider: {provider}")
assert "email" in provider
except Exception as e:
assert False, str(e)
Expand Down
197 changes: 101 additions & 96 deletions tests/test_gotrue.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# import os
# import random
# import string
# from typing import Any, Dict
# from typing import Optional

# import pytest

# from gotrue.client import Client
# from gotrue.lib.constants import GOTRUE_URL
# from gotrue import AsyncGoTrueClient
# from gotrue.constants import GOTRUE_URL
# from gotrue.types import ApiError, Session


# def _random_string(length: int = 10) -> str:
Expand All @@ -23,143 +23,148 @@
# return "{}-{}-{}".format(first, second, last)


# def _assert_authenticated_user(data: Dict[str, Any]):
# def _assert_authenticated_user(data: Session):
# """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"
# assert data.access_token
# assert data.refresh_token
# assert data.user
# assert data.user.id
# assert data.user.aud == "authenticated"


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

# supabase_url: str = os.environ.get("SUPABASE_TEST_URL")
# supabase_key: str = os.environ.get("SUPABASE_TEST_KEY")
# supabase_url = os.environ.get("SUPABASE_TEST_URL")
# supabase_key = os.environ.get("SUPABASE_TEST_KEY")
# if supabase_url and supabase_key:
# url: str = f"{supabase_url}/auth/v1"
# return Client(
# return AsyncGoTrueClient(
# url=url,
# headers={"apiKey": supabase_key, "Authorization": f"Bearer {supabase_key}"},
# )
# else:
# return Client(
# return AsyncGoTrueClient(
# url=GOTRUE_URL,
# headers={
# "Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwicm9sZSI6InN1cGFiYXNlX2FkbWluIiwiaWF0IjoxNTE2MjM5MDIyfQ.0sOtTSTfPv5oPZxsjvBO249FI4S4p0ymHoIZ6H6z9Y8"
# "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwicm9sZSI6InN1cGFiYXNlX2FkbWluIiwiaWF0IjoxNTE2MjM5MDIyfQ.0sOtTSTfPv5oPZxsjvBO249FI4S4p0ymHoIZ6H6z9Y8"
# },
# )


# def test_user_auth_flow(client: Client):
# @pytest.mark.asyncio
# async def test_user_auth_flow(client: AsyncGoTrueClient):
# """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
# random_email = f"{_random_string(10)}@supamail.com"
# random_password = _random_string(20)
# response = await client.sign_up(email=random_email, password=random_password)
# assert isinstance(response, Session)
# _assert_authenticated_user(response)
# assert client.current_user
# assert client.current_session
# # 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_get_user_and_session_methods(client: Client):
# await client.sign_out()
# assert not client.current_user
# assert not client.current_session
# response = await client.sign_in(email=random_email, password=random_password)
# assert isinstance(response, Session)
# _assert_authenticated_user(response)
# assert client.current_user
# assert client.current_session


# @pytest.mark.asyncio
# async def test_get_user_and_session_methods(client: AsyncGoTrueClient):
# """Ensure we can get the current user and session via the getters."""
# # Create a random user.
# 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)
# random_email = f"{_random_string(10)}@supamail.com"
# random_password = _random_string(20)
# response = await client.sign_up(email=random_email, password=random_password)
# assert isinstance(response, Session)
# _assert_authenticated_user(response)
# # Test that we get not null users and sessions.
# assert client.user() is not None
# assert client.session() is not None
# assert client.user()
# assert client.session()


# def test_refresh_session(client: Client):
# @pytest.mark.asyncio
# async def test_refresh_session(client: AsyncGoTrueClient):
# """Test user can signup/in and refresh their session."""
# # Create a random user.
# 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
# random_email = f"{_random_string(10)}@supamail.com"
# random_password = _random_string(20)
# response = await client.sign_up(email=random_email, password=random_password)
# assert isinstance(response, Session)
# _assert_authenticated_user(response)
# assert client.current_user
# assert client.current_session
# # Refresh users session
# data = client.refresh_session()
# assert data["status_code"] == 200
# assert client.current_user is not None
# assert client.current_session is not None
# response = await client.refresh_session()
# assert client.current_user
# assert client.current_session


# def test_send_magic_link(client: Client):
# @pytest.mark.asyncio
# async def test_send_magic_link(client: AsyncGoTrueClient):
# """Tests client can send a magic link to email address."""
# random_email: str = f"{_random_string(10)}@supamail.com"
# random_email = 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
# await client.sign_in(email=random_email)


# def test_set_auth(client: Client):
# @pytest.mark.asyncio
# async def test_set_auth(client: AsyncGoTrueClient):
# """Test client can override the access_token"""
# 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)

# random_email = f"{_random_string(10)}@supamail.com"
# random_password = _random_string(20)
# response = await client.sign_up(email=random_email, password=random_password)
# assert isinstance(response, Session)
# _assert_authenticated_user(response)
# mock_access_token = _random_string(20)
# client.set_auth(mock_access_token)
# await client.set_auth(access_token=mock_access_token)
# new_session = client.session()
# assert new_session["access_token"] == mock_access_token
# assert new_session
# assert new_session.access_token == mock_access_token


# def test_sign_up_phone_password(client: Client):
# @pytest.mark.asyncio
# async def test_sign_up_phone_password(client: AsyncGoTrueClient):
# """Test client can sign up with phone and password"""
# random_phone: str = _random_phone_number()
# random_password: str = _random_string(20)
# data = client.sign_up(phone=random_phone, password=random_password)
# _assert_authenticated_user(data)
# assert client.current_user is not None
# assert client.current_session is not None

# assert "id" in data and isinstance(data.get("id"), str)
# assert "created_at" in data and isinstance(data.get("created_at"), str)
# assert "email" in data and data.get("email") == ""
# assert "confirmation_sent_at" in data and isinstance(
# data.get("confirmation_sent_at"), str
# random_phone = _random_phone_number()
# random_password = _random_string(20)
# response = client.sign_up(phone=random_phone, password=random_password)
# assert isinstance(response, Session)
# _assert_authenticated_user(response)
# assert client.current_user
# assert client.current_session
# assert "id" in response and isinstance(response.get("id"), str)
# assert "created_at" in response and isinstance(response.get("created_at"), str)
# assert "email" in response and response.get("email") == ""
# assert "confirmation_sent_at" in response and isinstance(
# response.get("confirmation_sent_at"), str
# )
# assert "phone" in data and data.get("phone") == random_phone
# assert "aud" in data and isinstance(data.get("aud"), str)
# assert "updated_at" in data and isinstance(data.get("updated_at"), str)
# assert "app_metadata" in data and isinstance(data.get("app_metadata"), dict)
# assert "phone" in response and response.get("phone") == random_phone
# assert "aud" in response and isinstance(response.get("aud"), str)
# assert "updated_at" in response and isinstance(response.get("updated_at"), str)
# assert "app_metadata" in response and isinstance(response.get("app_metadata"), dict)
# assert (
# "provider" in data.get("app_metadata")
# and data["app_metadata"].get("provider") == "phone"
# "provider" in response.get("app_metadata")
# and response["app_metadata"].get("provider") == "phone"
# )
# assert "user_metadata" in data and isinstance(data.get("id"), dict)
# assert "user_metadata" in response and isinstance(response.get("id"), dict)
# assert (
# "status" in data.get("user_metadata")
# and data["user_metadata"].get("status") == "alpha"
# "status" in response.get("user_metadata")
# and response["user_metadata"].get("status") == "alpha"
# )


# def test_verify_mobile_otp(client: Client):
# @pytest.mark.asyncio
# async def test_verify_mobile_otp(client: AsyncGoTrueClient):
# """Test client can verify their mobile using OTP"""
# random_token: str = "123456"
# random_phone: str = _random_phone_number()
# data = client.verify_otp(phone=random_phone, token=random_token)

# assert "session" in data and data["session"] is None
# assert "user" in data and data["user"] is None
# assert "error" in data
# assert "message" in data["error"]
# assert "Otp has expired or is invalid" in data["error"]["message"]
# random_token = "123456"
# random_phone = _random_phone_number()
# try:
# await client.verify_otp(phone=random_phone, token=random_token)
# except ApiError as e:
# assert "Otp has expired or is invalid" in e.msg

0 comments on commit 068fe0d

Please sign in to comment.