Coverage for chatgpt_proxy / tests / test_markdown_gen.py: 98%
40 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-12 16:19 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-12 16:19 +0000
1# MIT License
2#
3# Copyright (c) 2025 Tuomo Kriikkula
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to deal
7# in the Software without restriction, including without limitation the rights
8# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9# copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in all
13# copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21# SOFTWARE.
23from typing import AsyncGenerator
25import asyncpg
26import pytest
27import pytest_asyncio
29from chatgpt_proxy.db import pool_acquire
30from chatgpt_proxy.tests import setup
31from chatgpt_proxy.tests.setup import common_test_setup
32from chatgpt_proxy.tests.setup import default_test_db_timeout
33from chatgpt_proxy.utils import utcnow
35common_test_setup()
37from chatgpt_proxy.app import get_chat_messages_markdown_table # noqa: E402
38from chatgpt_proxy.app import get_kills_markdown_table # noqa: E402
39from chatgpt_proxy.app import get_scoreboard_markdown_table # noqa: E402
41_db_timeout = default_test_db_timeout
44@pytest_asyncio.fixture
45async def markdown_gen_fixture() -> AsyncGenerator[asyncpg.Connection]:
46 raise NotImplementedError
49@pytest_asyncio.fixture
50async def maintenance_fixture(
51) -> AsyncGenerator[asyncpg.Connection]:
52 db_fixture_pool = await asyncpg.create_pool(
53 dsn=setup.db_base_url,
54 min_size=1,
55 max_size=1,
56 timeout=_db_timeout,
57 )
59 async with pool_acquire(db_fixture_pool, timeout=_db_timeout) as conn:
60 await setup.drop_test_db(conn, timeout=_db_timeout)
61 await setup.create_test_db(conn, timeout=_db_timeout)
63 test_db_pool = await asyncpg.create_pool(
64 dsn=setup.db_test_url,
65 min_size=1,
66 max_size=1,
67 timeout=_db_timeout,
68 )
70 async with pool_acquire(
71 test_db_pool,
72 timeout=_db_timeout,
73 ) as conn:
74 async with conn.transaction():
75 await setup.initialize_test_db(conn, timeout=_db_timeout)
76 await setup.seed_test_db(conn, timeout=_db_timeout)
78 yield conn
80 async with pool_acquire(db_fixture_pool, timeout=_db_timeout) as conn:
81 await setup.drop_test_db(conn, timeout=_db_timeout)
83 await db_fixture_pool.close()
84 await test_db_pool.close()
87@pytest.mark.asyncio
88async def test_markdown_gen(maintenance_fixture):
89 conn = maintenance_fixture
91 # TODO: fill DB with kills, players, etc.
93 now_todo = utcnow() # TODO
94 _ = await get_scoreboard_markdown_table(conn, "TODO")
95 _ = await get_kills_markdown_table(conn, "TODO", now_todo)
96 _ = await get_chat_messages_markdown_table(conn, "TODO", now_todo)