Spaces:
Sleeping
Sleeping
File size: 2,375 Bytes
5e0532d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import asyncio
import os
import uuid
from datetime import datetime
from app.services.journal import journal_service, JournalEntry
from app.services.profile import profile_service, TonePreference, SpiritualGoal
async def verify_persistence():
print("Verifying Persistence Layer...")
user_id = "test_persistence_user"
# --- Profile Test ---
print("\n--- Testing Profile ---")
# 1. Get default
p1 = await profile_service.get_profile(user_id)
print(f"Default Profile: {p1.tone_preference} (Expected: pastoral) | Translations: {p1.bible_translations}")
# 2. Update
print("Updating profile...")
updated = await profile_service.update_profile(user_id, {
"tone_preference": TonePreference.SCHOLARLY,
"bible_translations": ["KJV", "RSV"],
"spiritual_goals": [SpiritualGoal.STUDY]
})
# 3. Verify Update Persisted
p2 = await profile_service.get_profile(user_id)
if p2.tone_preference == TonePreference.SCHOLARLY and "KJV" in p2.bible_translations:
print("SUCCESS: Profile update persisted.")
else:
print(f"FAILURE: Profile content mismatch. Got {p2.tone_preference}")
# --- Journal Test ---
print("\n--- Testing Journal ---")
entry_id = str(uuid.uuid4())
entry = JournalEntry(
id=entry_id,
user_id=user_id,
content="Today I felt peace.",
timestamp=datetime.now(),
tags=["peace", "reflection"],
emotion="calm"
)
# 1. Save
await journal_service.save_entry(entry)
print("Saved journal entry.")
# 2. Retrieve
entries = await journal_service.get_recent(user_id)
if not entries:
print("FAILURE: No entries returned.")
else:
found = entries[0]
print(f"Retrieved Entry: {found.content} | Tags: {found.tags}")
if found.id == entry_id and "peace" in found.tags:
print("SUCCESS: Journal entry verified.")
else:
print("FAILURE: Entry content mismatch.")
# 3. Delete
await journal_service.delete_entry(entry_id)
entries_after = await journal_service.get_recent(user_id)
if len(entries_after) == 0:
print("SUCCESS: Journal entry deleted.")
else:
print("FAILURE: Entry still exists after delete.")
if __name__ == "__main__":
asyncio.run(verify_persistence())
|