File size: 2,815 Bytes
dbb04e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""

Tests for QdrantStore (Phase 3.5.2)

===================================

Uses unittest.mock to simulate Qdrant backend interactions.

Rewritten to use pytest-asyncio for proper async support.

"""

import pytest
from unittest.mock import MagicMock, patch, ANY
from mnemocore.core.config import get_config, reset_config
from mnemocore.core.qdrant_store import QdrantStore

@pytest.fixture
def mock_qdrant_client():
    with patch("src.core.qdrant_store.AsyncQdrantClient") as MockClass:
        mock_instance = MockClass.return_value
        # Setup default behaviors
        mock_instance.collection_exists.return_value = False
        yield mock_instance

@pytest.fixture
def store(mock_qdrant_client):
    reset_config()
    # Bypass get_instance() patch from conftest.py by instantiating directly
    # We want to test the logic of the class, not the singleton mechanism
    return QdrantStore()

@pytest.mark.asyncio
async def test_ensure_collections(store, mock_qdrant_client):
    # Setup mock to say collections don't exist (already default, but explicit here)
    mock_qdrant_client.collection_exists.return_value = False
    
    await store.ensure_collections()
    
    # Should create HOT and WARM
    assert mock_qdrant_client.create_collection.call_count == 2
    
    # Verify calls
    config = get_config().qdrant
    mock_qdrant_client.create_collection.assert_any_call(
        collection_name=config.collection_hot,
        vectors_config=ANY,
        quantization_config=ANY,
        hnsw_config=ANY
    )
    mock_qdrant_client.create_collection.assert_any_call(
        collection_name=config.collection_warm,
        vectors_config=ANY,
        quantization_config=ANY,
        hnsw_config=ANY
    )

@pytest.mark.asyncio
async def test_upsert(store, mock_qdrant_client):
    points = [MagicMock()]
    await store.upsert("test_coll", points)
    mock_qdrant_client.upsert.assert_called_with(collection_name="test_coll", points=points)

@pytest.mark.asyncio
async def test_search(store, mock_qdrant_client):
    query = [0.1, 0.2]
    await store.search("test_coll", query, limit=5)
    mock_qdrant_client.search.assert_called_with(
        collection_name="test_coll",
        query_vector=query,
        limit=5,
        score_threshold=0.0
    )

@pytest.mark.asyncio
async def test_get_point(store, mock_qdrant_client):
    await store.get_point("test_coll", "id1")
    mock_qdrant_client.retrieve.assert_called_with(
        collection_name="test_coll",
        ids=["id1"],
        with_vectors=True,
        with_payload=True
    )

@pytest.mark.asyncio
async def test_delete(store, mock_qdrant_client):
    await store.delete("test_coll", ["id1"])
    mock_qdrant_client.delete.assert_called_once()