{
"event": "PreToolUse",
"tool_name": "Write",
"tool_input": {
"file_path": "\/var\/www\/mcp-servers\/mcp-db\/tests\/conftest.py",
"content": "#!\/usr\/bin\/env python3\n\"\"\"Gemeinsame Test-Fixtures für MCP-DB Tests\"\"\"\n\nimport sys\nfrom pathlib import Path\n\nimport pytest\n\n# Pfad zum mcp-db Server hinzufügen\nsys.path.insert(0, \"\/opt\/mcp-servers\/mcp-db\")\n\n# .env laden BEVOR Config importiert wird\nfrom dotenv import load_dotenv\n\nload_dotenv(Path(\"\/opt\/mcp-servers\/mcp-db\/.env\"))\n\nfrom config import Config\nfrom domain.log_contract import LogEntry\nfrom infrastructure.protokoll_logger import ProtokollLogger\n\n\n@pytest.fixture\ndef db_connection():\n \"\"\"Fixture für Datenbank-Verbindung\"\"\"\n import mysql.connector\n\n conn = mysql.connector.connect(\n host=Config.DB_HOST,\n user=Config.DB_USER,\n password=Config.DB_PASSWORD,\n charset=\"utf8mb4\",\n )\n yield conn\n conn.close()\n\n\n@pytest.fixture\ndef ki_protokoll_connection():\n \"\"\"Fixture für ki_protokoll Datenbank-Verbindung\"\"\"\n import mysql.connector\n\n conn = mysql.connector.connect(\n host=Config.DB_HOST,\n database=\"ki_protokoll\",\n user=Config.DB_USER,\n password=Config.DB_PASSWORD,\n charset=\"utf8mb4\",\n )\n yield conn\n conn.close()\n\n\n@pytest.fixture\ndef ki_system_connection():\n \"\"\"Fixture für ki_system Datenbank-Verbindung\"\"\"\n import mysql.connector\n\n conn = mysql.connector.connect(\n host=Config.DB_HOST,\n database=\"ki_system\",\n user=Config.DB_USER,\n password=Config.DB_PASSWORD,\n charset=\"utf8mb4\",\n )\n yield conn\n conn.close()\n\n\n@pytest.fixture\ndef logger():\n \"\"\"Fixture für ProtokollLogger\"\"\"\n return ProtokollLogger()\n\n\n@pytest.fixture\ndef test_log_entry():\n \"\"\"Fixture für Test LogEntry\"\"\"\n return LogEntry(\n request=\"TEST: SELECT * FROM mcp_log\",\n status=\"success\",\n duration_ms=42,\n )\n\n\n@pytest.fixture\ndef test_denied_log_entry():\n \"\"\"Fixture für Test Denied LogEntry\"\"\"\n return LogEntry(\n request=\"TEST: DROP TABLE mcp_log\",\n status=\"denied\",\n duration_ms=0,\n error_message=\"Blocked keyword: DROP\",\n )\n\n\n@pytest.fixture\ndef test_error_log_entry():\n \"\"\"Fixture für Test Error LogEntry\"\"\"\n return LogEntry(\n request=\"TEST: SELECT * FROM nonexistent\",\n status=\"error\",\n duration_ms=15,\n error_message=\"Table doesn't exist\",\n )\n"
}
}
{
"tool_response": {
"type": "create",
"filePath": "\/var\/www\/mcp-servers\/mcp-db\/tests\/conftest.py",
"content": "#!\/usr\/bin\/env python3\n\"\"\"Gemeinsame Test-Fixtures für MCP-DB Tests\"\"\"\n\nimport sys\nfrom pathlib import Path\n\nimport pytest\n\n# Pfad zum mcp-db Server hinzufügen\nsys.path.insert(0, \"\/opt\/mcp-servers\/mcp-db\")\n\n# .env laden BEVOR Config importiert wird\nfrom dotenv import load_dotenv\n\nload_dotenv(Path(\"\/opt\/mcp-servers\/mcp-db\/.env\"))\n\nfrom config import Config\nfrom domain.log_contract import LogEntry\nfrom infrastructure.protokoll_logger import ProtokollLogger\n\n\n@pytest.fixture\ndef db_connection():\n \"\"\"Fixture für Datenbank-Verbindung\"\"\"\n import mysql.connector\n\n conn = mysql.connector.connect(\n host=Config.DB_HOST,\n user=Config.DB_USER,\n password=Config.DB_PASSWORD,\n charset=\"utf8mb4\",\n )\n yield conn\n conn.close()\n\n\n@pytest.fixture\ndef ki_protokoll_connection():\n \"\"\"Fixture für ki_protokoll Datenbank-Verbindung\"\"\"\n import mysql.connector\n\n conn = mysql.connector.connect(\n host=Config.DB_HOST,\n database=\"ki_protokoll\",\n user=Config.DB_USER,\n password=Config.DB_PASSWORD,\n charset=\"utf8mb4\",\n )\n yield conn\n conn.close()\n\n\n@pytest.fixture\ndef ki_system_connection():\n \"\"\"Fixture für ki_system Datenbank-Verbindung\"\"\"\n import mysql.connector\n\n conn = mysql.connector.connect(\n host=Config.DB_HOST,\n database=\"ki_system\",\n user=Config.DB_USER,\n password=Config.DB_PASSWORD,\n charset=\"utf8mb4\",\n )\n yield conn\n conn.close()\n\n\n@pytest.fixture\ndef logger():\n \"\"\"Fixture für ProtokollLogger\"\"\"\n return ProtokollLogger()\n\n\n@pytest.fixture\ndef test_log_entry():\n \"\"\"Fixture für Test LogEntry\"\"\"\n return LogEntry(\n request=\"TEST: SELECT * FROM mcp_log\",\n status=\"success\",\n duration_ms=42,\n )\n\n\n@pytest.fixture\ndef test_denied_log_entry():\n \"\"\"Fixture für Test Denied LogEntry\"\"\"\n return LogEntry(\n request=\"TEST: DROP TABLE mcp_log\",\n status=\"denied\",\n duration_ms=0,\n error_message=\"Blocked keyword: DROP\",\n )\n\n\n@pytest.fixture\ndef test_error_log_entry():\n \"\"\"Fixture für Test Error LogEntry\"\"\"\n return LogEntry(\n request=\"TEST: SELECT * FROM nonexistent\",\n status=\"error\",\n duration_ms=15,\n error_message=\"Table doesn't exist\",\n )\n",
"structuredPatch": [],
"originalFile": null
}
}