Skip to content

Commit b262e99

Browse files
Merge pull request #393 from supertokens/fix/test-multitenancy
fix: Linter errors in tests after multitenancy
2 parents f062633 + 5f8a58b commit b262e99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1233
-627
lines changed

supertokens_python/always_initialised_recipes.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

supertokens_python/recipe/emailpassword/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from supertokens_python.ingredients.emaildelivery.types import EmailDeliveryConfig
1919
from supertokens_python.recipe.emailpassword.types import EmailTemplateVars
20+
from supertokens_python.ingredients.emaildelivery import types as emaildelivery_types
2021

2122
from . import exceptions as ex
2223
from . import utils
@@ -28,6 +29,7 @@
2829
InputSignUpFeature = utils.InputSignUpFeature
2930
InputFormField = utils.InputFormField
3031
SMTPService = emaildelivery_services.SMTPService
32+
EmailDeliveryInterface = emaildelivery_types.EmailDeliveryInterface
3133

3234
if TYPE_CHECKING:
3335
from supertokens_python.supertokens import AppInfo

supertokens_python/recipe/emailverification/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from . import utils
2020
from .emaildelivery import services as emaildelivery_services
2121
from . import recipe
22+
from . import types
2223
from .interfaces import TypeGetEmailForUserIdFunction
2324
from .recipe import EmailVerificationRecipe
2425
from .types import EmailTemplateVars
@@ -28,6 +29,7 @@
2829
exception = ex
2930
SMTPService = emaildelivery_services.SMTPService
3031
EmailVerificationClaim = recipe.EmailVerificationClaim
32+
EmailDeliveryInterface = types.EmailDeliveryInterface
3133

3234

3335
if TYPE_CHECKING:

supertokens_python/recipe/multitenancy/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from __future__ import annotations
1515

1616
from typing import TYPE_CHECKING, Callable, Union
17-
from supertokens_python import always_initialised_recipes
1817

1918
from . import exceptions as ex
2019
from . import recipe
@@ -42,6 +41,3 @@ def init(
4241
error_handlers,
4342
override,
4443
)
45-
46-
47-
always_initialised_recipes.DEFAULT_MULTITENANCY_RECIPE = init()

supertokens_python/recipe/passwordless/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
SMTPService = emaildelivery_services.SMTPService
4848
TwilioService = smsdelivery_services.TwilioService
4949
SuperTokensSMSService = smsdelivery_services.SuperTokensSMSService
50+
EmailDeliveryInterface = types.EmailDeliveryInterface
51+
SMSDeliveryInterface = types.SMSDeliveryInterface
5052

5153

