From 3666fcf4f03917148ad01e258faeaab6d621adc8 Mon Sep 17 00:00:00 2001 From: Pavel Belokon Date: Tue, 21 Nov 2023 15:36:38 -0500 Subject: [PATCH 1/5] implemented createSnapshot method and created entry with create_snapshot_1 key --- .code-samples.meilisearch.yaml | 5 +++-- meilisearch/client.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 95da4c0a..fbcf52dc 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -216,8 +216,7 @@ getting_started_typo_tolerance: |- 'oneTypo': 4 } }) -get_typo_tolerance_1: - client.index('books').get_typo_tolerance() +get_typo_tolerance_1: client.index('books').get_typo_tolerance() update_typo_tolerance_1: |- client.index('books').update_typo_tolerance({ 'minWordSizeForTypos': { @@ -701,3 +700,5 @@ update_dictionary_1: |- client.index('books').update_dictionary(["J. R. R.", "W. E. B."]) reset_dictionary_1: |- client.index('books').reset_dictionary() +create_snapshot_1: |- + client.create_snapshot() diff --git a/meilisearch/client.py b/meilisearch/client.py index ed505673..7c741159 100644 --- a/meilisearch/client.py +++ b/meilisearch/client.py @@ -454,6 +454,7 @@ def create_dump(self) -> TaskInfo: task = self.http.post(self.config.paths.dumps) return TaskInfo(**task) + def swap_indexes(self, parameters: List[Dict[str, List[str]]]) -> TaskInfo: """Swap two indexes. @@ -672,3 +673,21 @@ def _valid_uuid(uuid: str) -> bool: ) match = uuid4hex.match(uuid) return bool(match) + + def create_snapshot(self) -> TaskInfo: + """Trigger the creation of a Meilisearch snapshot. + + Returns + ------- + Snapshot: + Information about the snapshot. + https://www.meilisearch.com/docs/reference/api/snapshots#create-a-snapshot + + Raises + ------ + MeilisearchApiError + An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors + """ + task = self.http.post(self.config.paths.snapshots) + + return TaskInfo(**task) \ No newline at end of file From 102651278e168965e8d76a3f5b3cdd87196ae87b Mon Sep 17 00:00:00 2001 From: Pavel Belokon <88114764+pbelokon@users.noreply.github.com> Date: Thu, 23 Nov 2023 11:29:12 -0500 Subject: [PATCH 2/5] Update .code-samples.meilisearch.yaml Co-authored-by: Paul Sanders --- .code-samples.meilisearch.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index fbcf52dc..f3656ff5 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -216,7 +216,8 @@ getting_started_typo_tolerance: |- 'oneTypo': 4 } }) -get_typo_tolerance_1: client.index('books').get_typo_tolerance() +get_typo_tolerance_1: |- + client.index('books').get_typo_tolerance() update_typo_tolerance_1: |- client.index('books').update_typo_tolerance({ 'minWordSizeForTypos': { From 6d4575a68bf11eeebc6d098cdf028e75875d2575 Mon Sep 17 00:00:00 2001 From: Pavel Belokon <88114764+pbelokon@users.noreply.github.com> Date: Thu, 23 Nov 2023 16:42:06 +0000 Subject: [PATCH 3/5] added snapshots to config path and fixed create snapshot in clint.py --- meilisearch/client.py | 37 ++++++++++++++++++------------------- meilisearch/config.py | 1 + 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/meilisearch/client.py b/meilisearch/client.py index 7c741159..f61b40cb 100644 --- a/meilisearch/client.py +++ b/meilisearch/client.py @@ -454,7 +454,24 @@ def create_dump(self) -> TaskInfo: task = self.http.post(self.config.paths.dumps) return TaskInfo(**task) - + + def create_snapshot(self) -> TaskInfo: + """Trigger the creation of a Meilisearch snapshot. + + Returns + ------- + task_info: + TaskInfo instance containing information about a task to track the progress of an asynchronous process. + https://www.meilisearch.com/docs/reference/api/tasks#get-one-task + + Raises + ------ + MeilisearchApiError + An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors + """ + task = self.http.post(self.config.paths.snapshots) + + return TaskInfo(**task) def swap_indexes(self, parameters: List[Dict[str, List[str]]]) -> TaskInfo: """Swap two indexes. @@ -673,21 +690,3 @@ def _valid_uuid(uuid: str) -> bool: ) match = uuid4hex.match(uuid) return bool(match) - - def create_snapshot(self) -> TaskInfo: - """Trigger the creation of a Meilisearch snapshot. - - Returns - ------- - Snapshot: - Information about the snapshot. - https://www.meilisearch.com/docs/reference/api/snapshots#create-a-snapshot - - Raises - ------ - MeilisearchApiError - An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors - """ - task = self.http.post(self.config.paths.snapshots) - - return TaskInfo(**task) \ No newline at end of file diff --git a/meilisearch/config.py b/meilisearch/config.py index 9117b7f8..616c44cf 100644 --- a/meilisearch/config.py +++ b/meilisearch/config.py @@ -31,6 +31,7 @@ class Paths: sortable_attributes = "sortable-attributes" typo_tolerance = "typo-tolerance" dumps = "dumps" + snapshots = "snapshots" pagination = "pagination" faceting = "faceting" dictionary = "dictionary" From ae2b05263fa348759abee21e7a62f215b1b64d57 Mon Sep 17 00:00:00 2001 From: Pavel Belokon <88114764+pbelokon@users.noreply.github.com> Date: Thu, 23 Nov 2023 16:50:29 +0000 Subject: [PATCH 4/5] modeled snapshot creation test of dump creation test --- tests/client/test_clinet_snapshots.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/client/test_clinet_snapshots.py diff --git a/tests/client/test_clinet_snapshots.py b/tests/client/test_clinet_snapshots.py new file mode 100644 index 00000000..8de73c7e --- /dev/null +++ b/tests/client/test_clinet_snapshots.py @@ -0,0 +1,11 @@ +# pylint: disable=invalid-name + + +def test_snapshot_creation(client, index_with_documents): + """Tests the creation of a Meilisearch snapshot.""" + index_with_documents("indexUID-snapshot-creation") + snapshot= client.create_snapshot() + client.wait_for_task(snapshot.task_uid) + snapshot_status = client.get_task(snapshot.task_uid) + assert snapshot_status.status == "succeeded" + assert snapshot_status.type == "snapshotCreation" \ No newline at end of file From 057e27a451c5cb74ea6c5df4de44ffe716922c4b Mon Sep 17 00:00:00 2001 From: Pavel Belokon <88114764+pbelokon@users.noreply.github.com> Date: Fri, 24 Nov 2023 01:13:22 +0000 Subject: [PATCH 5/5] ran black tests on meilisearch --- tests/client/test_clinet_snapshots.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/client/test_clinet_snapshots.py b/tests/client/test_clinet_snapshots.py index 8de73c7e..7822dfa6 100644 --- a/tests/client/test_clinet_snapshots.py +++ b/tests/client/test_clinet_snapshots.py @@ -4,8 +4,8 @@ def test_snapshot_creation(client, index_with_documents): """Tests the creation of a Meilisearch snapshot.""" index_with_documents("indexUID-snapshot-creation") - snapshot= client.create_snapshot() + snapshot = client.create_snapshot() client.wait_for_task(snapshot.task_uid) snapshot_status = client.get_task(snapshot.task_uid) assert snapshot_status.status == "succeeded" - assert snapshot_status.type == "snapshotCreation" \ No newline at end of file + assert snapshot_status.type == "snapshotCreation"