1717CLIENT_PATH = "haystack_integrations.document_stores.astra.astra_client.AstraDBClient"
1818
1919
20- def _existing_exc () -> CollectionAlreadyExistsException :
21- return CollectionAlreadyExistsException (text = "exists" , keyspace = "default" , collection_name = "my_collection" )
20+ CLIENT_KWARGS = {
21+ "api_endpoint" : "http://example.com" ,
22+ "token" : "test_token" ,
23+ "collection_name" : "my_collection" ,
24+ "embedding_dimension" : 4 ,
25+ "similarity_function" : "cosine" ,
26+ }
2227
2328
2429@pytest .fixture
2530def mock_db ():
26- """Yields the mocked astrapy database; tests configure it before constructing AstraClient."""
2731 with mock .patch (CLIENT_PATH ) as patched_client :
2832 yield patched_client .return_value .get_database .return_value
2933
3034
31- def _make_client () -> AstraClient :
32- return AstraClient (
33- api_endpoint = "http://example.com" ,
34- token = "test_token" ,
35- collection_name = "my_collection" ,
36- embedding_dimension = 4 ,
37- similarity_function = "cosine" ,
38- )
39-
40-
4135@pytest .fixture
4236def client (mock_db ) -> AstraClient : # noqa: ARG001
43- return _make_client ()
37+ return AstraClient (** CLIENT_KWARGS )
38+
39+
40+ def _existing_exc () -> CollectionAlreadyExistsException :
41+ return CollectionAlreadyExistsException (text = "exists" , keyspace = "default" , collection_name = "my_collection" )
4442
4543
4644def test_query_response_get_returns_value ():
@@ -70,7 +68,7 @@ def test_preexisting_collection_with_mismatched_indexing_warns(self, mock_db, pr
7068 SimpleNamespace (name = "my_collection" , options = SimpleNamespace (indexing = pre_indexing ))
7169 ]
7270 with pytest .warns (UserWarning , match = warning_match ):
73- _make_client ( )
71+ AstraClient ( ** CLIENT_KWARGS )
7472 mock_db .get_collection .assert_called_once_with ("my_collection" )
7573
7674 def test_preexisting_collection_with_matching_indexing_reuses_silently (self , mock_db ):
@@ -81,14 +79,14 @@ def test_preexisting_collection_with_matching_indexing_reuses_silently(self, moc
8179 options = SimpleNamespace (indexing = {"deny" : ["metadata._node_content" , "content" ]}),
8280 )
8381 ]
84- _make_client ( )
82+ AstraClient ( ** CLIENT_KWARGS )
8583 mock_db .get_collection .assert_called_once_with ("my_collection" )
8684
8785 def test_unrelated_already_exists_reraises (self , mock_db ):
8886 mock_db .create_collection .side_effect = _existing_exc ()
8987 mock_db .list_collections .return_value = []
9088 with pytest .raises (CollectionAlreadyExistsException ):
91- _make_client ( )
89+ AstraClient ( ** CLIENT_KWARGS )
9290
9391
9492@pytest .mark .parametrize (
0 commit comments