5254
def init(

supertokens_python/recipe/session/session_class.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,9 @@ async def fetch_and_set_claim(
223223
if user_context is None:
224224
user_context = {}
225225

226-
# TODO: Pass tenant id
227-
update = await claim.build(self.get_user_id(), "pass-tenant-id", user_context)
226+
update = await claim.build(
227+
self.get_user_id(), self.get_tenant_id(), user_context
228+
)
228229
return await self.merge_into_access_token_payload(update, user_context)
229230

230231
async def set_claim_value(

supertokens_python/recipe/thirdpartyemailpassword/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from supertokens_python.ingredients.emaildelivery.types import EmailDeliveryConfig
1919
from supertokens_python.recipe.thirdparty import provider
2020
from supertokens_python.recipe.thirdpartyemailpassword.types import EmailTemplateVars
21+
from supertokens_python.ingredients.emaildelivery import types as emaildelivery_types
22+
from . import types
2123

2224
from .. import emailpassword
2325
from . import exceptions as ex
@@ -34,6 +36,9 @@
3436
ProviderConfigForClientType = provider.ProviderConfigForClientType
3537
SMTPService = emaildelivery_services.SMTPService
3638

39+
EmailDeliveryInterface = emaildelivery_types.EmailDeliveryInterface
40+
PasswordResetEmailTemplateVars = types.PasswordResetEmailTemplateVars
41+
3742
if TYPE_CHECKING:
3843
from supertokens_python.supertokens import AppInfo
3944

supertokens_python/recipe/thirdpartypasswordless/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
from .recipe import ThirdPartyPasswordlessRecipe
2828
from .smsdelivery import services as smsdelivery_services
2929
from .types import EmailTemplateVars, SMSTemplateVars
30+
from supertokens_python.ingredients.emaildelivery import types as emaildelivery_types
31+
from supertokens_python.ingredients.smsdelivery import types as smsdelivery_types
3032

3133
InputOverrideConfig = utils.InputOverrideConfig
3234
exceptions = ex
@@ -42,6 +44,8 @@
4244
ProviderConfig = provider.ProviderConfig
4345
ProviderClientConfig = provider.ProviderClientConfig
4446
ProviderConfigForClientType = provider.ProviderConfigForClientType
47+
EmailDeliveryInterface = emaildelivery_types.EmailDeliveryInterface
48+
SMSDeliveryInterface = smsdelivery_types.SMSDeliveryInterface
4549

4650
if TYPE_CHECKING:
4751
from supertokens_python.supertokens import AppInfo

supertokens_python/recipe_module.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
from .exceptions import SuperTokensError
3131
from .normalised_url_path import NormalisedURLPath
3232

33-
from supertokens_python.recipe.multitenancy.recipe import MultitenancyRecipe
34-
3533

3634
class ApiIdWithTenantId:
3735
def __init__(self, api_id: str, tenant_id: str):
@@ -54,6 +52,7 @@ async def return_api_id_if_can_handle_request(
5452
self, path: NormalisedURLPath, method: str, user_context: Dict[str, Any]
5553
) -> Union[ApiIdWithTenantId, None]:
5654
from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID
55+
from supertokens_python.recipe.multitenancy.recipe import MultitenancyRecipe
5756

5857
apis_handled = self.get_apis_handled()
5958

supertokens_python/supertokens.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
send_non_200_response_with_message,
4747
)
4848

49-
from .always_initialised_recipes import DEFAULT_MULTITENANCY_RECIPE
5049
from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID
5150

5251
if TYPE_CHECKING:
@@ -189,20 +188,21 @@ def __init__(
189188
"Please provide at least one recipe to the supertokens.init function call"
190189
)
191190

192-
multitenancy_found = [False]
191+
from supertokens_python.recipe.multitenancy.recipe import MultitenancyRecipe
192+
193+
multitenancy_found = False
193194

194195
def make_recipe(recipe: Callable[[AppInfo], RecipeModule]) -> RecipeModule:
196+
nonlocal multitenancy_found
195197
recipe_module = recipe(self.app_info)
196-
if recipe_module.get_recipe_id() == "multitenancy":
197-
multitenancy_found[0] = True
198+
if recipe_module.get_recipe_id() == MultitenancyRecipe.recipe_id:
199+
multitenancy_found = True
198200
return recipe_module
199201

200202
self.recipe_modules: List[RecipeModule] = list(map(make_recipe, recipe_list))
201203

202-
if callable(DEFAULT_MULTITENANCY_RECIPE) and not multitenancy_found[0]:
203-
recipe = DEFAULT_MULTITENANCY_RECIPE( # pylint: disable=not-callable
204-
self.app_info
205-
)
204+
if not multitenancy_found:
205+
recipe = MultitenancyRecipe.init()(self.app_info)
206206
self.recipe_modules.append(recipe)
207207

208208
self.telemetry = (

tests/Django/test_django.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,15 @@ def override_email_password_apis(original_implementation: APIInterface):
343343
original_func = original_implementation.email_exists_get
344344

345345
async def email_exists_get(
346-
email: str, api_options: APIOptions, user_context: Dict[str, Any]
346+
email: str,
347+
tenant_id: str,
348+
api_options: APIOptions,
349+
user_context: Dict[str, Any],
347350
):
348351
response_dict = {"custom": True}
349352
api_options.response.set_status_code(203)
350353
api_options.response.set_json_content(response_dict)
351-
return await original_func(email, api_options, user_context)
354+
return await original_func(email, tenant_id, api_options, user_context)
352355

353356
original_implementation.email_exists_get = email_exists_get
354357
return original_implementation

tests/Fastapi/test_fastapi.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,12 +454,15 @@ def override_email_password_apis(original_implementation: EPAPIInterface):
454454
original_func = original_implementation.email_exists_get
455455

456456
async def email_exists_get(
457-
email: str, api_options: APIOptions, user_context: Dict[str, Any]
457+
email: str,
458+
tenant_id: str,
459+
api_options: APIOptions,
460+
user_context: Dict[str, Any],
458461
):
459462
response_dict = {"custom": True}
460463
api_options.response.set_status_code(203)
461464
api_options.response.set_json_content(response_dict)
462-
return await original_func(email, api_options, user_context)
465+
return await original_func(email, tenant_id, api_options, user_context)
463466

464467
original_implementation.email_exists_get = email_exists_get
465468
return original_implementation

tests/Flask/test_flask.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,15 @@ def override_email_password_apis(original_implementation: APIInterface):
8282
original_func = original_implementation.email_exists_get
8383

8484
async def email_exists_get(
85-
email: str, api_options: APIOptions, user_context: Dict[str, Any]
85+
email: str,
86+
tenant_id: str,
87+
api_options: APIOptions,
88+
user_context: Dict[str, Any],
8689
):
8790
response_dict = {"custom": True}
8891
api_options.response.set_status_code(203)
8992
api_options.response.set_json_content(response_dict)
90-
return await original_func(email, api_options, user_context)
93+
return await original_func(email, tenant_id, api_options, user_context)
9194

9295
original_implementation.email_exists_get = email_exists_get
9396
return original_implementation

0 commit comments

Comments
 (0)