Skip to content

Commit acfadf8

Browse files
committed
test verification service
1 parent dbe2c32 commit acfadf8

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/test_verification.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import pytest
2+
3+
from clerk import errors
4+
5+
6+
@pytest.mark.asyncio
7+
class TestVerify:
8+
@pytest.mark.parametrize("num_sessions", [1])
9+
async def test_verify_with_session_id(self, client, httpserver, session_data):
10+
expected_session = session_data[1][0]
11+
session_json = session_data[0][0]
12+
httpserver.expect_request(
13+
f"/sessions/{expected_session.id}/verify/", "POST", json={"token": "some-token"}
14+
).respond_with_json(session_json)
15+
16+
session = await client.verification.verify("some-token", expected_session.id)
17+
assert session == expected_session
18+
19+
@pytest.mark.parametrize("num_sessions", [1])
20+
@pytest.mark.parametrize("num_clients", [1])
21+
async def test_verify_without_session_id_and_active_session(
22+
self, client, httpserver, session_data, clients_data
23+
):
24+
expected_session = session_data[1][0]
25+
session_json = session_data[0][0]
26+
clients_json = clients_data[0][0]
27+
clients_json["id"] = expected_session.client_id
28+
clients_json["last_active_session_id"] = expected_session.id
29+
30+
httpserver.expect_request(
31+
"/clients/verify/", "POST", json={"token": "some-token"}
32+
).respond_with_json(clients_json)
33+
httpserver.expect_request(f"/sessions/{expected_session.id}/", "GET").respond_with_json(
34+
session_json
35+
)
36+
37+
session = await client.verification.verify("some-token")
38+
assert session == expected_session
39+
40+
@pytest.mark.parametrize("num_clients", [1])
41+
async def test_verify_without_session_id_and_no_active_session(
42+
self, client, httpserver, clients_data
43+
):
44+
clients_json = clients_data[0][0]
45+
clients_json["last_active_session_id"] = None
46+
47+
httpserver.expect_request(
48+
"/clients/verify/", "POST", json={"token": "some-token"}
49+
).respond_with_json(clients_json)
50+
51+
with pytest.raises(errors.NoActiveSessionException):
52+
await client.verification.verify("some-token")

0 commit comments

Comments
 (0)