Skip to content

Commit 3d487b7

Browse files
test: adds test for sendResetPasswordEmail
1 parent a8c9276 commit 3d487b7

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

tests/emailpassword/test_passwordreset.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ async def test_that_generated_password_link_is_correct(
130130
reset_url = None
131131
token_info: Union[None, str] = None
132132
rid_info: Union[None, str] = None
133+
tenant_info: Union[None, str] = None
133134

134135
class CustomEmailService(
135136
emailpassword.EmailDeliveryInterface[emailpassword.EmailTemplateVars]
@@ -139,11 +140,12 @@ async def send_email(
139140
template_vars: emailpassword.EmailTemplateVars,
140141
user_context: Dict[str, Any],
141142
) -> None:
142-
nonlocal reset_url, token_info, rid_info
143+
nonlocal reset_url, token_info, rid_info, tenant_info
143144
password_reset_url_with_token = template_vars.password_reset_link
144145
reset_url = password_reset_url_with_token.split("?")[0]
145146
token_info = password_reset_url_with_token.split("?")[1].split("&")[0]
146147
rid_info = password_reset_url_with_token.split("?")[1].split("&")[1]
148+
tenant_info = password_reset_url_with_token.split("?")[1].split("&")[2]
147149

148150
init(
149151
supertokens_config=SupertokensConfig("http://localhost:3567"),
@@ -178,6 +180,7 @@ async def send_email(
178180
assert reset_url == "http://supertokens.io/auth/reset-password"
179181
assert token_info is not None and "token=" in token_info # type: ignore pylint: disable=unsupported-membership-test
180182
assert rid_info is not None and "rid=emailpassword" in rid_info # type: ignore pylint: disable=unsupported-membership-test
183+
assert tenant_info is not None and "tenantId=" in tenant_info # type: ignore pylint: disable=unsupported-membership-test
181184

182185

183186
@mark.asyncio
@@ -264,6 +267,14 @@ async def send_email(
264267
token_info = (
265268
password_reset_url_with_token.split("?")[1].split("&")[0].split("=")[1]
266269
)
270+
assert (
271+
password_reset_url_with_token.split("?")[1].split("&")[2].split("=")[1]
272+
== "public"
273+
)
274+
assert (
275+
password_reset_url_with_token.split("?")[1].split("&")[1].split("=")[1]
276+
== "emailpassword"
277+
)
267278

268279
init(
269280
supertokens_config=SupertokensConfig("http://localhost:3567"),

tests/thirdpartyemailpassword/test_email_delivery.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@
4141
)
4242
from supertokens_python.recipe.thirdpartyemailpassword.asyncio import (
4343
create_reset_password_link,
44+
send_reset_password_email,
4445
)
4546
from supertokens_python.recipe.thirdpartyemailpassword.interfaces import (
4647
CreateResetPasswordLinkUnknownUserIdError,
48+
SendResetPasswordEmailEmailOkResult,
4749
)
4850
from supertokens_python.recipe.emailverification.emaildelivery.services import (
4951
SMTPService as EVSMTPService,
@@ -1086,3 +1088,41 @@ async def test_create_reset_password_link(
10861088
with raises(GeneralError) as err:
10871089
await create_reset_password_link("invalidTenantId", user_info["id"])
10881090
assert "status code: 400" in str(err.value)
1091+
1092+
1093+
@mark.asyncio
1094+
async def test_send_reset_password_email(
1095+
driver_config_client: TestClient,
1096+
):
1097+
init(
1098+
supertokens_config=SupertokensConfig("http://localhost:3567"),
1099+
app_info=InputAppInfo(
1100+
app_name="SuperTokens Demo",
1101+
api_domain="http://api.supertokens.io",
1102+
website_domain="http://supertokens.io",
1103+
api_base_path="/auth",
1104+
),
1105+
framework="fastapi",
1106+
recipe_list=[
1107+
thirdpartyemailpassword.init(),
1108+
session.init(get_token_transfer_method=lambda _, __, ___: "cookie"),
1109+
],
1110+
)
1111+
start_st()
1112+
1113+
response_1 = sign_up_request(
1114+
driver_config_client, "[email protected]", "validpass123"
1115+
)
1116+
assert response_1.status_code == 200
1117+
dict_response = json.loads(response_1.text)
1118+
user_info = dict_response["user"]
1119+
assert dict_response["status"] == "OK"
1120+
resp = await send_reset_password_email("public", user_info["id"])
1121+
assert isinstance(resp, SendResetPasswordEmailEmailOkResult)
1122+
1123+
link = await create_reset_password_link("public", "invalidUserId")
1124+
assert isinstance(link, CreateResetPasswordLinkUnknownUserIdError)
1125+
1126+
with raises(GeneralError) as err:
1127+
await create_reset_password_link("invalidTenantId", user_info["id"])
1128+
assert "status code: 400" in str(err.value)

0 commit comments

Comments
 (0)