{
"event": "PreToolUse",
"tool_name": "Write",
"tool_input": {
"file_path": "\/var\/www\/mcp-servers\/mcp-db\/tests\/test_logging.py",
"content": "#!\/usr\/bin\/env python3\n\"\"\"Tests für Logging-Funktionalität\"\"\"\n\nimport sys\nfrom pathlib import Path\n\nimport pytest\n\nsys.path.insert(0, \"\/opt\/mcp-servers\/mcp-db\")\n\nfrom dotenv import load_dotenv\n\nload_dotenv(Path(\"\/opt\/mcp-servers\/mcp-db\/.env\"))\n\n\nclass TestLogging:\n \"\"\"Test Logging-Funktionalität\"\"\"\n\n def test_success_log(self, logger, test_log_entry, ki_protokoll_connection):\n \"\"\"Test: Success Log schreiben\"\"\"\n logger.log(test_log_entry)\n\n # Prüfe ob Log geschrieben wurde\n cursor = ki_protokoll_connection.cursor(dictionary=True)\n cursor.execute(\n \"SELECT * FROM mcp_log WHERE request LIKE 'TEST:%' ORDER BY timestamp DESC LIMIT 1\"\n )\n log = cursor.fetchone()\n cursor.close()\n\n assert log is not None\n assert log[\"status\"] == \"success\"\n\n def test_denied_log(self, logger, test_denied_log_entry, ki_protokoll_connection):\n \"\"\"Test: Denied Log schreiben\"\"\"\n logger.log(test_denied_log_entry)\n\n # Prüfe ob Log geschrieben wurde\n cursor = ki_protokoll_connection.cursor(dictionary=True)\n cursor.execute(\n \"SELECT * FROM mcp_log WHERE request LIKE 'TEST: DROP%' ORDER BY timestamp DESC LIMIT 1\"\n )\n log = cursor.fetchone()\n cursor.close()\n\n assert log is not None\n assert log[\"status\"] == \"denied\"\n assert \"DROP\" in (log[\"error_message\"] or \"\")\n\n def test_error_log(self, logger, test_error_log_entry, ki_protokoll_connection):\n \"\"\"Test: Error Log schreiben\"\"\"\n logger.log(test_error_log_entry)\n\n # Prüfe ob Log geschrieben wurde\n cursor = ki_protokoll_connection.cursor(dictionary=True)\n cursor.execute(\n \"SELECT * FROM mcp_log WHERE request LIKE 'TEST: SELECT * FROM nonexistent%' ORDER BY timestamp DESC LIMIT 1\"\n )\n log = cursor.fetchone()\n cursor.close()\n\n assert log is not None\n assert log[\"status\"] == \"error\"\n assert log[\"error_message\"] is not None\n\n\nif __name__ == \"__main__\":\n pytest.main([__file__, \"-v\"])\n"
}
}
{
"tool_response": {
"type": "create",
"filePath": "\/var\/www\/mcp-servers\/mcp-db\/tests\/test_logging.py",
"content": "#!\/usr\/bin\/env python3\n\"\"\"Tests für Logging-Funktionalität\"\"\"\n\nimport sys\nfrom pathlib import Path\n\nimport pytest\n\nsys.path.insert(0, \"\/opt\/mcp-servers\/mcp-db\")\n\nfrom dotenv import load_dotenv\n\nload_dotenv(Path(\"\/opt\/mcp-servers\/mcp-db\/.env\"))\n\n\nclass TestLogging:\n \"\"\"Test Logging-Funktionalität\"\"\"\n\n def test_success_log(self, logger, test_log_entry, ki_protokoll_connection):\n \"\"\"Test: Success Log schreiben\"\"\"\n logger.log(test_log_entry)\n\n # Prüfe ob Log geschrieben wurde\n cursor = ki_protokoll_connection.cursor(dictionary=True)\n cursor.execute(\n \"SELECT * FROM mcp_log WHERE request LIKE 'TEST:%' ORDER BY timestamp DESC LIMIT 1\"\n )\n log = cursor.fetchone()\n cursor.close()\n\n assert log is not None\n assert log[\"status\"] == \"success\"\n\n def test_denied_log(self, logger, test_denied_log_entry, ki_protokoll_connection):\n \"\"\"Test: Denied Log schreiben\"\"\"\n logger.log(test_denied_log_entry)\n\n # Prüfe ob Log geschrieben wurde\n cursor = ki_protokoll_connection.cursor(dictionary=True)\n cursor.execute(\n \"SELECT * FROM mcp_log WHERE request LIKE 'TEST: DROP%' ORDER BY timestamp DESC LIMIT 1\"\n )\n log = cursor.fetchone()\n cursor.close()\n\n assert log is not None\n assert log[\"status\"] == \"denied\"\n assert \"DROP\" in (log[\"error_message\"] or \"\")\n\n def test_error_log(self, logger, test_error_log_entry, ki_protokoll_connection):\n \"\"\"Test: Error Log schreiben\"\"\"\n logger.log(test_error_log_entry)\n\n # Prüfe ob Log geschrieben wurde\n cursor = ki_protokoll_connection.cursor(dictionary=True)\n cursor.execute(\n \"SELECT * FROM mcp_log WHERE request LIKE 'TEST: SELECT * FROM nonexistent%' ORDER BY timestamp DESC LIMIT 1\"\n )\n log = cursor.fetchone()\n cursor.close()\n\n assert log is not None\n assert log[\"status\"] == \"error\"\n assert log[\"error_message\"] is not None\n\n\nif __name__ == \"__main__\":\n pytest.main([__file__, \"-v\"])\n",
"structuredPatch": [],
"originalFile": null
}
}