-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: adds test for create_reset_password_link
- Loading branch information
1 parent
d5ebe65
commit 5fc6211
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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, | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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, | ||
) | ||
|
@@ -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 |