Skip to content

Commit a8627bb

Browse files
committed
tests: Fix all failing tests
1 parent 617af6f commit a8627bb

File tree

12 files changed

+375
-74
lines changed

12 files changed

+375
-74
lines changed

supertokens_python/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# under the License.
1414
from __future__ import annotations
1515

16-
SUPPORTED_CDI_VERSIONS = ["2.21"]
16+
SUPPORTED_CDI_VERSIONS = ["3.0"]
1717
VERSION = "0.14.7"
1818
TELEMETRY = "/telemetry"
1919
USER_COUNT = "/users/count"

supertokens_python/normalised_url_path.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def equals(self, other: NormalisedURLPath) -> bool:
3939
return self.__value == other.get_as_string_dangerous()
4040

4141
def is_a_recipe_path(self) -> bool:
42-
return self.__value == "/recipe" or self.__value.startswith("/recipe/")
42+
parts = self.__value.split("/")
43+
return parts[1] == "recipe" or parts[2] == "recipe"
4344

4445

4546
def normalise_url_path_or_throw_error(input_str: str) -> str:

supertokens_python/recipe/multitenancy/api/implementation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async def login_methods_get(
7373

7474
return LoginMethodsGetOkResult(
7575
email_password=LoginMethodEmailPassword(
76-
tenant_config_res.email_password.enabled
76+
tenant_config_res.emailpassword.enabled
7777
),
7878
passwordless=LoginMethodPasswordless(
7979
tenant_config_res.passwordless.enabled

supertokens_python/recipe/multitenancy/asyncio/__init__.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,30 @@
1010
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1111
# License for the specific language governing permissions and limitations
1212
# under the License.
13-
from typing import Any, Dict, Union, Optional
13+
from __future__ import annotations
14+
15+
from typing import Any, Dict, Union, Optional, TYPE_CHECKING
1416

1517
from ..interfaces import (
1618
TenantConfig,
17-
ProviderConfig,
1819
CreateOrUpdateTenantOkResult,
1920
DeleteTenantOkResult,
2021
GetTenantOkResult,
2122
ListAllTenantsOkResult,
2223
CreateOrUpdateThirdPartyConfigOkResult,
2324
DeleteThirdPartyConfigOkResult,
2425
AssociateUserToTenantOkResult,
25-
AssociateUserToTenantErrorResult,
26+
AssociateUserToTenantUnknownUserIdErrorResult,
27+
AssociateUserToTenantEmailAlreadyExistsErrorResult,
28+
AssociateUserToTenantPhoneNumberAlreadyExistsErrorResult,
29+
AssociateUserToTenantThirdPartyUserAlreadyExistsErrorResult,
2630
DisassociateUserFromTenantOkResult,
2731
)
2832
from ..recipe import MultitenancyRecipe
2933

34+
if TYPE_CHECKING:
35+
from ..interfaces import ProviderConfig
36+
3037

3138
async def create_or_update_tenant(
3239
tenant_id: Optional[str],
@@ -108,7 +115,13 @@ async def associate_user_to_tenant(
108115
tenant_id: Optional[str],
109116
user_id: str,
110117
user_context: Optional[Dict[str, Any]] = None,
111-
) -> Union[AssociateUserToTenantOkResult, AssociateUserToTenantErrorResult]:
118+
) -> Union[
119+
AssociateUserToTenantOkResult,
120+
AssociateUserToTenantUnknownUserIdErrorResult,
121+
AssociateUserToTenantEmailAlreadyExistsErrorResult,
122+
AssociateUserToTenantPhoneNumberAlreadyExistsErrorResult,
123+
AssociateUserToTenantThirdPartyUserAlreadyExistsErrorResult,
124+
]:
112125
if user_context is None:
113126
user_context = {}
114127

supertokens_python/recipe/multitenancy/interfaces.py

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,29 @@ def __init__(
4040
self.third_party_enabled = third_party_enabled
4141
self.core_config = core_config
4242

43+
def to_json(self) -> Dict[str, Any]:
44+
res: Dict[str, Any] = {}
45+
if self.email_password_enabled is not None:
46+
res["emailPasswordEnabled"] = self.email_password_enabled
47+
if self.passwordless_enabled is not None:
48+
res["passwordlessEnabled"] = self.passwordless_enabled
49+
if self.third_party_enabled is not None:
50+
res["thirdPartyEnabled"] = self.third_party_enabled
51+
if self.core_config is not None:
52+
res["coreConfig"] = self.core_config
53+
return res
54+
4355

4456
class CreateOrUpdateTenantOkResult:
57+
status = "OK"
58+
4559
def __init__(self, created_new: bool):
4660
self.created_new = created_new
4761

4862

4963
class DeleteTenantOkResult:
64+
status = "OK"
65+
5066
def __init__(self, did_exist: bool):
5167
self.did_exist = did_exist
5268

@@ -67,51 +83,71 @@ def __init__(self, enabled: bool, providers: List[ProviderConfig]):
6783
self.providers = providers
6884

6985

70-
class GetTenantOkResult:
86+
class TenantConfigResponse:
7187
def __init__(
7288
self,
73-
email_password: EmailPasswordConfig,
89+
emailpassword: EmailPasswordConfig,
7490
passwordless: PasswordlessConfig,
7591
third_party: ThirdPartyConfig,
7692
core_config: Dict[str, Any],
7793
):
78-
self.email_password = email_password
94+
self.emailpassword = emailpassword
7995
self.passwordless = passwordless
8096
self.third_party = third_party
8197
self.core_config = core_config
8298

8399

100+
class GetTenantOkResult(TenantConfigResponse):
101+
status = "OK"
102+
103+
84104
class ListAllTenantsOkResult:
85-
def __init__(self, tenants: List[str]):
105+
status = "OK"
106+
107+
def __init__(self, tenants: List[TenantConfigResponse]):
86108
self.tenants = tenants
87109

88110

89111
class CreateOrUpdateThirdPartyConfigOkResult:
112+
status = "OK"
113+
90114
def __init__(self, created_new: bool):
91115
self.created_new = created_new
92116

93117

94118
class DeleteThirdPartyConfigOkResult:
119+
status = "OK"
120+
95121
def __init__(self, did_config_exist: bool):
96122
self.did_config_exist = did_config_exist
97123

98124

99-
class ListThirdPartyConfigsForThirdPartyIdOkResult:
100-
def __init__(self, providers: List[ProviderConfig]):
101-
self.providers = providers
102-
103-
104125
class AssociateUserToTenantOkResult:
126+
status = "OK"
127+
105128
def __init__(self, was_already_associated: bool):
106129
self.was_already_associated = was_already_associated
107130

108131

109-
class AssociateUserToTenantErrorResult:
110-
def __init__(self, status: str):
111-
self.status = status # FIXME: Create seperate errors for each kind
132+
class AssociateUserToTenantUnknownUserIdErrorResult:
133+
status = "UNKNOWN_USER_ID_ERROR"
134+
135+
136+
class AssociateUserToTenantEmailAlreadyExistsErrorResult:
137+
status = "EMAIL_ALREADY_EXISTS_ERROR"
138+
139+
140+
class AssociateUserToTenantPhoneNumberAlreadyExistsErrorResult:
141+
status = "PHONE_NUMBER_ALREADY_EXISTS_ERROR"
142+
143+
144+
class AssociateUserToTenantThirdPartyUserAlreadyExistsErrorResult:
145+
status = "THIRD_PARTY_USER_ALREADY_EXISTS_ERROR"
112146

113147

114148
class DisassociateUserFromTenantOkResult:
149+
status = "OK"
150+
115151
def __init__(self, was_associated: bool):
116152
self.was_associated = was_associated
117153

@@ -180,7 +216,13 @@ async def associate_user_to_tenant(
180216
tenant_id: Optional[str],
181217
user_id: str,
182218
user_context: Dict[str, Any],
183-
) -> Union[AssociateUserToTenantOkResult, AssociateUserToTenantErrorResult]:
219+
) -> Union[
220+
AssociateUserToTenantOkResult,
221+
AssociateUserToTenantUnknownUserIdErrorResult,
222+
AssociateUserToTenantEmailAlreadyExistsErrorResult,
223+
AssociateUserToTenantPhoneNumberAlreadyExistsErrorResult,
224+
AssociateUserToTenantThirdPartyUserAlreadyExistsErrorResult,
225+
]:
184226
pass
185227

186228
@abstractmethod

supertokens_python/recipe/multitenancy/recipe.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@
4444
from supertokens_python.querier import Querier
4545
from supertokens_python.types import GeneralErrorResponse
4646

47-
from supertokens_python.recipe.thirdparty.providers.config_utils import (
48-
find_and_create_provider_instance,
49-
merge_providers_from_core_and_static,
50-
)
51-
from supertokens_python.recipe.thirdparty.exceptions import ClientTypeNotFoundError
5247

5348
from .api import handle_login_methods_api
5449
from .constants import LOGIN_METHODS
@@ -218,6 +213,14 @@ async def login_methods_get(
218213
api_options: APIOptions,
219214
user_context: Dict[str, Any],
220215
) -> Union[LoginMethodsGetOkResult, GeneralErrorResponse]:
216+
from supertokens_python.recipe.thirdparty.providers.config_utils import (
217+
find_and_create_provider_instance,
218+
merge_providers_from_core_and_static,
219+
)
220+
from supertokens_python.recipe.thirdparty.exceptions import (
221+
ClientTypeNotFoundError,
222+
)
223+
221224
tenant_config = await api_options.recipe_implementation.get_tenant(
222225
tenant_id, user_context
223226
)
@@ -246,7 +249,7 @@ async def login_methods_get(
246249
)
247250

248251
return LoginMethodsGetOkResult(
249-
LoginMethodEmailPassword(tenant_config.email_password.enabled),
252+
LoginMethodEmailPassword(tenant_config.emailpassword.enabled),
250253
LoginMethodPasswordless(tenant_config.passwordless.enabled),
251254
LoginMethodThirdParty(
252255
tenant_config.third_party.enabled, final_provider_list

0 commit comments

Comments
 (0)