Skip to content

Commit a8c9276

Browse files
test: adds test for negative cases
1 parent 3895ad8 commit a8c9276

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

tests/emailpassword/test_passwordreset.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919
from fastapi import FastAPI
2020
from fastapi.requests import Request
2121
from fastapi.testclient import TestClient
22-
from pytest import fixture, mark
22+
from pytest import fixture, mark, raises
2323
from supertokens_python import InputAppInfo, SupertokensConfig, init
24+
from supertokens_python.exceptions import GeneralError
2425
from supertokens_python.framework.fastapi import get_middleware
2526
from supertokens_python.recipe import emailpassword, session
2627
from supertokens_python.recipe.emailpassword.asyncio import create_reset_password_link
28+
from supertokens_python.recipe.emailpassword.interfaces import (
29+
CreateResetPasswordLinkUnknownUserIdError,
30+
)
2731
from supertokens_python.recipe.session import SessionContainer
2832
from supertokens_python.recipe.session.asyncio import (
2933
create_new_session,
@@ -376,3 +380,10 @@ async def test_create_reset_password_link(
376380
assert url.path == "/auth/reset-password"
377381
assert "tenantId=public" in queries
378382
assert "rid=emailpassword" in queries
383+
384+
link = await create_reset_password_link("public", "invalidUserId")
385+
assert isinstance(link, CreateResetPasswordLinkUnknownUserIdError)
386+
387+
with raises(GeneralError) as err:
388+
await create_reset_password_link("invalidTenantId", user_info["id"])
389+
assert "status code: 400" in str(err.value)

tests/thirdpartyemailpassword/test_email_delivery.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
from fastapi import FastAPI
2121
from fastapi.requests import Request
2222
from fastapi.testclient import TestClient
23-
from pytest import fixture, mark
23+
from pytest import fixture, mark, raises
2424
from urllib.parse import urlparse
2525

2626
from supertokens_python import InputAppInfo, SupertokensConfig, init
27+
from supertokens_python.exceptions import GeneralError
2728
from supertokens_python.framework.fastapi import get_middleware
2829
from supertokens_python.ingredients.emaildelivery import EmailDeliveryInterface
2930
from supertokens_python.ingredients.emaildelivery.types import (
@@ -41,6 +42,9 @@
4142
from supertokens_python.recipe.thirdpartyemailpassword.asyncio import (
4243
create_reset_password_link,
4344
)
45+
from supertokens_python.recipe.thirdpartyemailpassword.interfaces import (
46+
CreateResetPasswordLinkUnknownUserIdError,
47+
)
4448
from supertokens_python.recipe.emailverification.emaildelivery.services import (
4549
SMTPService as EVSMTPService,
4650
)
@@ -1075,3 +1079,10 @@ async def test_create_reset_password_link(
10751079
assert url.path == "/auth/reset-password"
10761080
assert "tenantId=public" in queries
10771081
assert "rid=thirdpartyemailpassword" in queries
1082+
1083+
link = await create_reset_password_link("public", "invalidUserId")
1084+
assert isinstance(link, CreateResetPasswordLinkUnknownUserIdError)
1085+
1086+
with raises(GeneralError) as err:
1087+
await create_reset_password_link("invalidTenantId", user_info["id"])
1088+
assert "status code: 400" in str(err.value)

0 commit comments

Comments
 (0)