improvements

This commit is contained in:
olivier committed 2025-10-28 21:52:04 -04:00
1 parent 3d122b5022
commit bf1dca3bc4
12 files changed
+303 -103

No files matched your search

+61 -5
View File
@@ -6,6 +6,7 @@ from pathlib import Path
from src.obsidian_cli import OnyxCLI
from unittest.mock import patch, MagicMock
import click
from datetime import datetime
class TestOnyxCLI(unittest.TestCase):
def setUp(self):
@@ -48,6 +49,59 @@ class TestOnyxCLI(unittest.TestCase):
self.cli.create_note('test.md', 'Test content')
note_path = self.test_dir / 'test.md'
self.assertTrue(note_path.exists())
def test_export_to_csv(self):
"""Test exporting note frontmatter to CSV"""
# Create a test note with frontmatter
note_content = """---
title: Test Note
tags: [tag1, tag2]
status: in-progress
date: 2025-10-28
custom: value
---
Note content"""
self.cli.create_note('test_note.md', note_content)
# Test export with specific columns included
output_file = self.test_dir / 'output1.csv'
self.cli.export_to_csv('test_note', str(output_file), include_columns=['title', 'status', 'date'])
with open(output_file, 'r', encoding='utf-8') as f:
content = f.read().strip()
self.assertEqual(content, 'title,status,date\nTest Note,in-progress,2025-10-28')
# Test export excluding specific columns
output_file = self.test_dir / 'output2.csv'
self.cli.export_to_csv('test_note', str(output_file), exclude_columns=['tags', 'custom'])
with open(output_file, 'r', encoding='utf-8') as f:
content = f.read().strip()
self.assertEqual(content, 'title,status,date\nTest Note,in-progress,2025-10-28')
# Test export with both include and exclude (exclude takes precedence)
output_file = self.test_dir / 'output3.csv'
self.cli.export_to_csv('test_note', str(output_file),
include_columns=['title', 'status', 'date', 'custom'],
exclude_columns=['status'])
with open(output_file, 'r', encoding='utf-8') as f:
content = f.read().strip()
self.assertEqual(content, 'title,date,custom\nTest Note,2025-10-28,value')
# Test with non-existent note
with self.assertRaises(click.UsageError) as context:
self.cli.export_to_csv('non_existent', 'output.csv')
self.assertTrue("not found in vault" in str(context.exception))
# Test with note without frontmatter
self.cli.create_note('no_frontmatter.md', 'Just content')
with self.assertRaises(click.UsageError) as context:
self.cli.export_to_csv('no_frontmatter', 'output.csv')
self.assertTrue("No frontmatter found" in str(context.exception))
# Test with empty frontmatter
self.cli.create_note('empty_frontmatter.md', '---\n---\nContent')
with self.assertRaises(click.UsageError) as context:
self.cli.export_to_csv('empty_frontmatter', 'output.csv')
self.assertTrue("Empty frontmatter" in str(context.exception))
self.assertEqual(note_path.read_text(), 'Test content')
# Test note creation with auto-extension
@@ -150,9 +204,11 @@ Test content"""
def test_daily_note(self):
"""Test daily note creation"""
# Create daily note (default settings don't use templates)
# Mock datetime.now() to return a specific date
mock_dt = MagicMock()
mock_dt.strftime.return_value = '2025-10-24'
with patch('datetime.datetime') as mock_date:
mock_date.now.return_value.strftime.return_value = '2025-10-24'
mock_date.now.return_value = mock_dt
self.cli.daily_note()
daily_note = self.test_dir / '2025-10-24.md'
@@ -170,15 +226,15 @@ Test content"""
# Test opening on different platforms
with patch('sys.platform', 'win32'):
self.cli.open_note('test.md')
mock_startfile.assert_called_with('obsidian://open?vault=test_vault&file=test')
mock_startfile.assert_called_with('obsidian://open?vault=test_vault&file=test.md')
with patch('sys.platform', 'darwin'):
self.cli.open_note('test.md')
mock_run.assert_called_with(['open', 'obsidian://open?vault=test_vault&file=test'])
mock_run.assert_called_with(['open', 'obsidian://open?vault=test_vault&file=test.md'])
with patch('sys.platform', 'linux'):
self.cli.open_note('test.md')
mock_run.assert_called_with(['xdg-open', 'obsidian://open?vault=test_vault&file=test'])
mock_run.assert_called_with(['xdg-open', 'obsidian://open?vault=test_vault&file=test.md'])
def test_delete_note(self):
"""Test note deletion"""