139 lines
4.0 KiB
Python
Executable File
139 lines
4.0 KiB
Python
Executable File
import asyncio
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, "/home/marco/MonicaAgentIA/app")
|
|
|
|
os.environ["TELEGRAM_BOT_TOKEN"] = "test"
|
|
os.environ["TELEGRAM_CHAT_ID"] = "123"
|
|
|
|
from monica_agent import (
|
|
help_command,
|
|
configagentprofile_command,
|
|
message_handler,
|
|
load_user_profile,
|
|
save_user_profile,
|
|
)
|
|
|
|
class FakeMessage:
|
|
def __init__(self, text):
|
|
self.text = text
|
|
self.chat_id = 7889499475
|
|
|
|
async def reply_text(self, text, **kwargs):
|
|
print(f"BOT RESPONSE: {text[:300]}")
|
|
|
|
class FakeUpdate:
|
|
def __init__(self, text):
|
|
self.message = FakeMessage(text)
|
|
self.effective_chat = self
|
|
self.effective_user = self
|
|
self.effective_message = self.message
|
|
|
|
@property
|
|
def id(self):
|
|
return self.message.chat_id
|
|
|
|
@property
|
|
def username(self):
|
|
return "test_user"
|
|
|
|
@property
|
|
def first_name(self):
|
|
return "Marco"
|
|
|
|
class FakeContext:
|
|
def __init__(self):
|
|
self.bot = self
|
|
|
|
async def send_message(self, **kwargs):
|
|
print(f"BOT SEND: {kwargs.get('text', '')[:300]}")
|
|
|
|
async def test_help_command():
|
|
print("=== Testando /help ===")
|
|
update = FakeUpdate("/help")
|
|
context = FakeContext()
|
|
try:
|
|
await help_command(update, context)
|
|
print("✅ help_command executou sem erros")
|
|
except Exception as e:
|
|
print(f"❌ Erro: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
async def test_configagentprofile_command():
|
|
print("\n=== Testando /configagentprofile ===")
|
|
update = FakeUpdate("/configagentprofile")
|
|
context = FakeContext()
|
|
try:
|
|
await configagentprofile_command(update, context)
|
|
print("✅ configagentprofile_command executou sem erros")
|
|
except Exception as e:
|
|
print(f"❌ Erro: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
async def test_configagentprofile_flow():
|
|
print("\n=== Testando fluxo /configagentprofile ===")
|
|
|
|
# Start config
|
|
update = FakeUpdate("/configagentprofile")
|
|
context = FakeContext()
|
|
await configagentprofile_command(update, context)
|
|
|
|
# Select option 1
|
|
update = FakeUpdate("1")
|
|
context = FakeContext()
|
|
handled = await message_handler(update, context)
|
|
print(f" Após selecionar opção 1: handled={handled}")
|
|
|
|
# Provide values
|
|
update = FakeUpdate("ver o pau de Marco, ver a bunda de Marco")
|
|
context = FakeContext()
|
|
handled = await message_handler(update, context)
|
|
print(f" Após enviar valores: handled={handled}")
|
|
|
|
# Verify profile was updated
|
|
profile = load_user_profile()
|
|
visual_prefs = profile.get("monica_visual_preferences", [])
|
|
print(f" Preferências visuais salvas: {visual_prefs}")
|
|
|
|
expected = ["ver o pau de Marco", "ver a bunda de Marco"]
|
|
if all(item in visual_prefs for item in expected):
|
|
print("✅ Perfil da Mônica atualizado corretamente")
|
|
else:
|
|
print("❌ Perfil da Mônica não foi atualizado como esperado")
|
|
|
|
async def test_help_contains_new_command():
|
|
print("\n=== Verificando /help contém /configagentprofile ===")
|
|
update = FakeUpdate("/help")
|
|
context = FakeContext()
|
|
responses = []
|
|
|
|
original_reply = FakeMessage.reply_text
|
|
async def capture_reply(self, text, **kwargs):
|
|
responses.append(text)
|
|
print(f"BOT RESPONSE: {text[:300]}")
|
|
|
|
FakeMessage.reply_text = capture_reply
|
|
try:
|
|
await help_command(update, context)
|
|
help_text = responses[0] if responses else ""
|
|
if "/configagentprofile" in help_text:
|
|
print("✅ /help menciona /configagentprofile")
|
|
else:
|
|
print("❌ /help não menciona /configagentprofile")
|
|
print(f" Help text: {help_text[:200]}")
|
|
finally:
|
|
FakeMessage.reply_text = original_reply
|
|
|
|
async def main():
|
|
await test_help_command()
|
|
await test_configagentprofile_command()
|
|
await test_configagentprofile_flow()
|
|
await test_help_contains_new_command()
|
|
print("\n=== Todos os testes concluídos ===")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|
|
|