Skip to content

Commit 7dadddb

Browse files
Merge pull request #423 from supertokens/test-cicd/fix-unit-tests
test: Fix failing unit tests
2 parents f131ac9 + acbca67 commit 7dadddb

File tree

35 files changed

+127
-142
lines changed

35 files changed

+127
-142
lines changed

frontendDriverInterfaceSupported.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"_comment": "contains a list of frontend-driver interfaces branch names that this core supports",
33
"versions": [
4-
"1.16"
4+
"1.17"
55
]
6-
}
6+
}

supertokens_python/framework/django/django_middleware.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ def __syncMiddleware(request: HttpRequest):
7171
from django.http import HttpResponse
7272

7373
response = DjangoResponse(HttpResponse())
74+
user_context = default_user_context(custom_request)
75+
7476
try:
7577
result: Union[DjangoResponse, None] = async_to_sync(st.middleware)(
76-
custom_request, response
78+
custom_request, response, user_context
7779
)
7880

7981
if result is None:

supertokens_python/recipe/dashboard/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020

2121
from .recipe import DashboardRecipe
2222

23-
if TYPE_CHECKING:
24-
from supertokens_python.recipe.dashboard.utils import InputOverrideConfig
23+
from supertokens_python.recipe.dashboard import utils
24+
25+
InputOverrideConfig = utils.InputOverrideConfig
2526

2627

