194 lines
6.0 KiB
Python
Executable File
194 lines
6.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 (
|
|
editarperfil_command,
|
|
editaragente_command,
|
|
message_handler,
|
|
load_user_profile,
|
|
save_user_profile,
|
|
is_editing_user_profile,
|
|
editing_user_profile_field,
|
|
is_editing_agent_profile,
|
|
editing_agent_profile_field,
|
|
editing_agent_profile_action,
|
|
)
|
|
|
|
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_editarperfil_command():
|
|
print("=== Testando /editarperfil ===")
|
|
update = FakeUpdate("/editarperfil")
|
|
context = FakeContext()
|
|
try:
|
|
await editarperfil_command(update, context)
|
|
print("✅ editarperfil_command executou sem erros")
|
|
except Exception as e:
|
|
print(f"❌ Erro: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
async def test_editarperfil_flow():
|
|
print("\n=== Testando fluxo /editarperfil ===")
|
|
update = FakeUpdate("/editarperfil")
|
|
context = FakeContext()
|
|
await editarperfil_command(update, context)
|
|
|
|
update = FakeUpdate("1")
|
|
context = FakeContext()
|
|
handled = await message_handler(update, context)
|
|
print(f" Após selecionar opção 1: handled={handled}")
|
|
|
|
update = FakeUpdate("João")
|
|
context = FakeContext()
|
|
handled = await message_handler(update, context)
|
|
print(f" Após enviar nome: handled={handled}")
|
|
|
|
profile = load_user_profile()
|
|
print(f" Nome salvo: {profile.get('name')}")
|
|
if profile.get("name") == "João":
|
|
print("✅ Perfil do usuário atualizado corretamente")
|
|
else:
|
|
print("❌ Perfil do usuário não foi atualizado")
|
|
|
|
async def test_editaragente_command():
|
|
print("\n=== Testando /editaragente ===")
|
|
update = FakeUpdate("/editaragente")
|
|
context = FakeContext()
|
|
try:
|
|
await editaragente_command(update, context)
|
|
print("✅ editaragente_command executou sem erros")
|
|
except Exception as e:
|
|
print(f"❌ Erro: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
async def test_editaragente_remove():
|
|
print("\n=== Testando remoção no /editaragente ===")
|
|
profile = load_user_profile()
|
|
profile["monica_visual_preferences"] = ["item1", "item2", "item3"]
|
|
save_user_profile(profile)
|
|
|
|
update = FakeUpdate("/editaragente")
|
|
context = FakeContext()
|
|
await editaragente_command(update, context)
|
|
|
|
update = FakeUpdate("5")
|
|
context = FakeContext()
|
|
handled = await message_handler(update, context)
|
|
print(f" Após selecionar remover (opção 5): handled={handled}")
|
|
|
|
update = FakeUpdate("2")
|
|
context = FakeContext()
|
|
handled = await message_handler(update, context)
|
|
print(f" Após selecionar item 2: handled={handled}")
|
|
|
|
profile = load_user_profile()
|
|
visual = profile.get("monica_visual_preferences", [])
|
|
print(f" Preferências visuais após remoção: {visual}")
|
|
if "item2" not in visual and len(visual) == 2:
|
|
print("✅ Remoção funcionou corretamente")
|
|
else:
|
|
print("❌ Remoção não funcionou como esperado")
|
|
|
|
async def test_editaragente_add():
|
|
print("\n=== Testando adição no /editaragente ===")
|
|
profile = load_user_profile()
|
|
profile["monica_visual_preferences"] = ["item1"]
|
|
save_user_profile(profile)
|
|
|
|
update = FakeUpdate("/editaragente")
|
|
context = FakeContext()
|
|
await editaragente_command(update, context)
|
|
|
|
update = FakeUpdate("1")
|
|
context = FakeContext()
|
|
handled = await message_handler(update, context)
|
|
print(f" Após selecionar adicionar (opção 1): handled={handled}")
|
|
|
|
update = FakeUpdate("novo item, item1")
|
|
context = FakeContext()
|
|
handled = await message_handler(update, context)
|
|
print(f" Após enviar itens: handled={handled}")
|
|
|
|
profile = load_user_profile()
|
|
visual = profile.get("monica_visual_preferences", [])
|
|
print(f" Preferências visuais após adição: {visual}")
|
|
if "novo item" in visual:
|
|
print("✅ Adição funcionou corretamente")
|
|
else:
|
|
print("❌ Adição não funcionou como esperado")
|
|
|
|
async def test_help_contains_new_commands():
|
|
print("\n=== Verificando /help contém /editarperfil e /editaragente ===")
|
|
from monica_agent import help_command
|
|
|
|
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 ""
|
|
has_editarperfil = "/editarperfil" in help_text
|
|
has_editaragente = "/editaragente" in help_text
|
|
print(f" /editarperfil: {'✅' if has_editarperfil else '❌'}")
|
|
print(f" /editaragente: {'✅' if has_editaragente else '❌'}")
|
|
finally:
|
|
FakeMessage.reply_text = original_reply
|
|
|
|
async def main():
|
|
await test_editarperfil_command()
|
|
await test_editarperfil_flow()
|
|
await test_editaragente_command()
|
|
await test_editaragente_remove()
|
|
await test_editaragente_add()
|
|
await test_help_contains_new_commands()
|
|
print("\n=== Todos os testes concluídos ===")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|