Skip to content

Commit 23b21b0

Browse files
committed
add basic tests
1 parent 330841c commit 23b21b0

2 files changed

Lines changed: 139 additions & 0 deletions

File tree

tests/test_async_session.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import os
2+
3+
import pytest
4+
import pytest_asyncio
5+
6+
import lpdb
7+
from lpdb.async_session import AsyncLpdbSession
8+
9+
10+
KEY = os.getenv("API_KEY")
11+
12+
13+
@pytest_asyncio.fixture
14+
async def async_session() -> AsyncLpdbSession:
15+
return AsyncLpdbSession(KEY)
16+
17+
18+
@pytest.mark.asyncio
19+
async def test_get_wikis(async_session: AsyncLpdbSession):
20+
wikis = await async_session.get_wikis()
21+
assert isinstance(wikis, set)
22+
# Test with top 5 wikis
23+
assert {
24+
"dota2",
25+
"counterstrike",
26+
"valorant",
27+
"mobilelegends",
28+
"leagueoflegends",
29+
}.issubset(wikis)
30+
31+
32+
@pytest.mark.asyncio
33+
async def test_make_request_invalid_key():
34+
with pytest.raises(lpdb.LpdbError):
35+
async with AsyncLpdbSession("some_random_gibberish") as async_session:
36+
await async_session.make_request(
37+
"match",
38+
"valorant",
39+
conditions="[[parent::VCT/2025/Stage_1/Masters]]",
40+
streamurls="true",
41+
)
42+
43+
44+
@pytest.mark.asyncio
45+
async def test_make_request_invalid_type(async_session: AsyncLpdbSession):
46+
with pytest.raises(ValueError):
47+
await async_session.make_request("match2", "valorant")
48+
49+
50+
@pytest.mark.asyncio
51+
async def test_make_request(async_session: AsyncLpdbSession):
52+
responses = await async_session.make_request(
53+
"match",
54+
"valorant",
55+
conditions="[[parent::VCT/2025/Stage_1/Masters]]",
56+
streamurls="true",
57+
)
58+
59+
for response in responses:
60+
assert response["parent"] == "VCT/2025/Stage_1/Masters"
61+
62+
63+
@pytest.mark.asyncio
64+
async def test_get_team_template(async_session: AsyncLpdbSession):
65+
template = await async_session.get_team_template("valorant", "t1")
66+
assert template["page"] == "T1"
67+
68+
69+
@pytest.mark.asyncio
70+
async def test_get_team_templates(async_session: AsyncLpdbSession):
71+
templates = await async_session.get_team_template_list("valorant")
72+
assert isinstance(templates, list)
73+
for template in templates:
74+
assert isinstance(template["page"], str)

tests/test_session.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import os
2+
3+
import pytest
4+
5+
import lpdb
6+
7+
KEY = os.getenv("API_KEY")
8+
9+
10+
@pytest.fixture
11+
def session() -> lpdb.LpdbSession:
12+
return lpdb.LpdbSession(KEY)
13+
14+
15+
def test_get_wikis(session: lpdb.LpdbSession):
16+
wikis = session.get_wikis()
17+
assert isinstance(wikis, set)
18+
# Test with top 5 wikis
19+
assert {
20+
"dota2",
21+
"counterstrike",
22+
"valorant",
23+
"mobilelegends",
24+
"leagueoflegends",
25+
}.issubset(wikis)
26+
27+
28+
def test_make_request_invalid_key():
29+
session = lpdb.LpdbSession("some_random_gibberish")
30+
with pytest.raises(lpdb.LpdbError):
31+
session.make_request(
32+
"match",
33+
"leagueoflegends",
34+
conditions="[[parent::World_Championship/2025]]",
35+
streamurls="true",
36+
)
37+
38+
39+
def test_make_request_invalid_type(session: lpdb.LpdbSession):
40+
with pytest.raises(ValueError):
41+
session.make_request("match2", "leagueoflegends")
42+
43+
44+
def test_make_request(session: lpdb.LpdbSession):
45+
responses = session.make_request(
46+
"match",
47+
"leagueoflegends",
48+
conditions="[[parent::World_Championship/2025]]",
49+
streamurls="true",
50+
)
51+
52+
for response in responses:
53+
assert response["parent"] == "World_Championship/2025"
54+
55+
56+
def test_get_team_template(session: lpdb.LpdbSession):
57+
template = session.get_team_template("leagueoflegends", "t1")
58+
assert template["page"] == "T1"
59+
60+
61+
def test_get_team_templates(session: lpdb.LpdbSession):
62+
templates = session.get_team_template_list("leagueoflegends")
63+
assert isinstance(templates, list)
64+
for template in templates:
65+
assert isinstance(template["page"], str)

0 commit comments

Comments
 (0)