Skip to content

Commit

Permalink
test: adds test for create_reset_password_link
Browse files Browse the repository at this point in the history
  • Loading branch information
IamMayankThakur committed Nov 15, 2023
1 parent d5ebe65 commit 5fc6211
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/emailpassword/test_passwordreset.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import asyncio
import json
from typing import Any, Dict, Union
from urllib.parse import urlparse

from fastapi import FastAPI
from fastapi.requests import Request
Expand All @@ -22,6 +23,7 @@
from supertokens_python import InputAppInfo, SupertokensConfig, init
from supertokens_python.framework.fastapi import get_middleware
from supertokens_python.recipe import emailpassword, session
from supertokens_python.recipe.emailpassword.asyncio import create_reset_password_link
from supertokens_python.recipe.session import SessionContainer
from supertokens_python.recipe.session.asyncio import (
create_new_session,
Expand Down Expand Up @@ -339,3 +341,38 @@ async def send_email(
assert dict_response["status"] == "OK"
assert dict_response["user"]["id"] == user_info["id"]
assert dict_response["user"]["email"] == user_info["email"]


@mark.asyncio
async def test_create_reset_password_link(
driver_config_client: TestClient,
):
init(
supertokens_config=SupertokensConfig("http://localhost:3567"),
app_info=InputAppInfo(
app_name="SuperTokens Demo",
api_domain="http://api.supertokens.io",
website_domain="http://supertokens.io",
api_base_path="/auth",
),
framework="fastapi",
recipe_list=[
emailpassword.init(),
session.init(get_token_transfer_method=lambda _, __, ___: "cookie"),
],
)
start_st()

response_1 = sign_up_request(
driver_config_client, "[email protected]", "validpass123"
)
assert response_1.status_code == 200
dict_response = json.loads(response_1.text)
user_info = dict_response["user"]
assert dict_response["status"] == "OK"
link = await create_reset_password_link("public", user_info["id"])
url = urlparse(link.link) # type: ignore
queries = url.query.strip("&").split("&")
assert url.path == "/auth/reset-password"
assert "tenantId=public" in queries
assert "rid=emailpassword" in queries
39 changes: 39 additions & 0 deletions tests/thirdpartyemailpassword/test_email_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from fastapi.requests import Request
from fastapi.testclient import TestClient
from pytest import fixture, mark
from urllib.parse import urlparse

from supertokens_python import InputAppInfo, SupertokensConfig, init
from supertokens_python.framework.fastapi import get_middleware
Expand All @@ -37,6 +38,9 @@
session,
thirdpartyemailpassword,
)
from supertokens_python.recipe.thirdpartyemailpassword.asyncio import (
create_reset_password_link,
)
from supertokens_python.recipe.emailverification.emaildelivery.services import (
SMTPService as EVSMTPService,
)
Expand Down Expand Up @@ -1036,3 +1040,38 @@ async def send_email(

assert email == "[email protected]"
assert email_verify_url != ""


@mark.asyncio
async def test_create_reset_password_link(
driver_config_client: TestClient,
):
init(
supertokens_config=SupertokensConfig("http://localhost:3567"),
app_info=InputAppInfo(
app_name="SuperTokens Demo",
api_domain="http://api.supertokens.io",
website_domain="http://supertokens.io",
api_base_path="/auth",
),
framework="fastapi",
recipe_list=[
thirdpartyemailpassword.init(),
session.init(get_token_transfer_method=lambda _, __, ___: "cookie"),
],
)
start_st()

response_1 = sign_up_request(
driver_config_client, "[email protected]", "validpass123"
)
assert response_1.status_code == 200
dict_response = json.loads(response_1.text)
user_info = dict_response["user"]
assert dict_response["status"] == "OK"
link = await create_reset_password_link("public", user_info["id"])
url = urlparse(link.link) # type: ignore
queries = url.query.strip("&").split("&")
assert url.path == "/auth/reset-password"
assert "tenantId=public" in queries
assert "rid=thirdpartyemailpassword" in queries

0 comments on commit 5fc6211

Please sign in to comment.