Skip to content

Commit f9e1d73

Browse files
committed
Updated tests
1 parent 8002de4 commit f9e1d73

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

manticoresearch/rest.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import re
1919
import ssl
2020
from typing import Optional, Union
21-
from pprint import pprint
2221

2322
import aiohttp
2423
import aiohttp_retry
@@ -27,7 +26,7 @@
2726

2827
RESTResponseType = aiohttp.ClientResponse
2928

30-
ALLOW_RETRY_METHODS = frozenset({'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'TRACE', 'POST'})
29+
ALLOW_RETRY_METHODS = frozenset({'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'TRACE'})
3130

3231
class RESTResponse(io.IOBase):
3332

@@ -87,7 +86,6 @@ def __init__(self, configuration) -> None:
8786
retries = configuration.retries
8887
self.retry_client: Optional[aiohttp_retry.RetryClient]
8988
if retries is not None:
90-
pprint(retries)
9189
self.retry_client = aiohttp_retry.RetryClient(
9290
client_session=self.pool_manager,
9391
retry_options=aiohttp_retry.ExponentialRetry(
@@ -204,7 +202,6 @@ async def request(
204202

205203
pool_manager: Union[aiohttp.ClientSession, aiohttp_retry.RetryClient]
206204
if self.retry_client is not None and method in ALLOW_RETRY_METHODS:
207-
pprint("with retries")
208205
pool_manager = self.retry_client
209206
else:
210207
pool_manager = self.pool_manager

test/test_manual.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ class TestManualApi(IsolatedAsyncioTestCase):
2222

2323
def setUp(self):
2424
self.configuration = manticoresearch.Configuration(
25-
host = "http://localhost:9408",
26-
retries = 10
25+
host = "http://localhost:9408"
2726
)
2827

2928
def tearDown(self):
@@ -33,12 +32,40 @@ def tearDown(self):
3332
async def test_manual(self):
3433
async with manticoresearch.ApiClient(self.configuration) as client:
3534
utilsApi = manticoresearch.UtilsApi(client)
36-
res = await utilsApi.sql('query=DROP TABLE IF EXISTS movies')
37-
pprint(res)
38-
sleep(10)
39-
res = await utilsApi.sql("CREATE TABLE IF NOT EXISTS movies (title text, plot text, _year integer, rating float, code multi) min_infix_len='2'")
35+
await utilsApi.sql('query=DROP TABLE IF EXISTS movies')
36+
37+
async with manticoresearch.ApiClient(self.configuration) as client:
38+
utilsApi = manticoresearch.UtilsApi(client)
39+
await utilsApi.sql("CREATE TABLE IF NOT EXISTS movies (title text, plot text, _year integer, rating float, code multi) min_infix_len='2'")
40+
41+
42+
searchApi = manticoresearch.SearchApi(client)
43+
44+
docs = [ \
45+
{"insert": {"table" : "movies", "id" : 1, "doc" : {"title" : "Star Trek 2: Nemesis", "plot": "The Enterprise is diverted to the Romulan homeworld Romulus, supposedly because they want to negotiate a peace treaty. Captain Picard and his crew discover a serious threat to the Federation once Praetor Shinzon plans to attack Earth.", "_year": 2002, "rating": 6.4, "code": [1,2,3]}}}, \
46+
{"insert": {"table" : "movies", "id" : 2, "doc" : {"title" : "Star Trek 1: Nemesis", "plot": "The Enterprise is diverted to the Romulan homeworld Romulus, supposedly because they want to negotiate a peace treaty. Captain Picard and his crew discover a serious threat to the Federation once Praetor Shinzon plans to attack Earth.", "_year": 2001, "rating": 6.5, "code": [1,12,3]}}},
47+
{"insert": {"table" : "movies", "id" : 3, "doc" : {"title" : "Star Trek 3: Nemesis", "plot": "The Enterprise is diverted to the Romulan homeworld Romulus, supposedly because they want to negotiate a peace treaty. Captain Picard and his crew discover a serious threat to the Federation once Praetor Shinzon plans to attack Earth.", "_year": 2003, "rating": 6.6, "code": [11,2,3]}}}, \
48+
{"insert": {"table" : "movies", "id" : 4, "doc" : {"title" : "Star Trek 4: Nemesis", "plot": "The Enterprise is diverted to the Romulan homeworld Romulus, supposedly because they want to negotiate a peace treaty. Captain Picard and his crew discover a serious threat to the Federation once Praetor Shinzon plans to attack Earth.", "_year": 2003, "rating": 6.5, "code": [1,2,4]}}},
49+
]
50+
async with manticoresearch.ApiClient(self.configuration) as client:
51+
indexApi = manticoresearch.IndexApi(client)
52+
indexApi.bulk('\n'.join(map(json.dumps,docs)))
53+
54+
search_request = SearchRequest(
55+
table="movies",
56+
)
57+
matchFilter = QueryFilter()
58+
matchFilter.match = {"title":"4"}
59+
mustCond = [ matchFilter ]
60+
boolFilter = BoolFilter(must=mustCond)
61+
searchQuery = SearchQuery(bool={"must": [ {"match": {"title":"4"}}] })
62+
search_request.query = searchQuery
63+
64+
async with manticoresearch.ApiClient(self.configuration) as client:
65+
searchApi = manticoresearch.SearchApi(client)
66+
res = searchApi.search(search_request)
4067
pprint(res)
4168

42-
pprint("Tests finished")
69+
pprint("Tests finished")
4370
if __name__ == '__main__':
4471
unittest.main()

0 commit comments

Comments
 (0)