Skip to main content
Glama
by bsahane
test_notes_feature.pyโ€ข6.51 kB
#!/usr/bin/env python3 """Test script for VM/LXC Notes Management feature""" import sys import os import asyncio # Add src to path sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) async def test_notes_feature(): """Test all notes management functionality""" print("๐Ÿงช Testing VM/LXC Notes Management Feature") print("=" * 70) try: # Test 1: Import NotesManager print("\n1๏ธโƒฃ Testing NotesManager Import...") from proxmox_mcp.notes_manager import NotesManager print("โœ… NotesManager imported successfully") # Test 2: Import MCP tools print("\n2๏ธโƒฃ Testing MCP Tools Import...") from proxmox_mcp.server import ( proxmox_vm_notes_read, proxmox_vm_notes_update, proxmox_vm_notes_remove, proxmox_lxc_notes_read, proxmox_lxc_notes_update, proxmox_lxc_notes_remove, proxmox_notes_template ) print("โœ… All 7 MCP tools imported successfully") # Test 3: Test format detection print("\n3๏ธโƒฃ Testing Format Detection...") from proxmox_mcp.client import ProxmoxClient # Create a mock client for testing (without actual Proxmox connection) class MockClient: pass mock_client = MockClient() notes_mgr = NotesManager(mock_client) # Test HTML detection html_content = "<div><h3>Test</h3><p>Content</p></div>" format_html = notes_mgr.detect_format(html_content) assert format_html == 'html', f"Expected 'html', got '{format_html}'" print(f"โœ… HTML detection: {format_html}") # Test Markdown detection md_content = "# Header\n**Bold** text\n- List item" format_md = notes_mgr.detect_format(md_content) assert format_md == 'markdown', f"Expected 'markdown', got '{format_md}'" print(f"โœ… Markdown detection: {format_md}") # Test Plain text detection plain_content = "Just plain text" format_plain = notes_mgr.detect_format(plain_content) assert format_plain == 'plain', f"Expected 'plain', got '{format_plain}'" print(f"โœ… Plain text detection: {format_plain}") # Test 4: Test secret reference extraction print("\n4๏ธโƒฃ Testing Secret Reference Extraction...") content_with_secrets = """ VM: Production Server Credentials: secret://vm-341-ssh-key API Key: secret://api/production-key """ secrets = notes_mgr.extract_secret_references(content_with_secrets) assert len(secrets) == 2, f"Expected 2 secrets, got {len(secrets)}" assert "vm-341-ssh-key" in secrets assert "api/production-key" in secrets print(f"โœ… Extracted {len(secrets)} secret references: {secrets}") # Test 5: Test content validation print("\n5๏ธโƒฃ Testing Content Validation...") # Safe content safe_content = "VM: web-server\nCredentials: secret://vm-key" is_valid, warnings = notes_mgr.validate_content(safe_content) assert is_valid, "Safe content should be valid" print(f"โœ… Safe content validated: {len(warnings)} warnings") # Unsafe content unsafe_content = "password=mySecretPass123" is_valid, warnings = notes_mgr.validate_content(unsafe_content) assert not is_valid, "Unsafe content should be invalid" assert len(warnings) > 0, "Should have warnings" print(f"โœ… Unsafe content detected: {len(warnings)} warnings") print(f" Warning: {warnings[0][:50]}...") # Test 6: Test template generation print("\n6๏ธโƒฃ Testing Template Generation...") templates_to_test = [ ("web-server", "html"), ("database", "html"), ("development", "markdown"), ("generic", "markdown"), ("minimal", "plain") ] for template_type, format_type in templates_to_test: template = notes_mgr.generate_template( template_type, format_type, {"VM_NAME": "test-vm", "IP_ADDRESS": "192.168.1.100"} ) assert len(template) > 0, f"Template {template_type} should not be empty" assert "test-vm" in template, f"Template should contain VM_NAME" print(f"โœ… Template '{template_type}-{format_type}': {len(template)} chars") # Test 7: Test markdown rendering print("\n7๏ธโƒฃ Testing Markdown Rendering...") md_input = "# Header\n**Bold** text\n`code`" rendered = notes_mgr.render_markdown(md_input) assert len(rendered) > 0, "Rendered markdown should not be empty" print(f"โœ… Markdown rendered: {len(rendered)} chars") # Test 8: Test format_notes_output print("\n8๏ธโƒฃ Testing Notes Output Formatting...") test_content = "# Test VM\nCredentials: secret://test-key" output = notes_mgr.format_notes_output(test_content, "auto", True) assert "content" in output assert "format" in output assert "secret_references" in output assert output["format"] == "markdown" assert len(output["secret_references"]) == 1 print(f"โœ… Output formatted correctly") print(f" Format: {output['format']}") print(f" Secrets: {output['secret_references']}") print(f" Length: {output['length']} chars") # Summary print("\n" + "=" * 70) print("๐ŸŽ‰ ALL TESTS PASSED!") print("=" * 70) print("\n๐Ÿ“Š Test Summary:") print(" โœ… Module imports: PASS") print(" โœ… Format detection: PASS (HTML, Markdown, Plain)") print(" โœ… Secret extraction: PASS") print(" โœ… Content validation: PASS") print(" โœ… Template generation: PASS (5 templates)") print(" โœ… Markdown rendering: PASS") print(" โœ… Output formatting: PASS") print("\n๐ŸŽฏ Feature Status: FULLY FUNCTIONAL โœ…") return 0 except Exception as e: print(f"\nโŒ TEST FAILED: {e}") import traceback traceback.print_exc() return 1 if __name__ == "__main__": exit_code = asyncio.run(test_notes_feature()) sys.exit(exit_code)

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bsahane/mcp-proxmox'

If you have feedback or need assistance with the MCP directory API, please join our Discord server