Refactor: Move backend files to backend/ directory and split .gitignore

This commit is contained in:
Yunxiao Xu
2026-02-11 17:40:44 -08:00
parent 48924affa0
commit 7a69133e26
96 changed files with 144 additions and 176 deletions

View File

@@ -0,0 +1,72 @@
import pytest
from ea_chatbot.history.manager import HistoryManager
from ea_chatbot.history.models import User, Conversation, Message, Plot
from ea_chatbot.config import Settings
from sqlalchemy import delete
@pytest.fixture
def history_manager():
settings = Settings()
manager = HistoryManager(settings.history_db_url)
def cleanup():
with manager.get_session() as session:
session.execute(delete(Plot))
session.execute(delete(Message))
session.execute(delete(Conversation))
session.execute(delete(User))
cleanup()
yield manager
cleanup()
def test_full_history_workflow(history_manager):
# 1. Create and Authenticate User
email = "e2e@example.com"
password = "password123"
history_manager.create_user(email, password, "E2E User")
user = history_manager.authenticate_user(email, password)
assert user is not None
assert user.display_name == "E2E User"
# 1.1 Verify get_user_by_id
fetched_user = history_manager.get_user_by_id(user.id)
assert fetched_user is not None
assert fetched_user.username == email
# 2. Create Conversation
conv = history_manager.create_conversation(user.id, "nj", "Test Analytics")
assert conv.id is not None
# 3. Add User Message
history_manager.add_message(conv.id, "user", "How many voters in NJ?")
# 4. Add Assistant Message with Plot
plot_data = b"fake_png_data"
history_manager.add_message(
conv.id,
"assistant",
"There are X voters.",
plots=[plot_data]
)
# 5. Retrieve and Verify History
messages = history_manager.get_messages(conv.id)
assert len(messages) == 2
assert messages[0].role == "user"
assert messages[1].role == "assistant"
assert len(messages[1].plots) == 1
assert messages[1].plots[0].image_data == plot_data
# 6. Verify Conversation listing
convs = history_manager.get_conversations(user.id, "nj")
assert len(convs) == 1
assert convs[0].name == "Test Analytics"
# 7. Update summary
history_manager.update_conversation_summary(conv.id, "Voter count analysis")
# 8. Reload and verify summary
updated_convs = history_manager.get_conversations(user.id, "nj")
assert updated_convs[0].summary == "Voter count analysis"