forked from testcontainers/testcontainers-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_qdrant.py
More file actions
80 lines (58 loc) · 2.53 KB
/
test_qdrant.py
File metadata and controls
80 lines (58 loc) · 2.53 KB
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
import pytest
from testcontainers.qdrant import QdrantContainer
import uuid
from grpc import RpcError
from pathlib import Path
import qdrant_client
def test_docker_run_qdrant():
with QdrantContainer() as qdrant:
client = qdrant.get_client()
collections = client.get_collections().collections
assert len(collections) == 0
client = qdrant.get_client(prefer_grpc=True)
collections = client.get_collections().collections
assert len(collections) == 0
def test_qdrant_with_api_key_http():
api_key = uuid.uuid4().hex
with QdrantContainer(api_key=api_key) as qdrant:
with pytest.raises(qdrant_client.http.exceptions.UnexpectedResponse) as e:
# Construct a client without an API key
qdrant_client.QdrantClient(location=f"http://{qdrant.rest_host_address}").get_collections()
assert "Must provide an API key" in str(e.value)
# Construct a client with an API key
collections = (
qdrant_client.QdrantClient(location=f"http://{qdrant.rest_host_address}", api_key=api_key)
.get_collections()
.collections
)
assert len(collections) == 0
# Get an automatically configured client instance
collections = qdrant.get_client().get_collections().collections
assert len(collections) == 0
def test_qdrant_with_api_key_grpc():
api_key = uuid.uuid4().hex
with QdrantContainer(api_key=api_key) as qdrant:
with pytest.raises(RpcError) as e:
qdrant_client.QdrantClient(
url=f"http://{qdrant.grpc_host_address}",
grpc_port=qdrant.exposed_grpc_port,
prefer_grpc=True,
).get_collections()
assert "Must provide an API key" in str(e.value)
collections = (
qdrant_client.QdrantClient(
url=f"http://{qdrant.grpc_host_address}",
grpc_port=qdrant.exposed_grpc_port,
prefer_grpc=True,
api_key=api_key,
)
.get_collections()
.collections
)
assert len(collections) == 0
def test_qdrant_with_config_file():
config_file_path = Path(__file__).with_name("test_config.yaml")
with QdrantContainer(config_file_path=config_file_path) as qdrant:
with pytest.raises(qdrant_client.http.exceptions.UnexpectedResponse) as e:
qdrant_client.QdrantClient(location=f"http://{qdrant.rest_host_address}").get_collections()
assert "Must provide an API key" in str(e.value)