First Commit
This commit is contained in:
Executable
+269
@@ -0,0 +1,269 @@
|
||||
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 (
|
||||
verperfil_command,
|
||||
veragente_command,
|
||||
editarperfil_command,
|
||||
editaragente_command,
|
||||
message_handler,
|
||||
load_user_profile,
|
||||
save_user_profile,
|
||||
get_user_profile_summary,
|
||||
get_agent_profile_summary,
|
||||
)
|
||||
|
||||
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[:500]}")
|
||||
|
||||
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', '')[:500]}")
|
||||
|
||||
async def test_verperfil():
|
||||
print("=== Testando /verperfil ===")
|
||||
update = FakeUpdate("/verperfil")
|
||||
context = FakeContext()
|
||||
try:
|
||||
await verperfil_command(update, context)
|
||||
print("✅ verperfil_command executou sem erros")
|
||||
except Exception as e:
|
||||
print(f"❌ Erro: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
async def test_veragente():
|
||||
print("\n=== Testando /veragente ===")
|
||||
update = FakeUpdate("/veragente")
|
||||
context = FakeContext()
|
||||
try:
|
||||
await veragente_command(update, context)
|
||||
print("✅ veragente_command executou sem erros")
|
||||
except Exception as e:
|
||||
print(f"❌ Erro: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
async def test_editarperfil_all_fields():
|
||||
print("\n=== Testando edição de TODOS os campos do usuário ===")
|
||||
|
||||
test_cases = [
|
||||
("1", "João Silva", "name"),
|
||||
("2", "30", "age"),
|
||||
("3", "Masculino", "gender"),
|
||||
("4", "São Paulo", "location"),
|
||||
("5", "programação, música, viagens", "interests"),
|
||||
("6", "extrovertido, curioso", "personality_traits"),
|
||||
("7", "Carinhosa e direta", "preferences.communication_style"),
|
||||
("8", "política, futebol", "preferences.topics_to_avoid"),
|
||||
("9", "tecnologia, IA, cinema", "preferences.topics_of_interest"),
|
||||
("10", "Casado, feliz", "relationship_context"),
|
||||
("11", "Totalmente aberto", "sexual_preferences.openness"),
|
||||
("12", "fantasias, sedução", "sexual_preferences.preferred_topics"),
|
||||
("13", "respeito, consentimento", "sexual_preferences.boundaries"),
|
||||
("14", "7h", "daily_routine.wake_up_time"),
|
||||
("15", "23h", "daily_routine.sleep_time"),
|
||||
("16", "home-office", "daily_routine.work_schedule"),
|
||||
("17", "Nota de teste", "notes"),
|
||||
]
|
||||
|
||||
for option, value, expected_field in test_cases:
|
||||
update = FakeUpdate("/editarperfil")
|
||||
context = FakeContext()
|
||||
await editarperfil_command(update, context)
|
||||
|
||||
update = FakeUpdate(option)
|
||||
context = FakeContext()
|
||||
handled = await message_handler(update, context)
|
||||
print(f" Opção {option}: handled={handled}")
|
||||
|
||||
update = FakeUpdate(value)
|
||||
context = FakeContext()
|
||||
handled = await message_handler(update, context)
|
||||
print(f" Valor '{value}': handled={handled}")
|
||||
|
||||
profile = load_user_profile()
|
||||
field_path = expected_field.split(".")
|
||||
current = profile
|
||||
for key in field_path:
|
||||
if key in current:
|
||||
current = current[key]
|
||||
else:
|
||||
current = None
|
||||
break
|
||||
|
||||
if current is not None:
|
||||
print(f" ✅ Campo {expected_field} = {current}")
|
||||
else:
|
||||
print(f" ❌ Campo {expected_field} não encontrado")
|
||||
|
||||
print("\n✅ Todos os campos do usuário editados com sucesso")
|
||||
|
||||
async def test_editaragente_all_categories():
|
||||
print("\n=== Testando edição de TODAS as categorias do agente ===")
|
||||
|
||||
profile = load_user_profile()
|
||||
profile["monica_visual_preferences"] = ["item original visual"]
|
||||
profile["monica_sexual_preferences"] = ["item original sexual"]
|
||||
profile["monica_nudity_preferences"] = ["item original nudez"]
|
||||
profile["relationship_dynamics"] = ["item original dynamics"]
|
||||
profile["nudity_preferences"] = {"notas_adicionais": "texto original"}
|
||||
save_user_profile(profile)
|
||||
|
||||
test_cases = [
|
||||
("1", "novo visual", "add", "monica_visual_preferences"),
|
||||
("2", "novo sexual", "add", "monica_sexual_preferences"),
|
||||
("3", "novo nudez", "add", "monica_nudity_preferences"),
|
||||
("4", "nova dynamics", "add", "relationship_dynamics"),
|
||||
("9", "novo texto nudidade", "edit", "nudity_preferences"),
|
||||
]
|
||||
|
||||
for option, value, action, expected_field in test_cases:
|
||||
update = FakeUpdate("/editaragente")
|
||||
context = FakeContext()
|
||||
await editaragente_command(update, context)
|
||||
|
||||
update = FakeUpdate(option)
|
||||
context = FakeContext()
|
||||
handled = await message_handler(update, context)
|
||||
print(f" Opção {option}: handled={handled}")
|
||||
|
||||
update = FakeUpdate(value)
|
||||
context = FakeContext()
|
||||
handled = await message_handler(update, context)
|
||||
print(f" Valor '{value}': handled={handled}")
|
||||
|
||||
profile = load_user_profile()
|
||||
if expected_field == "nudity_preferences":
|
||||
current = profile.get(expected_field, {}).get("notas_adicionais", "")
|
||||
else:
|
||||
current = profile.get(expected_field, [])
|
||||
|
||||
if action == "add" and expected_field != "nudity_preferences":
|
||||
if value in current:
|
||||
print(f" ✅ {expected_field} contém '{value}'")
|
||||
else:
|
||||
print(f" ❌ {expected_field} não contém '{value}'")
|
||||
elif action == "edit":
|
||||
if current == value:
|
||||
print(f" ✅ {expected_field} = '{current}'")
|
||||
else:
|
||||
print(f" ❌ {expected_field} = '{current}' (esperado '{value}')")
|
||||
|
||||
print("\n✅ Todas as categorias do agente editadas com sucesso")
|
||||
|
||||
async def test_remove_agent_items():
|
||||
print("\n=== Testando remoção de itens do agente ===")
|
||||
|
||||
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" Opção remover visual: handled={handled}")
|
||||
|
||||
update = FakeUpdate("2")
|
||||
context = FakeContext()
|
||||
handled = await message_handler(update, context)
|
||||
print(f" Remover item 2: handled={handled}")
|
||||
|
||||
profile = load_user_profile()
|
||||
visual = profile.get("monica_visual_preferences", [])
|
||||
if "item2" not in visual and len(visual) == 2:
|
||||
print(" ✅ Remoção funcionou")
|
||||
else:
|
||||
print(f" ❌ Remoção não funcionou: {visual}")
|
||||
|
||||
async def test_summary_functions():
|
||||
print("\n=== Testando funções de sumário ===")
|
||||
profile = load_user_profile()
|
||||
|
||||
user_summary = get_user_profile_summary(profile)
|
||||
print(f"Sumário do usuário: {len(user_summary)} caracteres")
|
||||
if "=== SEU PERFIL ===" in user_summary and "Nome:" in user_summary:
|
||||
print("✅ Sumário do usuário OK")
|
||||
else:
|
||||
print("❌ Sumário do usuário com problema")
|
||||
|
||||
agent_summary = get_agent_profile_summary(profile)
|
||||
print(f"Sumário do agente: {len(agent_summary)} caracteres")
|
||||
if "=== PERFIL DA MÔNICA ===" in agent_summary:
|
||||
print("✅ Sumário do agente OK")
|
||||
else:
|
||||
print("❌ Sumário do agente com problema")
|
||||
|
||||
async def test_help_contains_new_commands():
|
||||
print("\n=== Verificando /help contém todos os comandos ===")
|
||||
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)
|
||||
|
||||
FakeMessage.reply_text = capture_reply
|
||||
try:
|
||||
await help_command(update, context)
|
||||
help_text = responses[0] if responses else ""
|
||||
commands_to_check = ["/verperfil", "/veragente", "/editarperfil", "/editaragente"]
|
||||
for cmd in commands_to_check:
|
||||
if cmd in help_text:
|
||||
print(f" ✅ /help menciona {cmd}")
|
||||
else:
|
||||
print(f" ❌ /help NÃO menciona {cmd}")
|
||||
finally:
|
||||
FakeMessage.reply_text = original_reply
|
||||
|
||||
async def main():
|
||||
await test_verperfil()
|
||||
await test_veragente()
|
||||
await test_summary_functions()
|
||||
await test_editarperfil_all_fields()
|
||||
await test_editaragente_all_categories()
|
||||
await test_remove_agent_items()
|
||||
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