Files
Hermes_rocket.chat_Plugin/tests/live_rc/test_01_echo.py

105 lines
2.9 KiB
Python

"""
Test 01 — Echo / Smoke Test: Bot antwortet überhaupt.
Verifiziert die grundlegende Funktionsfähigkeit:
1. Bernd postet eine einfache Nachricht via REST API
2. MyTestBot (.45) empfängt via DDP und antwortet
3. Die Antwort wird via REST channels.history verifiziert
4. Message-Ownership: Antwort stammt von mytestbot (nicht von bernd)
"""
from __future__ import annotations
import logging
import time
import pytest
from tests.live_rc.conftest import (
assert_bot_message,
post_test_message,
)
from tests.live_rc.helpers.polling import (
wait_for_bot_message,
PollTimeout,
RateLimitSkip,
)
logger = logging.getLogger(__name__)
@pytest.mark.live_rc
def test_01_echo_bot_responds(
rc_client,
test_room_id: str,
bot_username: str,
bot_user_id: str,
cursor: str,
posted_message_ids: list,
rate_limiter,
cleanup_messages,
bot_status_check,
):
"""Smoke-Test: Bot antwortet auf eine einfache Nachricht.
Steps:
1. Poste "Hallo Bot, bitte antworte mit 'Echo-Test OK'"
2. Warte auf Antwort von mytestbot (max 18s)
3. Verifiziere: Antwort enthält Text
4. Verifiziere: Antwort stammt von mytestbot (nicht von bernd)
"""
# Step 1: Post test message
test_text = "Hallo Bot, bitte antworte mit 'Echo-Test OK'"
msg_id, _ = post_test_message(
rc_client, test_room_id, test_text,
posted_message_ids, rate_limiter,
)
logger.info("Test 01: posted message %s", msg_id[:12])
# Step 2: Wait for bot response
try:
response = wait_for_bot_message(
client=rc_client,
room_id=test_room_id,
bot_username=bot_username,
cursor=cursor,
timeout=120.0,
rate_limiter=rate_limiter,
)
except RateLimitSkip as e:
pytest.skip(f"Rate limit triggered: {e}")
except PollTimeout as e:
pytest.fail(
f"Bot did not respond within 18s. "
f"Check that .45 MyTestBot is running and subscribed to room {test_room_id[:12]}. "
f"Error: {e}"
)
# Step 3: Verify response has text
response_text = response.get("msg", "")
assert response_text, (
f"Bot response has no text. Full message: {response}"
)
logger.info("Test 01: bot responded with %d chars", len(response_text))
# Step 4: Verify message ownership — must be from mytestbot
assert_bot_message(
response,
expected_username=bot_username,
context="test_01_echo",
)
# Also verify the bot user ID matches
actual_user_id = response.get("u", {}).get("_id", "")
assert actual_user_id == bot_user_id, (
f"Bot user ID mismatch: expected {bot_user_id[:12]}, "
f"got {actual_user_id[:12]}"
)
# Track bot response for cleanup
response_id = response.get("_id", "")
if response_id:
posted_message_ids.append(response_id)
logger.info("Test 01 PASSED: echo smoke test OK")