test_new_features.py•2.79 kB
#!/usr/bin/env python3
"""Quick test of new features."""
from pathlib import Path
from dotenv import load_dotenv
from obsidian_mcp.config import ObsidianConfig
from obsidian_mcp.vault import ObsidianVault
load_dotenv()
print("=" * 60)
print("Testing New Features")
print("=" * 60)
# Initialize
config = ObsidianConfig.from_env()
vault = ObsidianVault(config)
# Test get_all_tags
print("\n[1/8] Testing get_all_tags...")
tags = vault.get_all_tags()
print(f"✅ Found {len(tags)} unique tags")
if tags:
print(f" Top 3 tags: {list(tags.items())[:3]}")
# Test get_vault_stats
print("\n[2/8] Testing get_vault_stats...")
stats = vault.get_vault_stats()
print(f"✅ Stats:")
print(f" Total notes: {stats['total_notes']}")
print(f" Total tags: {stats['total_tags']}")
print(f" Total size: {stats['total_size_bytes']} bytes")
# Test create_note
print("\n[3/8] Testing create_note...")
test_note_path = "test_feature_note.md"
try:
vault.create_note(
test_note_path,
"This is a test note with [[links]] to other notes.\n\nIt has #testtag too.",
frontmatter={"tags": ["test", "automated"]},
overwrite=True
)
print(f"✅ Created test note: {test_note_path}")
except Exception as e:
print(f"❌ Failed: {e}")
# Test read_note (verify creation)
print("\n[4/8] Testing read of created note...")
try:
note = vault.read_note(test_note_path)
print(f"✅ Read note successfully")
print(f" Has frontmatter: {note.frontmatter is not None}")
print(f" Tags: {note.frontmatter.get('tags') if note.frontmatter else []}")
except Exception as e:
print(f"❌ Failed: {e}")
# Test get_outgoing_links
print("\n[5/8] Testing get_outgoing_links...")
try:
links = vault.get_outgoing_links(test_note_path)
print(f"✅ Found {len(links)} outgoing links")
except Exception as e:
print(f"❌ Failed: {e}")
# Test append_to_note
print("\n[6/8] Testing append_to_note...")
try:
vault.append_to_note(test_note_path, "\n\n## Appended Section\n\nThis was appended!")
print(f"✅ Appended to note")
except Exception as e:
print(f"❌ Failed: {e}")
# Test update_frontmatter
print("\n[7/8] Testing update_frontmatter...")
try:
vault.update_frontmatter(test_note_path, {"status": "done"})
updated = vault.read_note(test_note_path)
print(f"✅ Updated frontmatter")
print(f" Status: {updated.frontmatter.get('status') if updated.frontmatter else 'N/A'}")
except Exception as e:
print(f"❌ Failed: {e}")
# Test delete_note
print("\n[8/8] Testing delete_note...")
try:
vault.delete_note(test_note_path, use_trash=True)
print(f"✅ Moved note to trash")
except Exception as e:
print(f"❌ Failed: {e}")
print("\n" + "=" * 60)
print("✅ ALL NEW FEATURES TESTED!")
print("=" * 60)