Skip to content

fix: Linter errors in tests after multitenancy #393

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

Merged
merged 3 commits into from
Aug 9, 2023
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
21 changes: 0 additions & 21 deletions supertokens_python/always_initialised_recipes.py

This file was deleted.

2 changes: 2 additions & 0 deletions supertokens_python/recipe/emailpassword/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from supertokens_python.ingredients.emaildelivery.types import EmailDeliveryConfig
from supertokens_python.recipe.emailpassword.types import EmailTemplateVars
from supertokens_python.ingredients.emaildelivery import types as emaildelivery_types

from . import exceptions as ex
from . import utils
Expand All @@ -28,6 +29,7 @@
InputSignUpFeature = utils.InputSignUpFeature
InputFormField = utils.InputFormField
SMTPService = emaildelivery_services.SMTPService
EmailDeliveryInterface = emaildelivery_types.EmailDeliveryInterface

if TYPE_CHECKING:
from supertokens_python.supertokens import AppInfo
Expand Down
2 changes: 2 additions & 0 deletions supertokens_python/recipe/emailverification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from . import utils
from .emaildelivery import services as emaildelivery_services
from . import recipe
from . import types
from .interfaces import TypeGetEmailForUserIdFunction
from .recipe import EmailVerificationRecipe
from .types import EmailTemplateVars
Expand All @@ -28,6 +29,7 @@
exception = ex
SMTPService = emaildelivery_services.SMTPService
EmailVerificationClaim = recipe.EmailVerificationClaim
EmailDeliveryInterface = types.EmailDeliveryInterface


if TYPE_CHECKING:
Expand Down
4 changes: 0 additions & 4 deletions supertokens_python/recipe/multitenancy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Callable, Union
from supertokens_python import always_initialised_recipes

from . import exceptions as ex
from . import recipe
Expand Down Expand Up @@ -42,6 +41,3 @@ def init(
error_handlers,
override,
)


always_initialised_recipes.DEFAULT_MULTITENANCY_RECIPE = init()
2 changes: 2 additions & 0 deletions supertokens_python/recipe/passwordless/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
SMTPService = emaildelivery_services.SMTPService
TwilioService = smsdelivery_services.TwilioService
SuperTokensSMSService = smsdelivery_services.SuperTokensSMSService
EmailDeliveryInterface = types.EmailDeliveryInterface
SMSDeliveryInterface = types.SMSDeliveryInterface


