Skip to content

Commit

Permalink
fix fulltext_retriever tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mpangrazzi committed Dec 4, 2024
1 parent c00dba4 commit d92dc40
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions integrations/mongodb_atlas/tests/test_fulltext_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,38 @@
#
# SPDX-License-Identifier: Apache-2.0
import os
from time import sleep
from typing import List, Union
from unittest.mock import MagicMock

import pytest
from haystack import Document
from haystack.utils import Secret

from haystack_integrations.document_stores.mongodb_atlas import MongoDBAtlasDocumentStore


def get_document_store():
return MongoDBAtlasDocumentStore(
mongo_connection_string=Secret.from_env_var("MONGO_CONNECTION_STRING_2"),
database_name="haystack_test",
collection_name="test_collection",
vector_search_index="cosine_index",
full_text_search_index="full_text_index",
)


@pytest.mark.skipif(
"MONGO_CONNECTION_STRING" not in os.environ,
"MONGO_CONNECTION_STRING_2" not in os.environ,
reason="No MongoDB Atlas connection string provided",
)
@pytest.mark.integration
class TestFullTextRetrieval:

@pytest.fixture()
@pytest.fixture(scope="class")
def document_store(self) -> MongoDBAtlasDocumentStore:
return MongoDBAtlasDocumentStore(
database_name="haystack_integration_test",
collection_name="test_full_text_collection",
vector_search_index="cosine_index",
full_text_search_index="full_text_index",
)
return get_document_store()

@pytest.fixture(autouse=True)
@pytest.fixture(autouse=True, scope="class")
def setup_teardown(self, document_store):
document_store.collection.delete_many({})
document_store.write_documents(
Expand All @@ -39,9 +45,13 @@ def setup_teardown(self, document_store):
]
)

# Wait for documents to be indexed
sleep(5)

yield

def test_pipeline_correctly_passes_parameters(self, document_store: MongoDBAtlasDocumentStore):
def test_pipeline_correctly_passes_parameters(self):
document_store = get_document_store()
mock_collection = MagicMock()
document_store._collection = mock_collection
mock_collection.aggregate.return_value = []
Expand Down

0 comments on commit d92dc40

Please sign in to comment.