Skip to content

Commit fdb85d4

Browse files
Merge pull request #526 from supertokens/fix/failing-tests-related-to-any-type-support
fix: Failing tests regarding any type support in formFields
2 parents 89b7be2 + 674cc6e commit fdb85d4

File tree

2 files changed

+23
-37
lines changed

2 files changed

+23
-37
lines changed

tests/emailpassword/test_passwordreset.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,14 @@ async def test_email_validation_checks_in_generate_token_API(
119119
json={"formFields": [{"id": "email", "value": invalid_email}]},
120120
)
121121

122-
assert res.status_code == 200
123122
dict_res = json.loads(res.text)
124-
assert dict_res["status"] == "FIELD_ERROR"
123+
assert res.status_code == 200 if invalid_email == "random" else 400
124+
if invalid_email == "random":
125+
assert dict_res["status"] == "FIELD_ERROR"
126+
assert dict_res["formFields"][0]["id"] == "email"
127+
assert dict_res["formFields"][0]["error"] == "Email is not valid"
128+
else:
129+
assert dict_res["message"] == "email value must be a string"
125130

126131

127132
@mark.asyncio

tests/input_validation/test_input_validation.py

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Any, Dict, List
33

44
import pytest
5+
56
from supertokens_python import InputAppInfo, SupertokensConfig, init
67
from supertokens_python.recipe import (
78
emailpassword,
@@ -31,22 +32,6 @@ async def test_init_validation_emailpassword():
3132
)
3233
assert "app_info must be an instance of InputAppInfo" == str(ex.value)
3334

34-
with pytest.raises(ValueError) as ex:
35-
init(
36-
supertokens_config=SupertokensConfig("http://localhost:3567"),
37-
app_info=InputAppInfo(
38-
app_name="SuperTokens Demo",
39-
api_domain="http://api.supertokens.io",
40-
website_domain="http://supertokens.io",
41-
api_base_path="/auth",
42-
),
43-
framework="fastapi",
44-
recipe_list=[
45-
emailpassword.init(sign_up_feature="sign up"), # type: ignore
46-
],
47-
)
48-
assert "sign_up_feature must be of type InputSignUpFeature or None" == str(ex.value)
49-
5035
with pytest.raises(ValueError) as ex:
5136
init(
5237
supertokens_config=SupertokensConfig("http://localhost:3567"),
@@ -67,22 +52,6 @@ async def test_init_validation_emailpassword():
6752
== str(ex.value)
6853
)
6954

70-
with pytest.raises(ValueError) as ex:
71-
init(
72-
supertokens_config=SupertokensConfig("http://localhost:3567"),
73-
app_info=InputAppInfo(
74-
app_name="SuperTokens Demo",
75-
api_domain="http://api.supertokens.io",
76-
website_domain="http://supertokens.io",
77-
api_base_path="/auth",
78-
),
79-
framework="fastapi",
80-
recipe_list=[
81-
emailpassword.init(override="override"), # type: ignore
82-
],
83-
)
84-
assert "override must be of type InputOverrideConfig or None" == str(ex.value)
85-
8655

8756
async def get_email_for_user_id(_: str, __: Dict[str, Any]):
8857
return GetEmailForUserIdOkResult("[email protected]")
@@ -307,7 +276,9 @@ async def send_email(
307276
clients=[
308277
thirdparty.ProviderClientConfig(
309278
client_id=os.environ.get("GOOGLE_CLIENT_ID"), # type: ignore
310-
client_secret=os.environ.get("GOOGLE_CLIENT_SECRET"), # type: ignore
279+
client_secret=os.environ.get(
280+
"GOOGLE_CLIENT_SECRET"
281+
), # type: ignore
311282
)
312283
],
313284
)
@@ -318,7 +289,9 @@ async def send_email(
318289
clients=[
319290
thirdparty.ProviderClientConfig(
320291
client_id=os.environ.get("FACEBOOK_CLIENT_ID"), # type: ignore
321-
client_secret=os.environ.get("FACEBOOK_CLIENT_SECRET"), # type: ignore
292+
client_secret=os.environ.get(
293+
"FACEBOOK_CLIENT_SECRET"
294+
), # type: ignore
322295
)
323296
],
324297
)
@@ -329,7 +302,9 @@ async def send_email(
329302
clients=[
330303
thirdparty.ProviderClientConfig(
331304
client_id=os.environ.get("GITHUB_CLIENT_ID"), # type: ignore
332-
client_secret=os.environ.get("GITHUB_CLIENT_SECRET"), # type: ignore
305+
client_secret=os.environ.get(
306+
"GITHUB_CLIENT_SECRET"
307+
), # type: ignore
333308
)
334309
],
335310
)
@@ -365,6 +340,9 @@ async def test_init_validation_session():
365340
api_base_path="/auth",
366341
),
367342
framework="fastapi",
343+
# NOTE: Type is ignored in the following line because that
344+
# is what is being tested for so that the SDK throws an error
345+
# on invalid type.
368346
recipe_list=[session.init(error_handlers="error handlers")], # type: ignore
369347
)
370348
assert "error_handlers must be an instance of ErrorHandlers or None" == str(
@@ -401,6 +379,9 @@ async def test_init_validation_thirdparty():
401379
),
402380
framework="fastapi",
403381
recipe_list=[
382+
# NOTE: Type is ignored in the following line because that
383+
# is what is being tested for so that the SDK throws an error
384+
# on invalid type.
404385
thirdparty.init(sign_in_and_up_feature="sign in up") # type: ignore
405386
],
406387
)

0 commit comments

Comments
 (0)