|
10 | 10 | from haystack.dataclasses import Document |
11 | 11 | from haystack.document_stores.errors import DuplicateDocumentError |
12 | 12 | from haystack.document_stores.types import DocumentStore, DuplicatePolicy |
13 | | -from haystack.testing.document_store import AssertDocumentsEqualMixin |
| 13 | +from haystack.testing.document_store import AssertDocumentsEqualMixin, FilterableDocsFixtureMixin |
14 | 14 |
|
15 | 15 |
|
16 | 16 | class AsyncDocumentStore(DocumentStore, Protocol): |
@@ -550,3 +550,49 @@ async def test_get_metadata_field_unique_values_basic_async(document_store: Asyn |
550 | 550 | assert set(values) == {"A", "B", "C"} |
551 | 551 | if isinstance(result, tuple) and len(result) >= 2 and isinstance(result[1], int): |
552 | 552 | assert result[1] == 3 |
| 553 | + |
| 554 | + |
| 555 | +class FilterDocumentsAsyncTest(AssertDocumentsEqualMixin, FilterableDocsFixtureMixin): |
| 556 | + """ |
| 557 | + Smoke tests for the async filter_documents_async() path. |
| 558 | +
|
| 559 | + These tests verify that the async plumbing works correctly with no filters, |
| 560 | + a simple equality filter, and a compound AND filter. Full filter logic correctness |
| 561 | + is covered by FilterDocumentsTest — the sync and async paths share the same |
| 562 | + filter translation layer, so only the async dispatch needs smoke-testing here. |
| 563 | + """ |
| 564 | + |
| 565 | + @staticmethod |
| 566 | + @pytest.mark.asyncio |
| 567 | + async def test_no_filters_async(document_store: AsyncDocumentStore): |
| 568 | + """Verify the async path returns all documents when no filter is applied.""" |
| 569 | + docs = [Document(content="first doc"), Document(content="second doc"), Document(content="third doc")] |
| 570 | + await document_store.write_documents_async(docs) |
| 571 | + result = await document_store.filter_documents_async() |
| 572 | + assert len(result) == 3 |
| 573 | + |
| 574 | + @pytest.mark.asyncio |
| 575 | + async def test_filter_simple_async(self, document_store: AsyncDocumentStore, filterable_docs: list[Document]): |
| 576 | + """One equality filter — confirms async plumbing works with a filter.""" |
| 577 | + await document_store.write_documents_async(filterable_docs) |
| 578 | + result = await document_store.filter_documents_async( |
| 579 | + filters={"field": "meta.number", "operator": "==", "value": 2} |
| 580 | + ) |
| 581 | + self.assert_documents_are_equal(result, [d for d in filterable_docs if d.meta.get("number") == 2]) |
| 582 | + |
| 583 | + @pytest.mark.asyncio |
| 584 | + async def test_filter_compound_async(self, document_store: AsyncDocumentStore, filterable_docs: list[Document]): |
| 585 | + """One AND filter — verifies compound filters aren't broken by the async path.""" |
| 586 | + await document_store.write_documents_async(filterable_docs) |
| 587 | + result = await document_store.filter_documents_async( |
| 588 | + filters={ |
| 589 | + "operator": "AND", |
| 590 | + "conditions": [ |
| 591 | + {"field": "meta.number", "operator": "==", "value": 2}, |
| 592 | + {"field": "meta.name", "operator": "==", "value": "name_0"}, |
| 593 | + ], |
| 594 | + } |
| 595 | + ) |
| 596 | + self.assert_documents_are_equal( |
| 597 | + result, [d for d in filterable_docs if d.meta.get("number") == 2 and d.meta.get("name") == "name_0"] |
| 598 | + ) |
0 commit comments