@@ -55,6 +55,16 @@ def setUpClass(cls):
5555 # Mock environment variables for testing
5656 os .environ ["MOCK_EMBEDDINGS" ] = "true"
5757 os .environ ["CHROMA_DB_PATH" ] = cls .index_dir
58+ os .environ ["USE_PERSISTENT_CHROMA" ] = "false" # Use in-memory for tests
59+ os .environ ["USE_IN_MEMORY_CHROMA" ] = (
60+ "true" # Use in-memory Chroma client for tests
61+ )
62+ os .environ ["CHROMA_HOST" ] = (
63+ "" # Clear CHROMA_HOST to avoid HTTP connection attempts
64+ )
65+ os .environ ["CHROMA_PORT" ] = (
66+ "" # Clear CHROMA_PORT to avoid HTTP connection attempts
67+ )
5868
5969 # Create a test client for the API
6070 cls .client = TestClient (app )
@@ -93,31 +103,28 @@ def test_full_pipeline(self, mock_api_embedding, mock_indexer_embedding):
93103 # Verify chunks were indexed
94104 self .assertGreater (collection .count (), 0 )
95105
96- # Step 2: Test the API with indexed data
97- # We'll bypass the actual HTTP server and use the TestClient directly
98-
99- # Test query endpoint
100- response = self .client .post ("/query" , json = {"query" : "Tank Level" , "top_k" : 2 })
101- self .assertEqual (response .status_code , 200 )
102- query_data = response .json ()
103- self .assertIn ("results" , query_data )
104-
105- # Test agent query endpoint
106- response = self .client .post (
107- "/agent/query" ,
108- json = {"query" : "How is the Tank Level configured?" , "top_k" : 2 },
109- )
110- self .assertEqual (response .status_code , 200 )
111- agent_data = response .json ()
112- self .assertIn ("context_chunks" , agent_data )
113- self .assertIn ("suggested_prompt" , agent_data )
114-
115- # Test stats endpoint
116- response = self .client .get ("/stats" )
117- self .assertEqual (response .status_code , 200 )
118- stats_data = response .json ()
119- self .assertIn ("total_documents" , stats_data )
120- self .assertIn ("type_distribution" , stats_data )
106+ # Step 2: Test the API with indexed data
107+ # Patch the API to use our existing collection
108+ with patch ("api.get_collection" , return_value = collection ):
109+ # Test query endpoint
110+ response = self .client .post (
111+ "/query" , json = {"query" : "Tank Level" , "top_k" : 2 }
112+ )
113+ self .assertEqual (response .status_code , 200 )
114+ query_data = response .json ()
115+ self .assertIn ("results" , query_data )
116+ self .assertIn ("metadata" , query_data )
117+ self .assertIn ("total_chunks" , query_data ["metadata" ])
118+
119+ # Test agent query endpoint
120+ response = self .client .post (
121+ "/agent/query" ,
122+ json = {"query" : "How is the Tank Level configured?" , "top_k" : 2 },
123+ )
124+ self .assertEqual (response .status_code , 200 )
125+ agent_data = response .json ()
126+ self .assertIn ("context_chunks" , agent_data )
127+ self .assertIn ("suggested_prompt" , agent_data )
121128
122129 @patch ("indexer.mock_embedding" , return_value = [0.1 ] * 1536 )
123130 def test_incremental_indexing (self , mock_embedding_fn ):
0 commit comments