First Commit
This commit is contained in:
Executable
+170
@@ -0,0 +1,170 @@
|
||||
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 (
|
||||
adicionarperfil_command,
|
||||
adicionaragente_command,
|
||||
message_handler,
|
||||
load_user_profile,
|
||||
save_user_profile,
|
||||
is_adding_user_preference,
|
||||
adding_user_preference_field,
|
||||
is_adding_agent_preference,
|
||||
adding_agent_preference_field,
|
||||
)
|
||||
|
||||
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_adicionarperfil_command():
|
||||
print("=== Testando /adicionarperfil ===")
|
||||
update = FakeUpdate("/adicionarperfil")
|
||||
context = FakeContext()
|
||||
try:
|
||||
await adicionarperfil_command(update, context)
|
||||
print("✅ adicionarperfil_command executou sem erros")
|
||||
except Exception as e:
|
||||
print(f"❌ Erro: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
async def test_adicionarperfil_flow():
|
||||
print("\n=== Testando adição de interesses ===")
|
||||
profile = load_user_profile()
|
||||
profile["interests"] = ["programação"]
|
||||
save_user_profile(profile)
|
||||
|
||||
update = FakeUpdate("/adicionarperfil")
|
||||
context = FakeContext()
|
||||
await adicionarperfil_command(update, context)
|
||||
|
||||
update = FakeUpdate("1")
|
||||
context = FakeContext()
|
||||
handled = await message_handler(update, context)
|
||||
print(f" Selecionar interesses: handled={handled}")
|
||||
|
||||
update = FakeUpdate("música, viagens")
|
||||
context = FakeContext()
|
||||
handled = await message_handler(update, context)
|
||||
print(f" Adicionar itens: handled={handled}")
|
||||
|
||||
profile = load_user_profile()
|
||||
interests = profile.get("interests", [])
|
||||
print(f" Interesses: {interests}")
|
||||
|
||||
if "música" in interests and "viagens" in interests and "programação" in interests:
|
||||
print("✅ Interesses adicionados sem duplicatas")
|
||||
else:
|
||||
print("❌ Falha ao adicionar interesses")
|
||||
|
||||
async def test_adicionaragente_command():
|
||||
print("\n=== Testando /adicionaragente ===")
|
||||
update = FakeUpdate("/adicionaragente")
|
||||
context = FakeContext()
|
||||
try:
|
||||
await adicionaragente_command(update, context)
|
||||
print("✅ adicionaragente_command executou sem erros")
|
||||
except Exception as e:
|
||||
print(f"❌ Erro: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
async def test_adicionaragente_flow():
|
||||
print("\n=== Testando adição de preferências visuais ===")
|
||||
profile = load_user_profile()
|
||||
profile["monica_visual_preferences"] = ["item original"]
|
||||
save_user_profile(profile)
|
||||
|
||||
update = FakeUpdate("/adicionaragente")
|
||||
context = FakeContext()
|
||||
await adicionaragente_command(update, context)
|
||||
|
||||
update = FakeUpdate("1")
|
||||
context = FakeContext()
|
||||
handled = await message_handler(update, context)
|
||||
print(f" Selecionar visuais: handled={handled}")
|
||||
|
||||
update = FakeUpdate("novo visual, item original")
|
||||
context = FakeContext()
|
||||
handled = await message_handler(update, context)
|
||||
print(f" Adicionar itens: handled={handled}")
|
||||
|
||||
profile = load_user_profile()
|
||||
visual = profile.get("monica_visual_preferences", [])
|
||||
print(f" Preferências visuais: {visual}")
|
||||
|
||||
if "novo visual" in visual and "item original" in visual and len(visual) == 2:
|
||||
print("✅ Preferências visuais adicionadas sem duplicatas")
|
||||
else:
|
||||
print("❌ Falha ao adicionar preferências visuais")
|
||||
|
||||
async def test_help_contains_new_commands():
|
||||
print("\n=== Verificando /help contém /adicionarperfil e /adicionaragente ===")
|
||||
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_adicionarperfil = "/adicionarperfil" in help_text
|
||||
has_adicionaragente = "/adicionaragente" in help_text
|
||||
print(f" /adicionarperfil: {'✅' if has_adicionarperfil else '❌'}")
|
||||
print(f" /adicionaragente: {'✅' if has_adicionaragente else '❌'}")
|
||||
finally:
|
||||
FakeMessage.reply_text = original_reply
|
||||
|
||||
async def main():
|
||||
await test_adicionarperfil_command()
|
||||
await test_adicionarperfil_flow()
|
||||
await test_adicionaragente_command()
|
||||
await test_adicionaragente_flow()
|
||||
await test_help_contains_new_commands()
|
||||
print("\n=== Todos os testes concluídos ===")
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user