Skip to content

Commit 398762d

Browse files
committed
test improvement in progress
1 parent 5925f7b commit 398762d

6 files changed

+72
-29
lines changed

meilisearch/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from time import sleep
44
from meilisearch._httprequests import HttpRequests
55

6-
# pylint: disable=R0904
6+
# pylint: disable=too-many-public-methods
77
class Index():
88
"""
99
Indexes routes wrapper

meilisearch/tests/test_accept_new_fields_meilisearch.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,28 @@
22
from meilisearch.tests import BASE_URL, MASTER_KEY
33

44
class TestAcceptNewFields:
5+
6+
""" TESTS: acceptNewFields setting """
7+
58
client = meilisearch.Client(BASE_URL, MASTER_KEY)
69
index = client.create_index(uid='indexUID')
710
new_accept_new_fields = True
811

912
def teardown_class(self):
1013
self.index.delete()
1114

12-
def test_update_accept_new_fields(self):
13-
response = self.index.update_accept_new_fields(self.new_accept_new_fields)
14-
assert isinstance(response, object)
15-
assert 'updateId' in response
16-
1715
def test_get_accept_new_fields(self):
16+
""" Test the default behaviour of getting acceptNewFields setting """
1817
response = self.index.get_accept_new_fields()
1918
assert isinstance(response, object)
2019
assert response == self.new_accept_new_fields
20+
21+
def test_update_accept_new_fields(self):
22+
""" Test the changing the acceptNewFields value in MeiliSearch """
23+
response = self.index.update_accept_new_fields(not self.new_accept_new_fields)
24+
assert isinstance(response, object)
25+
assert 'updateId' in response
26+
update = self.index.wait_for_pending_update(response['updateId'])
27+
assert update['status'] == 'processed'
28+
response = self.index.get_accept_new_fields()
29+
assert response == (not self.new_accept_new_fields)

meilisearch/tests/test_client_meilisearch.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,26 @@
44

55
class TestClient:
66

7-
""" Client """
7+
""" TESTS: Client class """
8+
89
@staticmethod
910
def test_get_client():
1011
"""Tests a call to get a client instance of MeiliSearch"""
1112
client = meilisearch.Client(BASE_URL, MASTER_KEY)
1213
assert client.config
13-
response = client.get_indexes()
14-
assert isinstance(response, list)
14+
response = client.health()
15+
assert response.status_code == 200
1516

1617
@staticmethod
1718
def test_get_client_without_master_key():
18-
"""Tests a call to get a client instance of MeiliSearch"""
19+
"""Tests to get a client instance of MeiliSearch without MASTER KEY"""
1920
client = meilisearch.Client(BASE_URL)
2021
with pytest.raises(Exception):
21-
client.get_indexes()
22+
client.get_version()
23+
24+
@staticmethod
25+
def test_get_client_with_wrong_master_key():
26+
"""Tests to get a client instance of MeiliSearch with an invalid MASTER KEY"""
27+
client = meilisearch.Client(BASE_URL, MASTER_KEY + "123")
28+
with pytest.raises(Exception):
29+
client.get_version()
Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,50 @@
1-
import time
1+
import json
22
import meilisearch
33
from meilisearch.tests import BASE_URL, MASTER_KEY
44

55
class TestSearchableAttributes:
6+
7+
""" TESTS: displayedAttributes setting """
8+
69
client = meilisearch.Client(BASE_URL, MASTER_KEY)
710
index = None
8-
new_displayed_attributes = ['title']
11+
displayed_attributes = ['id', 'release_date', 'title', 'poster', 'overview']
912

1013
def setup_class(self):
1114
self.index = self.client.create_index(uid='indexUID')
1215

1316
def teardown_class(self):
1417
self.index.delete()
1518

16-
def test_update_displayed_attributes(self):
17-
response = self.index.update_displayed_attributes(self.new_displayed_attributes)
18-
assert isinstance(response, object)
19-
assert 'updateId' in response
20-
2119
def test_get_displayed_attributes(self):
20+
"""Tests a call to get displayedAttributes before and after indexig a dataset"""
2221
response = self.index.get_displayed_attributes()
2322
assert isinstance(response, object)
24-
assert response == self.new_displayed_attributes
23+
assert response == []
24+
json_file = open('./datasets/small_movies.json')
25+
data = json.load(json_file)
26+
response = self.index.add_documents(data, primary_key='id')
27+
self.index.wait_for_pending_update(response['updateId'])
28+
get_attributes = self.index.get_displayed_attributes()
29+
for attribute in self.displayed_attributes:
30+
assert attribute in get_attributes
31+
32+
def test_update_displayed_attributes(self):
33+
"""Tests the modification of displayedAttributes"""
34+
get_attributes = self.index.get_displayed_attributes()
35+
response = self.index.update_displayed_attributes(get_attributes[1:])
36+
self.index.wait_for_pending_update(response['updateId'])
37+
get_attributes_new = self.index.get_displayed_attributes()
38+
assert len(get_attributes_new) == len(self.displayed_attributes) - 1
39+
assert get_attributes[0] not in get_attributes_new
2540

2641
def test_reset_displayed_attributes(self):
42+
"""Tests the reset of displayedAttributes to default values (in dataset)"""
2743
response = self.index.reset_displayed_attributes()
2844
assert isinstance(response, object)
2945
assert 'updateId' in response
30-
time.sleep(0.1)
31-
response = self.index.get_displayed_attributes()
32-
assert isinstance(response, list)
46+
self.index.wait_for_pending_update(response['updateId'])
47+
get_attributes = self.index.get_displayed_attributes()
48+
assert len(get_attributes) == len(self.displayed_attributes)
49+
for attribute in self.displayed_attributes:
50+
assert attribute in get_attributes
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import time
21
import meilisearch
32
from meilisearch.tests import BASE_URL, MASTER_KEY
43

54
class TestDistinctAttribute:
5+
6+
""" TESTS: distinctAttribute setting """
7+
68
client = meilisearch.Client(BASE_URL, MASTER_KEY)
79
index = None
810
new_distinct_attribute = 'title'
@@ -14,20 +16,27 @@ def setup_class(self):
1416
def teardown_class(self):
1517
self.index.delete()
1618

19+
def test_get_distinct_attribute(self):
20+
"""Tests a call to get distinctAttribute geting `None`(null) default value"""
21+
response = self.index.get_distinct_attribute()
22+
assert isinstance(response, object)
23+
assert response == self.default_distinct_attribute
24+
1725
def test_update_distinct_attribute(self):
26+
"""Tests a call to set a custom distinctAttribute and checks it has ben set in MeiliSearch"""
1827
response = self.index.update_distinct_attribute(self.new_distinct_attribute)
1928
assert isinstance(response, object)
2029
assert 'updateId' in response
21-
22-
def test_get_distinct_attribute(self):
30+
self.index.wait_for_pending_update(response['updateId'])
2331
response = self.index.get_distinct_attribute()
2432
assert isinstance(response, object)
2533
assert response == self.new_distinct_attribute
2634

2735
def test_reset_distinct_attribute(self):
36+
"""Tests a call to reset distinctAttribute geting `None`(null) default value again"""
2837
response = self.index.reset_distinct_attribute()
2938
assert isinstance(response, object)
3039
assert 'updateId' in response
31-
time.sleep(0.1)
40+
self.index.wait_for_pending_update(response['updateId'])
3241
response = self.index.get_distinct_attribute()
3342
assert response == self.default_distinct_attribute

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import setuptools
2-
from setuptools import setup
1+
from setuptools import setup, find_packages
32

43
with open("README.md", "r") as fh:
54
long_description = fh.read()
@@ -16,7 +15,7 @@
1615
long_description=long_description,
1716
long_description_content_type="text/markdown",
1817
url="https://github.com/meilisearch/meilisearch-python",
19-
packages=["meilisearch"],
18+
packages=find_packages(),
2019
project_urls={"Documentation": "https://docs.meilisearch.com/",},
2120
keywords="search python meilisearch",
2221
platform="any",

0 commit comments

Comments
 (0)