Created At: 2026-11-18T08:45:03Z Completed At: 2026-11-18T08:45:12Z Command exited with code 1. Command output: ============================= test session starts ============================== platform linux -- Python 3.12.3, pytest-9.2.0, pluggy-1.7.0 -- /root/telegram-saas/.venv/bin/python3 cachedir: .pytest_cache rootdir: /root/telegram-saas configfile: pyproject.toml plugins: anyio-4.16.0, asyncio-1.5.0 asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function collecting ... collected 1 item tests/integration/test_multi_bot_engine.py::test_multi_tenant_multi_bot_engine_lifecycle FAILED [100%] =================================== FAILURES =================================== _________________ test_multi_tenant_multi_bot_engine_lifecycle _________________ async_client = db_session = @pytest.mark.asyncio async def test_multi_tenant_multi_bot_engine_lifecycle( async_client: AsyncClient, db_session: AsyncSession, ): # ------------------------------------------------------------- # 1. Setup Mock Bot Tokens # ------------------------------------------------------------- token_a1 = f"token_a1_{uuid.uuid4().hex[:8]}_test" token_a2 = f"token_a2_{uuid.uuid4().hex[:8]}_test" token_b1 = f"token_b1_{uuid.uuid4().hex[:8]}_test" bot_uname_a1 = f"alpha_bot_1_{uuid.uuid4().hex[:6]}" bot_uname_a2 = f"alpha_bot_2_{uuid.uuid4().hex[:6]}" bot_uname_b1 = f"beta_bot_1_{uuid.uuid4().hex[:6]}" TelegramApiService.register_mock_bot(token_a1, bot_uname_a1, "Alpha One") TelegramApiService.register_mock_bot(token_a2, bot_uname_a2, "Alpha Two") TelegramApiService.register_mock_bot(token_b1, bot_uname_b1, "Beta One") # ------------------------------------------------------------- # 2. Register User A & Tenant Alpha # ------------------------------------------------------------- user_a_email = f"user_a_{uuid.uuid4().hex[:6]}@example.com" resp_a = await async_client.post( "/api/v1/auth/register", json={"email": user_a_email, "password": "PasswordA123!", "full_name": "Alice Alpha"}, ) token_user_a = resp_a.json()["data"]["access_token"] tenant_a_resp = await async_client.post( "/api/v1/tenants", headers={"Authorization": f"Bearer {token_user_a}"}, json={"name": "Tenant Alpha Org", "slug": f"alpha-{uuid.uuid4().hex[:6]}"}, ) tenant_a_id = tenant_a_resp.json()["data"]["id"] headers_a = { "Authorization": f"Bearer {token_user_a}", "X-Tenant-ID": str(tenant_a_id), } # Set Tenant Alpha to Pro plan to support multiple bots under entitlement limits from datetime import datetime, timedelta, timezone from modules.billing.service import BillingService from modules.tenants.models import Tenant b_serv = BillingService(db_session) await b_serv.seed_default_plans() now_dt = datetime.now(timezone.utc) await b_serv.repo.create_subscription( tenant_id=uuid.UUID(tenant_a_id), plan_id="pro", status="active", current_period_start=now_dt, current_period_end=now_dt + timedelta(days=30), ) t_obj = await db_session.get(Tenant, uuid.UUID(tenant_a_id)) if t_obj: t_obj.plan_id = "pro" await db_session.commit() # ------------------------------------------------------------- # 3. Register User B & Tenant Beta # ------------------------------------------------------------- user_b_email = f"user_b_{uuid.uuid4().hex[:6]}@example.com" resp_b = await async_client.post( "/api/v1/auth/register", json={"email": user_b_email, "password": "PasswordB123!", "full_name": "Bob Beta"}, ) token_user_b = resp_b.json()["data"]["access_token"] tenant_b_resp = await async_client.post( "/api/v1/tenants", headers={"Authorization": f"Bearer {token_user_b}"}, json={"name": "Tenant Beta Org", "slug": f"beta-{uuid.uuid4().hex[:6]}"}, ) tenant_b_id = tenant_b_resp.json()["data"]["id"] headers_b = { "Authorization": f"Bearer {token_user_b}", "X-Tenant-ID": str(tenant_b_id), } # ------------------------------------------------------------- # 4. Tenant Alpha Registers Bot A1 and Bot A2 # ------------------------------------------------------------- reg_a1 = await async_client.post( "/api/v1/bots", headers=headers_a, json={"token": token_a1, "name": "Alpha Bot 1", "default_locale": "en"}, ) assert reg_a1.status_code == 201, reg_a1.text bot_a1_data = reg_a1.json()["data"] bot_a1_id = bot_a1_data["id"] assert bot_a1_data["username"] == bot_uname_a1 assert bot_a1_data["webhook_active"] is True # Ensure raw token was NEVER returned assert "token" not in bot_a1_data assert "encrypted_token" not in bot_a1_data reg_a2 = await async_client.post( "/api/v1/bots", headers=headers_a, json={"token": token_a2, "name": "Alpha Bot 2", "default_locale": "hi"}, ) assert reg_a2.status_code == 201 bot_a2_id = reg_a2.json()["data"]["id"] # ------------------------------------------------------------- # 5. Tenant Beta Registers Bot B1 # ------------------------------------------------------------- reg_b1 = await async_client.post( "/api/v1/bots", headers=headers_b, json={"token": token_b1, "name": "Beta Bot 1", "default_locale": "en"}, ) assert reg_b1.status_code == 201 bot_b1_id = reg_b1.json()["data"]["id"] # Duplicate registration of same username must fail reg_dup = await async_client.post( "/api/v1/bots", headers=headers_b, json={"token": token_a1, "name": "Duplicate Bot"}, ) > assert reg_dup.status_code == 409 E assert 429 == 409 E + where 429 = .status_code tests/integration/test_multi_bot_engine.py:135: AssertionError ----------------------------- Captured stdout call ----------------------------- 2026-11-18 08:45:10 [info ] dispatching_domain_event event_id=95e3a3a4-03b0-4baf-a15e-ed51976e328c event_type=UserRegisteredEvent handlers_count=0 2026-11-18 08:45:10 [info ] dispatching_domain_event event_id=a9bb1651-f30f-42ba-9aa9-d58c411b6620 event_type=TenantCreatedEvent handlers_count=0 2026-11-18 08:45:11 [info ] dispatching_domain_event event_id=0fb669aa-ead3-4713-808f-4c58d134e07a event_type=UserRegisteredEvent handlers_count=0 2026-11-18 08:45:11 [info ] dispatching_domain_event event_id=2a029a42-b28e-477d-9628-7cd1f727378a event_type=TenantCreatedEvent handlers_count=0 2026-11-18 08:45:11 [info ] bot_registered_successfully bot_id=d68b2449-7383-4159-b614-815da292713c tenant_id=23228578-1450-45d1-a766-ab234fc9fea8 username=alpha_bot_1_19d184 2026-11-18 08:45:11 [info ] bot_registered_successfully bot_id=96844735-a22e-472d-8e2b-9d93747f908c tenant_id=23228578-1450-45d1-a766-ab234fc9fea8 username=alpha_bot_2_e18285 2026-11-18 08:45:11 [info ] bot_registered_successfully bot_id=58ca7bb5-cb9c-41d1-a86b-fe84ca0b6fd3 tenant_id=a14996ae-983c-462d-9823-f889b9a3bdb9 username=beta_bot_1_019dbc 2026-11-18 08:45:11 [warning ] app_exception_handled error_code=QUOTA_EXCEEDED message="Plan 'Free Tier' limit of 1 active bot(s) reached. Please upgrade your subscription to connect more bots." method=POST path=/api/v1/bots =========================== short test summary info ============================ FAILED tests/integration/test_multi_bot_engine.py::test_multi_tenant_multi_bot_engine_lifecycle ============================== 1 failed in 1.16s ===============================