Skip to content

Commit cd0c1ba

Browse files
authored
Merge branch 'main' into meili-bot/code-samples-v0-28
2 parents 39ced55 + 65663d8 commit cd0c1ba

File tree

12 files changed

+190
-102
lines changed

12 files changed

+190
-102
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
name: integration-tests
2222
runs-on: ubuntu-latest
2323
steps:
24-
- uses: actions/checkout@v2
24+
- uses: actions/checkout@v3
2525
- name: Set up Python ${{ matrix.python-version }}
2626
uses: actions/setup-python@v2
2727
with:
@@ -39,7 +39,7 @@ jobs:
3939
name: pylint
4040
runs-on: ubuntu-latest
4141
steps:
42-
- uses: actions/checkout@v2
42+
- uses: actions/checkout@v3
4343
- name: Set up Python 3.7
4444
uses: actions/setup-python@v2
4545
with:
@@ -55,7 +55,7 @@ jobs:
5555
name: mypy
5656
runs-on: ubuntu-latest
5757
steps:
58-
- uses: actions/checkout@v2
58+
- uses: actions/checkout@v3
5959
- name: Set up Python 3.9
6060
uses: actions/setup-python@v2
6161
with:

CONTRIBUTING.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ First of all, thank you for contributing to Meilisearch! The goal of this docume
2828

2929
### Setup <!-- omit in toc -->
3030

31+
You can set up your local environment natively or using `docker`, check out the [`docker-compose.yml`](/docker-compose.yml).
32+
33+
Example of running all the checks with docker:
34+
```bash
35+
docker-compose run --rm package bash -c "pipenv run mypy meilisearch && pipenv run pylint meilisearch && pipenv run pytest tests"
36+
```
37+
38+
To install dependencies:
39+
3140
```bash
3241
pipenv install --dev
3342
```
@@ -40,7 +49,7 @@ Each PR should pass the tests, mypy type checking, and the linter to be accepted
4049
# Tests
4150
curl -L https://install.meilisearch.com | sh # download Meilisearch
4251
./meilisearch --master-key=masterKey --no-analytics # run Meilisearch
43-
pipenv run pytest meilisearch
52+
pipenv run pytest tests
4453
# MyPy
4554
pipenv run mypy meilisearch
4655
# Linter

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.8.4-buster
2+
3+
COPY Pipfile .
4+
COPY Pipfile.lock .
5+
6+
RUN apt-get update -y
7+
8+
# Install pipenv and compilation dependencies
9+
RUN pip3 install pipenv
10+
RUN pipenv install --dev

Pipfile.lock

Lines changed: 98 additions & 88 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
version: "3.8"
2+
3+
services:
4+
package:
5+
build: .
6+
tty: true
7+
stdin_open: true
8+
working_dir: /home/package
9+
environment:
10+
- MEILISEARCH_HOST=http://meilisearch:7700
11+
depends_on:
12+
- meilisearch
13+
links:
14+
- meilisearch
15+
volumes:
16+
- ./:/home/package
17+
18+
meilisearch:
19+
image: getmeili/meilisearch:latest
20+
ports:
21+
- "7700"
22+
environment:
23+
- MEILI_MASTER_KEY=masterKey
24+
- MEILI_NO_ANALYTICS=true

meilisearch/client.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,14 @@ def get_key(self, key_or_uid: str) -> Dict[str, Any]:
262262
"""
263263
return self.http.get(f'{self.config.paths.keys}/{key_or_uid}')
264264

265-
def get_keys(self) -> Dict[str, Any]:
265+
def get_keys(self, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
266266
"""Gets the Meilisearch API keys.
267267
268+
Parameters
269+
----------
270+
parameters (optional):
271+
parameters accepted by the get keys route: https://docs.meilisearch.com/reference/api/keys.html#get-all-keys
272+
268273
Returns
269274
-------
270275
keys:
@@ -276,7 +281,11 @@ def get_keys(self) -> Dict[str, Any]:
276281
MeiliSearchApiError
277282
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
278283
"""
279-
return self.http.get(self.config.paths.keys)
284+
if parameters is None:
285+
parameters = {}
286+
return self.http.get(
287+
f'{self.config.paths.keys}?{parse.urlencode(parameters)}'
288+
)
280289

281290
def create_key(
282291
self,

meilisearch/index.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,15 @@ def search(self, query: str, opt_params: Optional[Dict[str, Any]] = None) -> Dic
249249
body=body
250250
)
251251

252-
def get_document(self, document_id: str) -> Dict[str, Any]:
252+
def get_document(self, document_id: str, parameters: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
253253
"""Get one document with given document identifier.
254254
255255
Parameters
256256
----------
257257
document_id:
258258
Unique identifier of the document.
259+
parameters (optional):
260+
parameters accepted by the get document route: https://docs.meilisearch.com/reference/api/documents.html#get-one-document
259261
260262
Returns
261263
-------
@@ -267,8 +269,12 @@ def get_document(self, document_id: str) -> Dict[str, Any]:
267269
MeiliSearchApiError
268270
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
269271
"""
272+
if parameters is None:
273+
parameters = {}
274+
elif 'fields' in parameters and isinstance(parameters['fields'], list):
275+
parameters['fields'] = ",".join(parameters['fields'])
270276
return self.http.get(
271-
f'{self.config.paths.index}/{self.uid}/{self.config.paths.document}/{document_id}'
277+
f'{self.config.paths.index}/{self.uid}/{self.config.paths.document}/{document_id}?{parse.urlencode(parameters)}'
272278
)
273279

274280
def get_documents(self, parameters: Optional[Dict[str, Any]] = None) -> List[Dict[str, Any]]:
@@ -291,6 +297,8 @@ def get_documents(self, parameters: Optional[Dict[str, Any]] = None) -> List[Dic
291297
"""
292298
if parameters is None:
293299
parameters = {}
300+
elif 'fields' in parameters and isinstance(parameters['fields'], list):
301+
parameters['fields'] = ",".join(parameters['fields'])
294302
return self.http.get(
295303
f'{self.config.paths.index}/{self.uid}/{self.config.paths.document}?{parse.urlencode(parameters)}'
296304
)

