(mock_call_llm, monkeypatch)
| 23 | |
| 24 | @patch("codegraphcontext.viz.server.call_llm") |
| 25 | def test_ai_query_success(mock_call_llm, monkeypatch): |
| 26 | monkeypatch.setenv("GEMINI_API_KEY", "fake-gemini-key") |
| 27 | |
| 28 | mock_call_llm.side_effect = [ |
| 29 | '{"cypher_query": "MATCH (n) RETURN n", "explanation": "translating test"}', |
| 30 | "This is the explanation of the results." |
| 31 | ] |
| 32 | |
| 33 | mock_db = MagicMock() |
| 34 | mock_driver = MagicMock() |
| 35 | mock_session = MagicMock() |
| 36 | mock_result = MagicMock() |
| 37 | |
| 38 | mock_record = MagicMock() |
| 39 | mock_node_dict = {"_label": "Class", "name": "TestClass", "path": "/path/to/test"} |
| 40 | mock_record.values.return_value = [mock_node_dict] |
| 41 | mock_record.items.return_value = [("n", mock_node_dict)] |
| 42 | mock_record.get.return_value = mock_node_dict |
| 43 | |
| 44 | mock_result.__iter__.return_value = [mock_record] |
| 45 | |
| 46 | mock_session.run.return_value = mock_result |
| 47 | mock_driver.session.return_value.__enter__.return_value = mock_session |
| 48 | mock_db.get_driver.return_value = mock_driver |
| 49 | set_db_manager(mock_db) |
| 50 | |
| 51 | response = client.post("/api/ai_query", json={"query": "test query"}) |
| 52 | |
| 53 | assert response.status_code == 200 |
| 54 | res_data = response.json() |
| 55 | assert res_data["success"] is True |
| 56 | assert res_data["cypher_query"] == "MATCH (n) RETURN n" |
| 57 | assert res_data["explanation"] == "This is the explanation of the results." |
| 58 | assert len(res_data["nodes"]) > 0 |
| 59 | assert res_data["nodes"][0]["name"] == "TestClass" |
nothing calls this directly
no test coverage detected