2728
def init(

supertokens_python/recipe/emailpassword/asyncio/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def get_user_by_email(
7070
if user_context is None:
7171
user_context = {}
7272
return await EmailPasswordRecipe.get_instance().recipe_implementation.get_user_by_email(
73-
tenant_id, email, user_context
73+
email, tenant_id, user_context
7474
)
7575

7676

@@ -93,7 +93,7 @@ async def reset_password_using_token(
9393
if user_context is None:
9494
user_context = {}
9595
return await EmailPasswordRecipe.get_instance().recipe_implementation.reset_password_using_token(
96-
new_password, tenant_id, token, user_context
96+
token, new_password, tenant_id, user_context
9797
)
9898

9999

supertokens_python/recipe/multitenancy/recipe_implementation.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from .utils import MultitenancyConfig
4646

4747
from supertokens_python.querier import NormalisedURLPath
48+
from .constants import DEFAULT_TENANT_ID
4849

4950

5051
def parse_tenant_config(tenant: Dict[str, Any]) -> TenantConfigResponse:
@@ -161,7 +162,7 @@ async def get_tenant(
161162
self, tenant_id: Optional[str], user_context: Dict[str, Any]
162163
) -> Optional[GetTenantOkResult]:
163164
res = await self.querier.send_get_request(
164-
NormalisedURLPath(f"{tenant_id}/recipe/multitenancy/tenant"),
165+
NormalisedURLPath(f"{tenant_id or DEFAULT_TENANT_ID}/recipe/multitenancy/tenant"),
165166
)
166167

167168
if res["status"] == "TENANT_NOT_FOUND_ERROR":
@@ -209,7 +210,7 @@ async def create_or_update_third_party_config(
209210
user_context: Dict[str, Any],
210211
) -> CreateOrUpdateThirdPartyConfigOkResult:
211212
response = await self.querier.send_put_request(
212-
NormalisedURLPath(f"{tenant_id}/recipe/multitenancy/config/thirdparty"),
213+
NormalisedURLPath(f"{tenant_id or DEFAULT_TENANT_ID}/recipe/multitenancy/config/thirdparty"),
213214
{
214215
"config": config.to_json(),
215216
"skipValidation": skip_validation is True,
@@ -228,7 +229,7 @@ async def delete_third_party_config(
228229
) -> DeleteThirdPartyConfigOkResult:
229230
response = await self.querier.send_post_request(
230231
NormalisedURLPath(
231-
f"{tenant_id}/recipe/multitenancy/config/thirdparty/remove"
232+
f"{tenant_id or DEFAULT_TENANT_ID}/recipe/multitenancy/config/thirdparty/remove"
232233
),
233234
{
234235
"thirdPartyId": third_party_id,
@@ -240,7 +241,7 @@ async def delete_third_party_config(
240241
)
241242

242243
async def associate_user_to_tenant(
243-
self, tenant_id: str | None, user_id: str, user_context: Dict[str, Any]
244+
self, tenant_id: Optional[str], user_id: str, user_context: Dict[str, Any]
244245
) -> Union[
245246
AssociateUserToTenantOkResult,
246247
AssociateUserToTenantUnknownUserIdError,
@@ -249,7 +250,7 @@ async def associate_user_to_tenant(
249250
AssociateUserToTenantThirdPartyUserAlreadyExistsError,
250251
]:
251252
response: Dict[str, Any] = await self.querier.send_post_request(
252-
NormalisedURLPath(f"{tenant_id}/recipe/multitenancy/tenant/user"),
253+
NormalisedURLPath(f"{tenant_id or DEFAULT_TENANT_ID}/recipe/multitenancy/tenant/user"),
253254
{
254255
"userId": user_id,
255256
},
@@ -277,10 +278,10 @@ async def associate_user_to_tenant(
277278
raise Exception("Should never come here")
278279

279280
async def dissociate_user_from_tenant(
280-
self, tenant_id: str | None, user_id: str, user_context: Dict[str, Any]
281+
self, tenant_id: Optional[str], user_id: str, user_context: Dict[str, Any]
281282
) -> DisassociateUserFromTenantOkResult:
282283
response = await self.querier.send_post_request(
283-
NormalisedURLPath(f"{tenant_id}/recipe/multitenancy/tenant/user/remove"),
284+
NormalisedURLPath(f"{tenant_id or DEFAULT_TENANT_ID}/recipe/multitenancy/tenant/user/remove"),
284285
{
285286
"userId": user_id,
286287
},

supertokens_python/recipe/passwordless/api/implementation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,17 @@ async def consume_code_post(
289289
ev_instance = EmailVerificationRecipe.get_instance_optional()
290290
if ev_instance is not None:
291291
token_response = await ev_instance.recipe_implementation.create_email_verification_token(
292-
tenant_id, user.user_id, user.email, user_context
292+
user.user_id, user.email, tenant_id, user_context
293293
)
294294

295295
if isinstance(token_response, CreateEmailVerificationTokenOkResult):
296296
await ev_instance.recipe_implementation.verify_email_using_token(
297-
tenant_id, token_response.token, user_context
297+
token_response.token, tenant_id, user_context
298298
)
299299

300300
session = await create_new_session(
301-
tenant_id=tenant_id,
302301
request=api_options.request,
302+
tenant_id=tenant_id,
303303
user_id=user.user_id,
304304
access_token_payload={},
305305
session_data_in_database={},

supertokens_python/recipe/session/asyncio/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
from typing import Any, Callable, Dict, List, Optional, TypeVar, Union
14+
from __future__ import annotations
15+
from typing import Any, Callable, Dict, List, Optional, TypeVar, Union, TYPE_CHECKING
1516

1617
from supertokens_python.recipe.openid.interfaces import (
1718
GetOpenIdDiscoveryConfigurationResult,
@@ -46,9 +47,12 @@
4647

4748
_T = TypeVar("_T")
4849

50+
if TYPE_CHECKING:
51+
from supertokens_python.framework.request import BaseRequest
52+
4953

5054
async def create_new_session(
51-
request: Any,
55+
request: BaseRequest,
5256
tenant_id: str,
5357
user_id: str,
5458
access_token_payload: Union[Dict[str, Any], None] = None,

supertokens_python/recipe/session/syncio/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
14-
15-
from typing import Any, Dict, List, Union, Callable, Optional, TypeVar
14+
from __future__ import annotations
15+
from typing import Any, Dict, List, Union, Callable, Optional, TypeVar, TYPE_CHECKING
1616

1717
from supertokens_python.async_to_sync_wrapper import sync
1818
from supertokens_python.recipe.openid.interfaces import (
@@ -37,8 +37,12 @@
3737
)
3838

3939

40+
if TYPE_CHECKING:
41+
from supertokens_python.framework.request import BaseRequest
42+
43+
4044
def create_new_session(
41-
request: Any,
45+
request: BaseRequest,
4246
tenant_id: str,
4347
user_id: str,
4448
access_token_payload: Union[Dict[str, Any], None] = None,

supertokens_python/recipe/thirdparty/api/implementation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async def sign_in_up_post(
9191
email=await provider.config.generate_fake_email(
9292
user_info.third_party_user_id, tenant_id, user_context
9393
),
94-
email_verified=True,
94+
is_verified=True,
9595
)
9696

9797
email = user_info.email.id if user_info.email is not None else None
@@ -123,15 +123,15 @@ async def sign_in_up_post(
123123

124124
if isinstance(token_response, CreateEmailVerificationTokenOkResult):
125125
await ev_instance.recipe_implementation.verify_email_using_token(
126-
tenant_id=tenant_id,
127126
token=token_response.token,
127+
tenant_id=tenant_id,
128128
user_context=user_context,
129129
)
130130

131131
user = signinup_response.user
132132
session = await create_new_session(
133-
tenant_id=tenant_id,
134133
request=api_options.request,
134+
tenant_id=tenant_id,
135135
user_id=user.user_id,
136136
user_context=user_context,
137137
)

supertokens_python/recipe/thirdparty/providers/github.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async def get_user_info(
5555
for info in email_info:
5656
if info.get("primary"):
5757
result.email = UserInfoEmail(
58-
email=info.get("email"), email_verified=info.get("verified")
58+
email=info.get("email"), is_verified=info.get("verified")
5959
)
6060

6161
return result

supertokens_python/recipe/thirdparty/providers/linkedin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async def get_user_info(
8383
third_party_user_id=raw_user_info_from_provider.from_user_info_api.get("id"), # type: ignore
8484
email=UserInfoEmail(
8585
email=raw_user_info_from_provider.from_user_info_api.get("email"), # type: ignore
86-
email_verified=False,
86+
is_verified=False,
8787
),
8888
)
8989

supertokens_python/recipe/thirdparty/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ def __eq__(self, other: object) -> bool:
6666

6767

6868
class UserInfoEmail:
69-
def __init__(self, email: str, email_verified: bool):
69+
def __init__(self, email: str, is_verified: bool):
7070
self.id: str = email
71-
self.is_verified: bool = email_verified
71+
self.is_verified: bool = is_verified
7272

7373

7474
class UserInfo:

supertokens_python/recipe/userroles/asyncio/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async def add_role_to_user(
2525
if user_context is None:
2626
user_context = {}
2727
return await UserRolesRecipe.get_instance().recipe_implementation.add_role_to_user(
28-
role, tenant_id, user_id, user_context
28+
user_id, role, tenant_id, user_context
2929
)
3030

3131

@@ -38,7 +38,7 @@ async def remove_user_role(
3838
if user_context is None:
3939
user_context = {}
4040
return await UserRolesRecipe.get_instance().recipe_implementation.remove_user_role(
41-
role, tenant_id, user_id, user_context
41+
user_id, role, tenant_id, user_context
4242
)
4343

4444

supertokens_python/supertokens.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ async def get_user_count( # pylint: disable=no-self-use
263263
include_recipe_ids_str = ",".join(include_recipe_ids)
264264

265265
response = await querier.send_get_request(
266-
NormalisedURLPath(f"/{tenant_id}{USER_COUNT}"),
266+
NormalisedURLPath(f"/{tenant_id or 'public'}{USER_COUNT}"),
267267
{
268268
"includeRecipeIds": include_recipe_ids_str,
269269
"includeAllTenants": tenant_id is None,

tests/Django/test_django.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,9 @@ async def test_thirdparty_parsing_works(self):
471471
start_st()
472472

473473
state = b64encode(
474-
json.dumps({"redirectURI": "http://localhost:3000/redirect"}).encode()
474+
json.dumps(
475+
{"frontendRedirectURI": "http://localhost:3000/redirect"}
476+
).encode()
475477
).decode()
476478
code = "testing"
477479

tests/Flask/test_flask.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def test_thirdparty_parsing_works(driver_config_app: Any):
480480

481481
test_client = driver_config_app.test_client()
482482
state = b64encode(
483-
json.dumps({"redirectURI": "http://localhost:3000/redirect"}).encode()
483+
json.dumps({"frontendRedirectURI": "http://localhost:3000/redirect"}).encode()
484484
).decode()
485485
code = "testing"
486486

tests/auth-react/django3x/mysite/utils.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
CreateAndSendCustomTextMessageParameters,
5656
)
5757
from supertokens_python.recipe.session import SessionContainer, SessionRecipe
58+
from supertokens_python.recipe.multitenancy.recipe import MultitenancyRecipe
5859
from supertokens_python.recipe.session.interfaces import (
5960
APIInterface as SessionAPIInterface,
6061
)
@@ -246,17 +247,6 @@ async def get_user_info( # pylint: disable=no-self-use
246247
],
247248
),
248249
),
249-
thirdparty.ProviderInput(
250-
config=thirdparty.ProviderConfig(
251-
third_party_id="facebook",
252-
clients=[
253-
thirdparty.ProviderClientConfig(
254-
client_id=os.environ["FACEBOOK_CLIENT_ID"],
255-
client_secret=os.environ["FACEBOOK_CLIENT_SECRET"],
256-
),
257-
],
258-
),
259-
),
260250
thirdparty.ProviderInput(
261251
config=thirdparty.ProviderConfig(
262252
third_party_id="github",
@@ -268,17 +258,6 @@ async def get_user_info( # pylint: disable=no-self-use
268258
],
269259
)
270260
),
271-
thirdparty.ProviderInput(
272-
config=thirdparty.ProviderConfig(
273-
third_party_id="custom",
274-
clients=[
275-
thirdparty.ProviderClientConfig(
276-
client_id=os.environ["DISCORD_CLIENT_ID"],
277-
client_secret=os.environ["DISCORD_CLIENT_SECRET"],
278-
),
279-
],
280-
)
281-
),
282261
thirdparty.ProviderInput(
283262
config=thirdparty.ProviderConfig(
284263
third_party_id="auth0",
@@ -315,6 +294,7 @@ def custom_init(
315294
EmailVerificationRecipe.reset()
316295
ThirdPartyEmailPasswordRecipe.reset()
317296
DashboardRecipe.reset()
297+
MultitenancyRecipe.reset()
318298
Supertokens.reset()
319299

320300
def override_email_verification_apis(

0 commit comments

Comments
 (0)