Skip to content

Commit 1ec1f34

Browse files
committed
Inspect http_method name for get and exclude body
1 parent 561ff46 commit 1ec1f34

10 files changed

+12
-9
lines changed

meilisearch/_httprequests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def send_request(
3333
self.headers["Content-Type"] = content_type
3434
try:
3535
request_path = self.config.url + "/" + path
36-
if body is None or body == "":
36+
if http_method.__name__ == "get":
3737
request = http_method(
3838
request_path,
3939
timeout=self.config.timeout,
@@ -51,7 +51,7 @@ def send_request(
5151
request_path,
5252
timeout=self.config.timeout,
5353
headers=self.headers,
54-
data=json.dumps(body),
54+
data=json.dumps(body) if body else "" if body == "" else "null",
5555
)
5656
return self.__validate(request)
5757

tests/errors/test_api_error_meilisearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_meilisearch_api_error_wrong_master_key():
2525
@patch("requests.post")
2626
def test_meilisearch_api_error_no_code(mock_post):
2727
"""Here to test for regressions related to https://github.com/meilisearch/meilisearch-python/issues/305."""
28-
28+
mock_post.configure_mock(__name__="post")
2929
mock_response = requests.models.Response()
3030
mock_response.status_code = 408
3131
mock_post.return_value = mock_response

tests/errors/test_communication_error_meilisearch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
@patch("requests.post")
1414
def test_meilisearch_communication_error_host(mock_post):
15+
mock_post.configure_mock(__name__="post")
1516
mock_post.side_effect = requests.exceptions.ConnectionError()
1617
client = meilisearch.Client("http://wrongurl:1234", MASTER_KEY)
1718
with pytest.raises(MeilisearchCommunicationError):

tests/errors/test_timeout_error_meilisearch.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
@patch("requests.get")
1212
def test_client_timeout_error(mock_get):
13+
mock_get.configure_mock(__name__="get")
1314
mock_get.side_effect = requests.exceptions.Timeout()
1415
client = meilisearch.Client(BASE_URL, MASTER_KEY, timeout=1)
1516

tests/settings/test_settings_displayed_attributes_meilisearch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def test_update_displayed_attributes_to_none(empty_index):
3636
get_attributes = index.get_displayed_attributes()
3737
for attribute in DISPLAYED_ATTRIBUTES:
3838
assert attribute in get_attributes
39-
response = index.reset_displayed_attributes()
39+
# Launch test to update at null the setting
40+
response = index.update_displayed_attributes(None)
4041
index.wait_for_task(response.task_uid)
4142
response = index.get_displayed_attributes()
4243
assert response == ["*"]

tests/settings/test_settings_distinct_attribute_meilisearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_update_distinct_at_to_none(empty_index):
2828
response = index.get_distinct_attribute()
2929
assert response == NEW_DISTINCT_ATTRIBUTE
3030
# Launch test to update at null the setting
31-
response = index.reset_distinct_attribute()
31+
response = index.update_distinct_attribute(None)
3232
index.wait_for_task(response.task_uid)
3333
response = index.get_distinct_attribute()
3434
assert response == DEFAULT_DISTINCT_ATTRIBUTE

tests/settings/test_settings_filterable_attributes_meilisearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_update_filterable_attributes_to_none(empty_index):
3232
for attribute in FILTERABLE_ATTRIBUTES:
3333
assert attribute in get_attributes
3434
# Launch test to update at null the setting
35-
response = index.reset_filterable_attributes()
35+
response = index.update_filterable_attributes(None)
3636
index.wait_for_task(response.task_uid)
3737
response = index.get_filterable_attributes()
3838
assert response == []

tests/settings/test_settings_ranking_rules_meilisearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_update_ranking_rules_none(empty_index):
3131
for rule in NEW_RANKING_RULES:
3232
assert rule in response
3333
# Launch test to update at null the setting
34-
response = index.reset_ranking_rules()
34+
response = index.update_ranking_rules(None)
3535
index.wait_for_task(response.task_uid)
3636
response = index.get_ranking_rules()
3737
for rule in DEFAULT_RANKING_RULES:

tests/settings/test_settings_searchable_attributes_meilisearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_update_searchable_attributes_to_none(empty_index):
3737
for attribute in NEW_SEARCHABLE_ATTRIBUTES:
3838
assert attribute in response
3939
# Launch test to update at null the setting
40-
response = index.reset_searchable_attributes()
40+
response = index.update_searchable_attributes(None)
4141
index.wait_for_task(response.task_uid)
4242
response = index.get_searchable_attributes()
4343
assert response == ["*"]

tests/settings/test_settings_sortable_attributes_meilisearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_update_sortable_attributes_to_none(empty_index):
3232
for attribute in SORTABLE_ATTRIBUTES:
3333
assert attribute in get_attributes
3434
# Launch test to update at null the setting
35-
response = index.reset_sortable_attributes()
35+
response = index.update_sortable_attributes(None)
3636
index.wait_for_task(response.task_uid)
3737
response = index.get_sortable_attributes()
3838
assert response == []

0 commit comments

Comments
 (0)