Skip to content

Commit

Permalink
chore: implement clients and utils for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
leynier committed Oct 29, 2022
1 parent 20638fe commit 6fbd3de
Show file tree
Hide file tree
Showing 20 changed files with 223 additions and 1,917 deletions.
4 changes: 3 additions & 1 deletion gotrue/constants.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

from typing import Dict

from . import __version__

GOTRUE_URL = "http://localhost:9999"
DEFAULT_HEADERS = {
DEFAULT_HEADERS: Dict[str, str] = {
"X-Client-Info": f"gotrue-py/{__version__}",
}
EXPIRY_MARGIN = 10 # seconds
Expand Down
105 changes: 105 additions & 0 deletions tests/_async/clients.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
from gotrue import AsyncGoTrueAdminAPI, AsyncGoTrueClient
from jwt import encode

SIGNUP_ENABLED_AUTO_CONFIRM_OFF_PORT = 9999
SIGNUP_ENABLED_AUTO_CONFIRM_ON_PORT = 9998
SIGNUP_DISABLED_AUTO_CONFIRM_OFF_PORT = 9997

GOTRUE_URL_SIGNUP_ENABLED_AUTO_CONFIRM_OFF = (
f"http://localhost:{SIGNUP_ENABLED_AUTO_CONFIRM_OFF_PORT}"
)
GOTRUE_URL_SIGNUP_ENABLED_AUTO_CONFIRM_ON = (
f"http://localhost:{SIGNUP_ENABLED_AUTO_CONFIRM_ON_PORT}"
)
GOTRUE_URL_SIGNUP_DISABLED_AUTO_CONFIRM_OFF = (
f"http://localhost:{SIGNUP_DISABLED_AUTO_CONFIRM_OFF_PORT}"
)

GOTRUE_JWT_SECRET = "37c304f8-51aa-419a-a1af-06154e63707a"

AUTH_ADMIN_JWT = encode(
{
"sub": "1234567890",
"role": "supabase_admin",
},
GOTRUE_JWT_SECRET,
)

auth_client = AsyncGoTrueClient(
url=GOTRUE_URL_SIGNUP_ENABLED_AUTO_CONFIRM_ON,
auto_refresh_token=False,
persist_session=True,
)

auth_client_with_session = AsyncGoTrueClient(
url=GOTRUE_URL_SIGNUP_ENABLED_AUTO_CONFIRM_ON,
auto_refresh_token=False,
persist_session=False,
)

auth_subscription_client = AsyncGoTrueClient(
url=GOTRUE_URL_SIGNUP_ENABLED_AUTO_CONFIRM_ON,
auto_refresh_token=False,
persist_session=True,
)


client_api_auto_confirm_enabled_client = AsyncGoTrueClient(
url=GOTRUE_URL_SIGNUP_ENABLED_AUTO_CONFIRM_ON,
auto_refresh_token=False,
persist_session=True,
)

client_api_auto_confirm_off_signups_enabled_client = AsyncGoTrueClient(
url=GOTRUE_URL_SIGNUP_ENABLED_AUTO_CONFIRM_OFF,
auto_refresh_token=False,
persist_session=True,
)

client_api_auto_confirm_disabled_client = AsyncGoTrueClient(
url=GOTRUE_URL_SIGNUP_DISABLED_AUTO_CONFIRM_OFF,
auto_refresh_token=False,
persist_session=True,
)

auth_admin_api_auto_confirm_enabled_client = AsyncGoTrueAdminAPI(
url=GOTRUE_URL_SIGNUP_ENABLED_AUTO_CONFIRM_ON,
headers={
"Authorization": f"Bearer {AUTH_ADMIN_JWT}",
},
)

auth_admin_api_auto_confirm_disabled_client = AsyncGoTrueAdminAPI(
url=GOTRUE_URL_SIGNUP_ENABLED_AUTO_CONFIRM_OFF,
headers={
"Authorization": f"Bearer {AUTH_ADMIN_JWT}",
},
)

SERVICE_ROLE_JWT = encode(
{
"role": "service_role",
},
GOTRUE_JWT_SECRET,
)

service_role_api_client = AsyncGoTrueAdminAPI(
url=GOTRUE_URL_SIGNUP_ENABLED_AUTO_CONFIRM_ON,
headers={
"Authorization": f"Bearer {SERVICE_ROLE_JWT}",
},
)

service_role_api_client_with_sms = AsyncGoTrueAdminAPI(
url=GOTRUE_URL_SIGNUP_ENABLED_AUTO_CONFIRM_OFF,
headers={
"Authorization": f"Bearer {SERVICE_ROLE_JWT}",
},
)

service_role_api_client_no_sms = AsyncGoTrueAdminAPI(
url=GOTRUE_URL_SIGNUP_DISABLED_AUTO_CONFIRM_OFF,
headers={
"Authorization": f"Bearer {SERVICE_ROLE_JWT}",
},
)
1 change: 1 addition & 0 deletions tests/_async/old/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.py
98 changes: 0 additions & 98 deletions tests/_async/test_api_with_auto_confirm_disabled.py

This file was deleted.

62 changes: 0 additions & 62 deletions tests/_async/test_api_with_auto_confirm_enabled.py

This file was deleted.

0 comments on commit 6fbd3de

Please sign in to comment.