def init(
Expand Down
5 changes: 3 additions & 2 deletions supertokens_python/recipe/session/session_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ async def fetch_and_set_claim(
if user_context is None:
user_context = {}

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

async def set_claim_value(
Expand Down
5 changes: 5 additions & 0 deletions supertokens_python/recipe/thirdpartyemailpassword/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from supertokens_python.ingredients.emaildelivery.types import EmailDeliveryConfig
from supertokens_python.recipe.thirdparty import provider
from supertokens_python.recipe.thirdpartyemailpassword.types import EmailTemplateVars
from supertokens_python.ingredients.emaildelivery import types as emaildelivery_types
from . import types

from .. import emailpassword
from . import exceptions as ex
Expand All @@ -34,6 +36,9 @@
ProviderConfigForClientType = provider.ProviderConfigForClientType
SMTPService = emaildelivery_services.SMTPService

EmailDeliveryInterface = emaildelivery_types.EmailDeliveryInterface
PasswordResetEmailTemplateVars = types.PasswordResetEmailTemplateVars

if TYPE_CHECKING:
from supertokens_python.supertokens import AppInfo

Expand Down
4 changes: 4 additions & 0 deletions supertokens_python/recipe/thirdpartypasswordless/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from .recipe import ThirdPartyPasswordlessRecipe
from .smsdelivery import services as smsdelivery_services
from .types import EmailTemplateVars, SMSTemplateVars
from supertokens_python.ingredients.emaildelivery import types as emaildelivery_types
from supertokens_python.ingredients.smsdelivery import types as smsdelivery_types

InputOverrideConfig = utils.InputOverrideConfig
exceptions = ex
Expand All @@ -42,6 +44,8 @@
ProviderConfig = provider.ProviderConfig
ProviderClientConfig = provider.ProviderClientConfig
ProviderConfigForClientType = provider.ProviderConfigForClientType
EmailDeliveryInterface = emaildelivery_types.EmailDeliveryInterface
SMSDeliveryInterface = smsdelivery_types.SMSDeliveryInterface

if TYPE_CHECKING:
from supertokens_python.supertokens import AppInfo
Expand Down
3 changes: 1 addition & 2 deletions supertokens_python/recipe_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
from .exceptions import SuperTokensError
from .normalised_url_path import NormalisedURLPath

from supertokens_python.recipe.multitenancy.recipe import MultitenancyRecipe


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

apis_handled = self.get_apis_handled()

Expand Down
16 changes: 8 additions & 8 deletions supertokens_python/supertokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
send_non_200_response_with_message,
)

from .always_initialised_recipes import DEFAULT_MULTITENANCY_RECIPE
from supertokens_python.recipe.multitenancy.constants import DEFAULT_TENANT_ID

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

multitenancy_found = [False]
from supertokens_python.recipe.multitenancy.recipe import MultitenancyRecipe

multitenancy_found = False

def make_recipe(recipe: Callable[[AppInfo], RecipeModule]) -> RecipeModule:
nonlocal multitenancy_found
recipe_module = recipe(self.app_info)
if recipe_module.get_recipe_id() == "multitenancy":
multitenancy_found[0] = True
if recipe_module.get_recipe_id() == MultitenancyRecipe.recipe_id:
multitenancy_found = True
return recipe_module

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

if callable(DEFAULT_MULTITENANCY_RECIPE) and not multitenancy_found[0]:
recipe = DEFAULT_MULTITENANCY_RECIPE( # pylint: disable=not-callable
self.app_info
)
if not multitenancy_found:
recipe = MultitenancyRecipe.init()(self.app_info)
self.recipe_modules.append(recipe)

self.telemetry = (
Expand Down
7 changes: 5 additions & 2 deletions tests/Django/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,15 @@ def override_email_password_apis(original_implementation: APIInterface):
original_func = original_implementation.email_exists_get

async def email_exists_get(
email: str, api_options: APIOptions, user_context: Dict[str, Any]
email: str,
tenant_id: str,
api_options: APIOptions,
user_context: Dict[str, Any],
):
response_dict = {"custom": True}
api_options.response.set_status_code(203)
api_options.response.set_json_content(response_dict)
return await original_func(email, api_options, user_context)
return await original_func(email, tenant_id, api_options, user_context)

original_implementation.email_exists_get = email_exists_get
return original_implementation
Expand Down
7 changes: 5 additions & 2 deletions tests/Fastapi/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,15 @@ def override_email_password_apis(original_implementation: EPAPIInterface):
original_func = original_implementation.email_exists_get

async def email_exists_get(
email: str, api_options: APIOptions, user_context: Dict[str, Any]
email: str,
tenant_id: str,
api_options: APIOptions,
user_context: Dict[str, Any],
):
response_dict = {"custom": True}
api_options.response.set_status_code(203)
api_options.response.set_json_content(response_dict)
return await original_func(email, api_options, user_context)
return await original_func(email, tenant_id, api_options, user_context)

original_implementation.email_exists_get = email_exists_get
return original_implementation
Expand Down
7 changes: 5 additions & 2 deletions tests/Flask/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,15 @@ def override_email_password_apis(original_implementation: APIInterface):
original_func = original_implementation.email_exists_get

async def email_exists_get(
email: str, api_options: APIOptions, user_context: Dict[str, Any]
email: str,
tenant_id: str,
api_options: APIOptions,
user_context: Dict[str, Any],
):
response_dict = {"custom": True}
api_options.response.set_status_code(203)
api_options.response.set_json_content(response_dict)
return await original_func(email, api_options, user_context)
return await original_func(email, tenant_id, api_options, user_context)

original_implementation.email_exists_get = email_exists_get
return original_implementation
Expand Down
Loading