Skip to content

Commit

Permalink
fixes more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rishabhpoddar committed Sep 25, 2024
1 parent 85221ea commit 19a13bf
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
6 changes: 3 additions & 3 deletions tests/sessions/claims/test_create_new_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def test_create_access_token_payload_with_session_claims(timestamp: int):
s = await create_new_session(dummy_req, "public", RecipeUserId("someId"))

payload = s.get_access_token_payload()
assert len(payload) == 10
assert len(payload) == 11
assert payload["st-true"] == {"v": True, "t": timestamp}


Expand All @@ -45,7 +45,7 @@ async def test_should_create_access_token_payload_with_session_claims_with_an_no
s = await create_new_session(dummy_req, "public", RecipeUserId("someId"))

payload = s.get_access_token_payload()
assert len(payload) == 9
assert len(payload) == 10
assert payload.get("st-true") is None


Expand All @@ -70,6 +70,6 @@ async def test_should_merge_claims_and_passed_access_token_payload_obj(timestamp
s = await create_new_session(dummy_req, "public", RecipeUserId("someId"))

payload = s.get_access_token_payload()
assert len(payload) == 11
assert len(payload) == 12
assert payload["st-true"] == {"v": True, "t": timestamp}
assert payload["user-custom-claim"] == "foo"
11 changes: 9 additions & 2 deletions tests/sessions/claims/test_primitive_array_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,16 @@ async def test_primitive_claim_matching__add_to_payload():
async def test_primitive_claim_fetch_value_params_correct():
claim = PrimitiveArrayClaim("key", sync_fetch_value)
user_id, ctx = "user_id", {}
await claim.build(user_id, RecipeUserId(user_id), DEFAULT_TENANT_ID, ctx)
recipe_user_id = RecipeUserId(user_id)
await claim.build(user_id, recipe_user_id, DEFAULT_TENANT_ID, ctx)
assert sync_fetch_value.call_count == 1
assert (user_id, DEFAULT_TENANT_ID, ctx) == sync_fetch_value.call_args_list[0][
assert (
user_id,
recipe_user_id,
DEFAULT_TENANT_ID,
ctx,
{},
) == sync_fetch_value.call_args_list[0][
0
] # extra [0] refers to call params

Expand Down
8 changes: 7 additions & 1 deletion tests/sessions/claims/test_primitive_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ async def test_primitive_claim_fetch_value_params_correct():
user_id, ctx = "user_id", {}
await claim.build(user_id, RecipeUserId(user_id), DEFAULT_TENANT_ID, ctx)
assert sync_fetch_value.call_count == 1
assert (user_id, DEFAULT_TENANT_ID, ctx) == sync_fetch_value.call_args_list[0][
assert (
user_id,
RecipeUserId(user_id),
DEFAULT_TENANT_ID,
ctx,
{},
) == sync_fetch_value.call_args_list[0][
0
] # extra [0] refers to call params

Expand Down
4 changes: 2 additions & 2 deletions tests/sessions/claims/test_set_claim_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async def test_should_overwrite_claim_value(timestamp: int):
s = await create_new_session(dummy_req, "public", RecipeUserId("someId"))

payload = s.get_access_token_payload()
assert len(payload) == 10
assert len(payload) == 11
assert payload["st-true"] == {"t": timestamp, "v": True}

await s.set_claim_value(TrueClaim, False)
Expand All @@ -81,7 +81,7 @@ async def test_should_overwrite_claim_value_using_session_handle(timestamp: int)
s = await create_new_session(dummy_req, "public", RecipeUserId("someId"))

payload = s.get_access_token_payload()
assert len(payload) == 10
assert len(payload) == 11
assert payload["st-true"] == {"t": timestamp, "v": True}

await set_claim_value(s.get_handle(), TrueClaim, False)
Expand Down
2 changes: 1 addition & 1 deletion tests/sessions/claims/test_verify_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ async def test_should_allow_if_assert_claims_returns_no_error(
assert validators == [validator]
assert ctx["_default"]["request"]
recipe_impl_mock.validate_claims.assert_called_once_with( # type: ignore
"test_user_id", {}, [validator], ctx
"test_user_id", RecipeUserId("test_user_id"), {}, [validator], ctx
)


Expand Down
4 changes: 2 additions & 2 deletions tests/sessions/claims/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from supertokens_python.types import RecipeUserId
from tests.utils import st_init_common_args

TrueClaim = BooleanClaim("st-true", fetch_value=lambda _, __, ___: True) # type: ignore
NoneClaim = BooleanClaim("st-none", fetch_value=lambda _, __, ___: None) # type: ignore
TrueClaim = BooleanClaim("st-true", fetch_value=lambda _, __, ___, _____, ______: True)
NoneClaim = BooleanClaim("st-none", fetch_value=lambda _, __, ___, _____, ______: None)


def session_functions_override_with_claim(
Expand Down
2 changes: 1 addition & 1 deletion tests/sessions/test_access_token_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def test_access_token_v4():
False,
)
assert res["userId"] == "user-id"
assert parsed_info.version == 4
assert parsed_info.version == 5


async def test_parsing_access_token_v2():
Expand Down

0 comments on commit 19a13bf

Please sign in to comment.