|
| 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) |
0 commit comments