11import asyncio
22import csv
33import json
4+ import ssl
5+ import sys
6+ from logging import warning
47from pathlib import Path
58from uuid import uuid4
69
710import pytest
11+
12+ try :
13+ import truststore
14+
15+ has_truststore = True
16+ except ImportError :
17+ if sys .version_info > (3 , 10 ):
18+ warning (
19+ "truststore is not installed, SSL verification will not work. run pip install truststore"
20+ )
21+ has_truststore = True
822from httpx import AsyncClient as HttpxAsyncClient
923
1024from meilisearch_python_sdk import AsyncClient , Client
2236)
2337
2438MASTER_KEY = "masterKey"
25- BASE_URL = "http ://127.0.0.1:7700"
39+ BASE_URL = "https ://127.0.0.1:7700"
2640
2741ROOT_PATH = Path ().absolute ()
2842SMALL_MOVIES_PATH = ROOT_PATH / "datasets" / "small_movies.json"
2943
44+ _SSL_VERIFY : ssl .SSLContext | bool = (
45+ truststore .SSLContext (ssl .PROTOCOL_TLS_CLIENT ) if has_truststore else False
46+ )
47+
48+
49+ @pytest .fixture (scope = "session" )
50+ async def ssl_verify ():
51+ yield _SSL_VERIFY
52+
3053
3154@pytest .fixture
3255async def async_client ():
33- async with AsyncClient (BASE_URL , MASTER_KEY ) as client :
56+ async with AsyncClient (BASE_URL , MASTER_KEY , verify = _SSL_VERIFY ) as client :
3457 yield client
3558
3659
3760@pytest .fixture
3861async def async_client_orjson_handler ():
39- async with AsyncClient (BASE_URL , MASTER_KEY , json_handler = OrjsonHandler ()) as client :
62+ async with AsyncClient (
63+ BASE_URL , MASTER_KEY , json_handler = OrjsonHandler (), verify = _SSL_VERIFY
64+ ) as client :
4065 yield client
4166
4267
4368@pytest .fixture
4469async def async_client_ujson_handler ():
45- async with AsyncClient (BASE_URL , MASTER_KEY , json_handler = UjsonHandler ()) as client :
70+ async with AsyncClient (
71+ BASE_URL , MASTER_KEY , json_handler = UjsonHandler (), verify = _SSL_VERIFY
72+ ) as client :
4673 yield client
4774
4875
4976@pytest .fixture
5077async def async_client_with_plugins ():
51- async with AsyncClient (BASE_URL , MASTER_KEY ) as client :
78+ async with AsyncClient (BASE_URL , MASTER_KEY , verify = _SSL_VERIFY ) as client :
5279 yield client
5380
5481
5582@pytest .fixture
5683def client ():
57- yield Client (BASE_URL , MASTER_KEY )
84+ yield Client (BASE_URL , MASTER_KEY , verify = _SSL_VERIFY )
5885
5986
6087@pytest .fixture
6188def client_orjson_handler ():
62- yield Client (BASE_URL , MASTER_KEY , json_handler = OrjsonHandler ())
89+ yield Client (BASE_URL , MASTER_KEY , json_handler = OrjsonHandler (), verify = _SSL_VERIFY )
6390
6491
6592@pytest .fixture
6693def client_ujson_handler ():
67- yield Client (BASE_URL , MASTER_KEY , json_handler = UjsonHandler ())
94+ yield Client (BASE_URL , MASTER_KEY , json_handler = UjsonHandler (), verify = _SSL_VERIFY )
6895
6996
7097@pytest .fixture (autouse = True )
@@ -254,7 +281,7 @@ async def default_search_key(async_client):
254281@pytest .fixture (scope = "session" , autouse = True )
255282async def enable_vector_search ():
256283 async with HttpxAsyncClient (
257- base_url = BASE_URL , headers = {"Authorization" : f"Bearer { MASTER_KEY } " }
284+ base_url = BASE_URL , headers = {"Authorization" : f"Bearer { MASTER_KEY } " }, verify = _SSL_VERIFY
258285 ) as client :
259286 await client .patch ("/experimental-features" , json = {"vectorStore" : True })
260287 yield
@@ -263,7 +290,7 @@ async def enable_vector_search():
263290@pytest .fixture (scope = "session" , autouse = True )
264291async def enable_edit_by_function ():
265292 async with HttpxAsyncClient (
266- base_url = BASE_URL , headers = {"Authorization" : f"Bearer { MASTER_KEY } " }
293+ base_url = BASE_URL , headers = {"Authorization" : f"Bearer { MASTER_KEY } " }, verify = _SSL_VERIFY
267294 ) as client :
268295 await client .patch ("/experimental-features" , json = {"editDocumentsByFunction" : True })
269296 yield
0 commit comments