Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Failing tests regarding any type support in formFields #526

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tests/emailpassword/test_passwordreset.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,14 @@ async def test_email_validation_checks_in_generate_token_API(
json={"formFields": [{"id": "email", "value": invalid_email}]},
)

assert res.status_code == 200
dict_res = json.loads(res.text)
assert dict_res["status"] == "FIELD_ERROR"
assert res.status_code == 200 if invalid_email == "random" else 400
if invalid_email == "random":
assert dict_res["status"] == "FIELD_ERROR"
assert dict_res["formFields"][0]["id"] == "email"
assert dict_res["formFields"][0]["error"] == "Email is not valid"
else:
assert dict_res["message"] == "email value must be a string"


@mark.asyncio
Expand Down
51 changes: 16 additions & 35 deletions tests/input_validation/test_input_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any, Dict, List

import pytest

from supertokens_python import InputAppInfo, SupertokensConfig, init
from supertokens_python.recipe import (
emailpassword,
Expand Down Expand Up @@ -31,22 +32,6 @@ async def test_init_validation_emailpassword():
)
assert "app_info must be an instance of InputAppInfo" == str(ex.value)

with pytest.raises(ValueError) as ex:
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(sign_up_feature="sign up"), # type: ignore
],
)
assert "sign_up_feature must be of type InputSignUpFeature or None" == str(ex.value)

with pytest.raises(ValueError) as ex:
init(
supertokens_config=SupertokensConfig("http://localhost:3567"),
Expand All @@ -67,22 +52,6 @@ async def test_init_validation_emailpassword():
== str(ex.value)
)

with pytest.raises(ValueError) as ex:
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(override="override"), # type: ignore
],
)
assert "override must be of type InputOverrideConfig or None" == str(ex.value)


async def get_email_for_user_id(_: str, __: Dict[str, Any]):
return GetEmailForUserIdOkResult("[email protected]")
Expand Down Expand Up @@ -307,7 +276,9 @@ async def send_email(
clients=[
thirdparty.ProviderClientConfig(
client_id=os.environ.get("GOOGLE_CLIENT_ID"), # type: ignore
client_secret=os.environ.get("GOOGLE_CLIENT_SECRET"), # type: ignore
client_secret=os.environ.get(
"GOOGLE_CLIENT_SECRET"
), # type: ignore
)
],
)
Expand All @@ -318,7 +289,9 @@ async def send_email(
clients=[
thirdparty.ProviderClientConfig(
client_id=os.environ.get("FACEBOOK_CLIENT_ID"), # type: ignore
client_secret=os.environ.get("FACEBOOK_CLIENT_SECRET"), # type: ignore
client_secret=os.environ.get(
"FACEBOOK_CLIENT_SECRET"
), # type: ignore
)
],
)
Expand All @@ -329,7 +302,9 @@ async def send_email(
clients=[
thirdparty.ProviderClientConfig(
client_id=os.environ.get("GITHUB_CLIENT_ID"), # type: ignore
client_secret=os.environ.get("GITHUB_CLIENT_SECRET"), # type: ignore
client_secret=os.environ.get(
"GITHUB_CLIENT_SECRET"
), # type: ignore
)
],
)
Expand Down Expand Up @@ -365,6 +340,9 @@ async def test_init_validation_session():
api_base_path="/auth",
),
framework="fastapi",
# NOTE: Type is ignored in the following line because that
# is what is being tested for so that the SDK throws an error
# on invalid type.
recipe_list=[session.init(error_handlers="error handlers")], # type: ignore
)
assert "error_handlers must be an instance of ErrorHandlers or None" == str(
Expand Down Expand Up @@ -401,6 +379,9 @@ async def test_init_validation_thirdparty():
),
framework="fastapi",
recipe_list=[
# NOTE: Type is ignored in the following line because that
# is what is being tested for so that the SDK throws an error
# on invalid type.
thirdparty.init(sign_in_and_up_feature="sign in up") # type: ignore
],
)
Expand Down
Loading