Skip to content

Commit 6cf55b0

Browse files
committed
fix: added test
1 parent d27a37d commit 6cf55b0

File tree

1 file changed

+72
-9
lines changed

1 file changed

+72
-9
lines changed

tests/emailpassword/test_emaildelivery.py

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,32 @@
2121
from fastapi.requests import Request
2222
from fastapi.testclient import TestClient
2323
from pytest import fixture, mark
24+
2425
from supertokens_python import InputAppInfo, SupertokensConfig, init
2526
from supertokens_python.framework.fastapi import get_middleware
2627
from supertokens_python.ingredients.emaildelivery import EmailDeliveryInterface
2728
from supertokens_python.ingredients.emaildelivery.types import (
2829
EmailContent,
2930
EmailDeliveryConfig,
30-
SMTPSettingsFrom,
3131
SMTPServiceInterface,
3232
SMTPSettings,
33+
SMTPSettingsFrom,
3334
)
34-
from supertokens_python.recipe import emailpassword, session, emailverification
35-
from supertokens_python.recipe.emailpassword import (
36-
InputResetPasswordUsingTokenFeature,
37-
)
35+
from supertokens_python.recipe import emailpassword, emailverification, session
36+
from supertokens_python.recipe.emailpassword import InputResetPasswordUsingTokenFeature
3837
from supertokens_python.recipe.emailpassword.emaildelivery.services import SMTPService
39-
from supertokens_python.recipe.emailverification.emaildelivery.services import (
40-
SMTPService as EVSMTPService,
41-
)
4238
from supertokens_python.recipe.emailpassword.types import (
4339
EmailTemplateVars,
4440
PasswordResetEmailTemplateVars,
4541
)
4642
from supertokens_python.recipe.emailpassword.types import User as EPUser
43+
from supertokens_python.recipe.emailverification.emaildelivery.services import (
44+
SMTPService as EVSMTPService,
45+
)
46+
from supertokens_python.recipe.emailverification.types import User as EVUser
4747
from supertokens_python.recipe.emailverification.types import (
4848
VerificationEmailTemplateVars,
4949
)
50-
from supertokens_python.recipe.emailverification.types import User as EVUser
5150
from supertokens_python.recipe.session import SessionRecipe
5251
from supertokens_python.recipe.session.recipe_implementation import (
5352
RecipeImplementation as SessionRecipeImplementation,
@@ -299,6 +298,70 @@ def api_side_effect(request: httpx.Request):
299298
assert password_reset_url != ""
300299

301300

301+
@mark.asyncio
302+
async def test_reset_password_custom_override_with_send_email_override(
303+
driver_config_client: TestClient,
304+
):
305+
"Reset password: test custom override with send email override"
306+
email = ""
307+
password_reset_url = ""
308+
309+
def email_delivery_override(oi: EmailDeliveryInterface[EmailTemplateVars]):
310+
oi_send_email = oi.send_email
311+
312+
async def send_email(
313+
template_vars: EmailTemplateVars, user_context: Dict[str, Any]
314+
):
315+
template_vars.user.email = "[email protected]"
316+
assert isinstance(template_vars, PasswordResetEmailTemplateVars)
317+
await oi_send_email(template_vars, user_context)
318+
319+
oi.send_email = send_email
320+
return oi
321+
322+
async def custom_create_and_send_custom_email(
323+
user: EPUser, password_reset_link: str, _: Dict[str, Any]
324+
):
325+
nonlocal email, password_reset_url
326+
email = user.email
327+
password_reset_url = password_reset_link
328+
329+
init(
330+
supertokens_config=SupertokensConfig("http://localhost:3567"),
331+
app_info=InputAppInfo(
332+
app_name="ST",
333+
api_domain="http://api.supertokens.io",
334+
website_domain="http://supertokens.io",
335+
api_base_path="/auth",
336+
),
337+
framework="fastapi",
338+
recipe_list=[
339+
emailpassword.init(
340+
email_delivery=EmailDeliveryConfig(
341+
service=None,
342+
override=email_delivery_override,
343+
),
344+
reset_password_using_token_feature=emailpassword.InputResetPasswordUsingTokenFeature(
345+
create_and_send_custom_email=custom_create_and_send_custom_email
346+
),
347+
),
348+
session.init(),
349+
],
350+
)
351+
start_st()
352+
353+
sign_up_request(driver_config_client, "[email protected]", "1234abcd")
354+
355+
resp = reset_password_request(
356+
driver_config_client, "[email protected]", use_server=True
357+
)
358+
359+
assert resp.status_code == 200
360+
361+
assert email == "[email protected]"
362+
assert password_reset_url != ""
363+
364+
302365
@mark.asyncio
303366
async def test_reset_password_smtp_service(driver_config_client: TestClient):
304367
"Reset password: test smtp service"

0 commit comments

Comments
 (0)