(mock_call_llm, monkeypatch)
| 82 | |
| 83 | @patch("codegraphcontext.viz.server.call_llm") |
| 84 | def test_ai_query_success(mock_call_llm, monkeypatch): |
| 85 | monkeypatch.setenv("GEMINI_API_KEY", "fake-gemini-key") |
| 86 | |
| 87 | mock_call_llm.side_effect = [ |
| 88 | '{"cypher_query": "MATCH (n) RETURN n", "explanation": "translating test"}', |
| 89 | "This is the explanation of the results." |
| 90 | ] |
| 91 | |
| 92 | mock_db = MagicMock() |
| 93 | mock_driver = MagicMock() |
| 94 | mock_session = MagicMock() |
| 95 | mock_result = MagicMock() |
| 96 | |
| 97 | mock_record = MagicMock() |
| 98 | mock_node_dict = {"_label": "Class", "name": "TestClass", "path": "/path/to/test"} |
| 99 | mock_record.values.return_value = [mock_node_dict] |
| 100 | mock_record.items.return_value = [("n", mock_node_dict)] |
| 101 | mock_record.get.return_value = mock_node_dict |
| 102 | |
| 103 | mock_result.__iter__.return_value = [mock_record] |
| 104 | |
| 105 | mock_session.run.return_value = mock_result |
| 106 | mock_driver.session.return_value.__enter__.return_value = mock_session |
| 107 | mock_db.get_driver.return_value = mock_driver |
| 108 | set_db_manager(mock_db) |
| 109 | |
| 110 | response = client.post("/api/ai_query", json={"query": "test query"}) |
| 111 | |
| 112 | assert response.status_code == 200 |
| 113 | res_data = response.json() |
| 114 | assert res_data["success"] is True |
| 115 | assert res_data["cypher_query"] == "MATCH (n) RETURN n" |
| 116 | assert res_data["explanation"] == "This is the explanation of the results." |
| 117 | assert len(res_data["nodes"]) > 0 |
| 118 | assert res_data["nodes"][0]["name"] == "TestClass" |
nothing calls this directly
no test coverage detected