Skip to content

Commit f791ae6

Browse files
committed
tests: add bootstrap idempotency and master-service linking tests
1 parent db86e5a commit f791ae6

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pytest
2+
from sqlalchemy import select, func
3+
4+
from bot.app.core.bootstrap import init_services, init_masters, DEFAULT_SERVICES, DEFAULT_MASTERS
5+
from bot.app.core.db import get_session
6+
from bot.app.domain import models
7+
8+
9+
@pytest.mark.asyncio
10+
async def test_init_services_idempotent():
11+
# first run
12+
await init_services()
13+
# second run should not duplicate services
14+
await init_services()
15+
async with get_session() as s:
16+
count_ = (await s.execute(select(func.count()).select_from(models.Service))).scalar_one()
17+
assert count_ == len(DEFAULT_SERVICES)
18+
19+
20+
@pytest.mark.asyncio
21+
async def test_init_masters_links_all_services():
22+
await init_services()
23+
await init_masters()
24+
async with get_session() as s:
25+
svc_count = (await s.execute(select(func.count()).select_from(models.Service))).scalar_one()
26+
mst_count = (await s.execute(select(func.count()).select_from(models.Master))).scalar_one()
27+
link_count = (
28+
await s.execute(select(func.count()).select_from(models.MasterService))
29+
).scalar_one()
30+
# each master linked to every service (>= because code skips existing)
31+
assert link_count >= svc_count * mst_count
32+
assert svc_count == len(DEFAULT_SERVICES)
33+
assert mst_count == len(DEFAULT_MASTERS)

0 commit comments

Comments
 (0)