Spaces:
Sleeping
Sleeping
File size: 5,449 Bytes
7c87115 | 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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | """Tests for NotesMixin class."""
import pytest
from unittest.mock import patch, MagicMock
def test_notes_mixin_import():
"""Test that NotesMixin can be imported."""
from notebooklm_tools.core.notes import NotesMixin
assert NotesMixin is not None
def test_notes_mixin_inherits_base():
"""Test that NotesMixin inherits from BaseClient."""
from notebooklm_tools.core.notes import NotesMixin
from notebooklm_tools.core.base import BaseClient
assert issubclass(NotesMixin, BaseClient)
def test_notes_mixin_has_methods():
"""Test that NotesMixin has all expected methods."""
from notebooklm_tools.core.notes import NotesMixin
expected_methods = [
'create_note',
'list_notes',
'update_note',
'delete_note',
]
for method_name in expected_methods:
assert hasattr(NotesMixin, method_name), f"Missing method: {method_name}"
def test_create_note_calls_rpc():
"""Test that create_note calls the correct RPC."""
from notebooklm_tools.core.notes import NotesMixin
with patch.object(NotesMixin, '_refresh_auth_tokens'):
with patch.object(NotesMixin, '_call_rpc') as mock_rpc:
# Mock create response
mock_rpc.return_value = [["note_id_123", "Test Note"]]
mixin = NotesMixin(cookies={"test": "cookie"}, csrf_token="test")
# Mock update_note to avoid second RPC call
with patch.object(mixin, 'update_note') as mock_update:
mock_update.return_value = {
"id": "note_id_123",
"title": "Test Note",
"content": "Test content"
}
result = mixin.create_note("notebook_123", "Test content", "Test Note")
# Verify create RPC was called
assert mock_rpc.called
assert result is not None
assert result.get("id") == "note_id_123"
def test_list_notes_filters_mind_maps():
"""Test that list_notes filters out mind maps."""
from notebooklm_tools.core.notes import NotesMixin
with patch.object(NotesMixin, '_refresh_auth_tokens'):
with patch.object(NotesMixin, '_call_rpc') as mock_rpc:
# Mock response with both note and mind map
mock_rpc.return_value = [
[
# Regular note
["note_1", ["note_1", "This is a regular note", {}, None, "Note Title"], 1],
# Mind map (has JSON with "children")
["note_2", ["note_2", '{"children": []}', {}, None, "Mind Map"], 1],
],
12345678,
]
mixin = NotesMixin(cookies={"test": "cookie"}, csrf_token="test")
notes = mixin.list_notes("notebook_123")
# Should only return the note, not the mind map
assert len(notes) == 1
assert notes[0]["id"] == "note_1"
assert notes[0]["title"] == "Note Title"
def test_update_note_requires_notebook_id():
"""Test that update_note requires notebook_id."""
from notebooklm_tools.core.notes import NotesMixin
with patch.object(NotesMixin, '_refresh_auth_tokens'):
mixin = NotesMixin(cookies={"test": "cookie"}, csrf_token="test")
with pytest.raises(ValueError, match="notebook_id is required"):
mixin.update_note("note_123", content="New content")
def test_update_note_requires_content_or_title():
"""Test that update_note requires either content or title."""
from notebooklm_tools.core.notes import NotesMixin
with patch.object(NotesMixin, '_refresh_auth_tokens'):
mixin = NotesMixin(cookies={"test": "cookie"}, csrf_token="test")
with pytest.raises(ValueError, match="Must provide content or title"):
mixin.update_note("note_123", notebook_id="notebook_123")
def test_delete_note_returns_bool():
"""Test that delete_note returns boolean."""
from notebooklm_tools.core.notes import NotesMixin
with patch.object(NotesMixin, '_refresh_auth_tokens'):
with patch.object(NotesMixin, '_call_rpc') as mock_rpc:
mock_rpc.return_value = None # API returns null on success
mixin = NotesMixin(cookies={"test": "cookie"}, csrf_token="test")
result = mixin.delete_note("note_123", "notebook_123")
assert isinstance(result, bool)
assert result is True
def test_client_has_notes_methods():
"""Test that NotebookLMClient has notes methods."""
from notebooklm_tools.core.client import NotebookLMClient
expected_methods = [
'create_note',
'list_notes',
'update_note',
'delete_note',
]
for method_name in expected_methods:
assert hasattr(NotebookLMClient, method_name), f"Missing method: {method_name}"
def test_rpc_constants_exist():
"""Test that RPC constants are defined."""
from notebooklm_tools.core.base import BaseClient
assert hasattr(BaseClient, 'RPC_CREATE_NOTE')
assert hasattr(BaseClient, 'RPC_GET_NOTES')
assert hasattr(BaseClient, 'RPC_UPDATE_NOTE')
assert hasattr(BaseClient, 'RPC_DELETE_NOTE')
# Verify the values match the discovered RPCs
assert BaseClient.RPC_CREATE_NOTE == "CYK0Xb"
assert BaseClient.RPC_GET_NOTES == "cFji9"
assert BaseClient.RPC_UPDATE_NOTE == "cYAfTb"
assert BaseClient.RPC_DELETE_NOTE == "AH0mwd"
|