Skip to content

Commit 1dca00f

Browse files
committed
fix: Multitenancy tests for userroles, thirdparty, and emailpassword
1 parent 08903a6 commit 1dca00f

File tree

7 files changed

+55
-15
lines changed

7 files changed

+55
-15
lines changed

supertokens_python/recipe/thirdparty/provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def __init__(
226226
force_pkce: bool = False,
227227
additional_config: Optional[Dict[str, Any]] = None,
228228
# CommonProviderConfig:
229+
third_party_id: Optional[str] = None,
229230
name: Optional[str] = None,
230231
authorization_endpoint: Optional[str] = None,
231232
authorization_endpoint_query_params: Optional[
@@ -261,7 +262,7 @@ def __init__(
261262
)
262263
CommonProviderConfig.__init__(
263264
self,
264-
"temp",
265+
third_party_id or "", # FIXME?
265266
name,
266267
authorization_endpoint,
267268
authorization_endpoint_query_params,

supertokens_python/recipe/thirdparty/providers/config_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ def merge_providers_from_core_and_static(
166166
merged_provider_input.override = provider_input_from_static.override
167167
break
168168

169+
merged_providers.append(merged_provider_input)
170+
169171
return merged_providers
170172

171173

supertokens_python/recipe/thirdparty/providers/custom.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def get_provider_config_for_client(
4343
force_pkce=client_config.force_pkce,
4444
additional_config=client_config.additional_config,
4545
# CommonProviderConfig
46+
third_party_id=config.third_party_id,
4647
name=config.name,
4748
authorization_endpoint=config.authorization_endpoint,
4849
authorization_endpoint_query_params=config.authorization_endpoint_query_params,

supertokens_python/recipe/thirdparty/recipe_implementation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async def get_users_by_email(
7777
user["id"],
7878
user["email"],
7979
user["timeJoined"],
80-
response["user"]["tenantIds"],
80+
user["tenantIds"],
8181
ThirdPartyInfo(
8282
user["thirdParty"]["userId"], user["thirdParty"]["id"]
8383
),

tests/emailpassword/test_multitenancy.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from supertokens_python.recipe.multitenancy.interfaces import TenantConfig
3434

3535
from tests.utils import get_st_init_args
36-
from tests.utils import setup_function, teardown_function, setup_multitenancy_feature
36+
from tests.utils import setup_function, teardown_function, setup_multitenancy_feature, start_st
3737

3838

3939
_ = setup_function
@@ -42,7 +42,7 @@
4242
pytestmark = mark.asyncio
4343

4444

45-
async def test_multitenancy_in_user_roles():
45+
async def test_multitenancy_in_emailpassword():
4646
# test that different roles can be assigned for the same user for each tenant
4747
args = get_st_init_args(
4848
[
@@ -53,6 +53,8 @@ async def test_multitenancy_in_user_roles():
5353
]
5454
)
5555
init(**args) # type: ignore
56+
start_st()
57+
5658
setup_multitenancy_feature()
5759

5860
await create_or_update_tenant("t1", TenantConfig(email_password_enabled=True))
@@ -77,14 +79,16 @@ async def test_multitenancy_in_user_roles():
7779

7880
# sign in
7981
ep_user1 = await sign_in("[email protected]", "password1", "t1")
80-
ep_user2 = await sign_in("[email protected]", "password1", "t2")
81-
ep_user3 = await sign_in("[email protected]", "password1", "t3")
82+
ep_user2 = await sign_in("[email protected]", "password2", "t2")
83+
ep_user3 = await sign_in("[email protected]", "password3", "t3")
8284

8385
assert isinstance(ep_user1, SignInOkResult)
8486
assert isinstance(ep_user2, SignInOkResult)
8587
assert isinstance(ep_user3, SignInOkResult)
8688

87-
assert ep_user1.user.user_id == user2.user.user_id == user3.user.user_id
89+
assert ep_user1.user.user_id == user1.user.user_id
90+
assert ep_user2.user.user_id == user2.user.user_id
91+
assert ep_user3.user.user_id == user3.user.user_id
8892

8993
# get user by id:
9094
g_user1 = await get_user_by_id(user1.user.user_id)
@@ -106,8 +110,8 @@ async def test_multitenancy_in_user_roles():
106110

107111
# create password reset token:
108112
pless_reset_link1 = await create_reset_password_token(user1.user.user_id, "t1")
109-
pless_reset_link2 = await create_reset_password_token(user1.user.user_id, "t2")
110-
pless_reset_link3 = await create_reset_password_token(user1.user.user_id, "t3")
113+
pless_reset_link2 = await create_reset_password_token(user2.user.user_id, "t2")
114+
pless_reset_link3 = await create_reset_password_token(user3.user.user_id, "t3")
111115

112116
assert isinstance(pless_reset_link1, CreateResetPasswordOkResult)
113117
assert isinstance(pless_reset_link2, CreateResetPasswordOkResult)

tests/thirdparty/test_multitenancy.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from supertokens_python.recipe.multitenancy.interfaces import TenantConfig
2929

3030
from tests.utils import get_st_init_args
31-
from tests.utils import setup_function, teardown_function, setup_multitenancy_feature
31+
from tests.utils import setup_function, teardown_function, setup_multitenancy_feature, start_st
3232

3333

3434
_ = setup_function
@@ -37,10 +37,11 @@
3737
pytestmark = mark.asyncio
3838

3939

40-
async def test_multitenancy_functions():
40+
async def test_thirtyparty_multitenancy_functions():
4141
# test that different roles can be assigned for the same user for each tenant
4242
args = get_st_init_args([session.init(), thirdparty.init(), multitenancy.init()])
4343
init(**args) # type: ignore
44+
start_st()
4445
setup_multitenancy_feature()
4546

4647
await create_or_update_tenant("t1", TenantConfig(third_party_enabled=True))
@@ -115,13 +116,43 @@ async def test_multitenancy_functions():
115116

116117

117118
async def test_get_provider():
118-
args = get_st_init_args([session.init(), thirdparty.init(), multitenancy.init()])
119+
args = get_st_init_args([
120+
session.init(),
121+
thirdparty.init(
122+
sign_in_and_up_feature=thirdparty.SignInAndUpFeature(
123+
providers=[
124+
thirdparty.ProviderInput(
125+
thirdparty.ProviderConfig(
126+
third_party_id="google",
127+
)
128+
),
129+
thirdparty.ProviderInput(
130+
thirdparty.ProviderConfig(
131+
third_party_id="facebook",
132+
)
133+
),
134+
thirdparty.ProviderInput(
135+
thirdparty.ProviderConfig(
136+
third_party_id="discord",
137+
)
138+
),
139+
thirdparty.ProviderInput(
140+
thirdparty.ProviderConfig(
141+
third_party_id="linkedin",
142+
)
143+
),
144+
]
145+
)
146+
),
147+
multitenancy.init()
148+
])
119149
init(**args)
150+
start_st()
120151
setup_multitenancy_feature()
121152

122153
await create_or_update_tenant("t1", TenantConfig(third_party_enabled=True))
123-
await create_or_update_tenant("t1", TenantConfig(third_party_enabled=True))
124-
await create_or_update_tenant("t1", TenantConfig(third_party_enabled=True))
154+
await create_or_update_tenant("t2", TenantConfig(third_party_enabled=True))
155+
await create_or_update_tenant("t3", TenantConfig(third_party_enabled=True))
125156

126157
await create_or_update_third_party_config(
127158
"t1",

tests/userroles/test_multitenancy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
)
2929

3030
from tests.utils import get_st_init_args
31-
from tests.utils import setup_function, teardown_function, setup_multitenancy_feature
31+
from tests.utils import setup_function, teardown_function, setup_multitenancy_feature, start_st
3232

3333

3434
_ = setup_function
@@ -48,6 +48,7 @@ async def test_multitenancy_in_user_roles():
4848
]
4949
)
5050
init(**args) # type: ignore
51+
start_st()
5152
setup_multitenancy_feature()
5253

5354
await create_or_update_tenant("t1", TenantConfig(email_password_enabled=True))

0 commit comments

Comments
 (0)