Spaces:
Sleeping
Sleeping
| 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()) | |