meilisearch/task.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ def get_tasks(config: Config, parameters: Optional[Dict[str, Any]] = None) -> Di
2929
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
3030
"""
3131
http = HttpRequests(config)
32-
if parameters is None or parameters == {}:
32+
if parameters is None:
3333
parameters = {}
34-
elif 'indexUid' in parameters:
35-
parameters['indexUid'] = ",".join(parameters['indexUid'])
34+
for param in parameters:
35+
if isinstance(parameters[param], list):
36+
parameters[param] = ",".join(parameters[param])
3637
return http.get(
3738
f"{config.paths.task}?{parse.urlencode(parameters)}"
3839
)

tests/client/test_client_key_meilisearch.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ def test_get_keys_default(client):
1313
assert keys['results'][0]['key'] is not None
1414
assert keys['results'][1]['key'] is not None
1515

16+
def test_get_keys_with_parameters(client):
17+
"""Tests if search and admin keys have been generated and can be retrieved."""
18+
keys = client.get_keys({'limit': 1})
19+
assert isinstance(keys, dict)
20+
assert len(keys['results']) == 1
21+
1622
def test_get_key(client, test_key):
1723
"""Tests if a key can be retrieved."""
1824
key = client.get_key(test_key['key'])
@@ -65,7 +71,7 @@ def test_update_keys(client, test_key_info):
6571
"""Tests updating a key."""
6672
key = client.create_key(test_key_info)
6773
assert key['name'] == test_key_info['name']
68-
update_key = client.update_key(key=key['key'], options={ 'name': 'keyTest' })
74+
update_key = client.update_key(key_or_uid=key['key'], options={ 'name': 'keyTest' })
6975
assert update_key['key'] is not None
7076
assert update_key['expiresAt'] is None
7177
assert update_key['name'] == 'keyTest'

tests/common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import os
2+
13
MASTER_KEY = 'masterKey'
2-
BASE_URL = 'http://127.0.0.1:7700'
4+
BASE_URL = os.getenv('MEILISEARCH_HOST') if os.getenv('MEILISEARCH_HOST') else 'http://127.0.0.1:7700'
35

46
INDEX_UID = 'indexUID'
57
INDEX_UID2 = 'indexUID2'

tests/index/test_index_document_meilisearch.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ def test_get_document(index_with_documents):
5050
assert 'title' in response
5151
assert response['title'] == 'The Highwaymen'
5252

53+
def test_get_document_with_fields(index_with_documents):
54+
"""Tests getting one document from a populated index."""
55+
response = index_with_documents().get_document('500682', {'fields' : ['id', 'title']})
56+
assert isinstance(response, dict)
57+
assert 'title' in response
58+
assert 'poster' not in response
59+
assert response['title'] == 'The Highwaymen'
60+
5361
def test_get_document_inexistent(empty_index):
5462
"""Tests getting one inexistent document from a populated index."""
5563
with pytest.raises(Exception):
@@ -73,6 +81,7 @@ def test_get_documents_offset_optional_params(index_with_documents):
7381
'fields': 'title'
7482
})
7583
assert len(response_offset_limit['results']) == 3
84+
assert 'title' in response_offset_limit['results'][0]
7685
assert response_offset_limit['results'][0]['title'] == response['results'][1]['title']
7786

7887
def test_update_documents(index_with_documents, small_movies):

tests/index/test_index_task_meilisearch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_get_tasks_default(index_with_documents):
1212

1313
def test_get_tasks(empty_index, small_movies):
1414
"""Tests getting the tasks list of a populated index."""
15-
index = empty_index()
15+
index = empty_index("test_task")
1616
current_tasks = index.get_tasks()
1717
pre_count = len(current_tasks['results'])
1818
response = index.add_documents(small_movies)

0 commit comments

Comments
 (0)