From 1240b32736e7d0b3bba418d141b90fdcbf8cecfd Mon Sep 17 00:00:00 2001 From: Manuel Irazabal Date: Thu, 2 Oct 2025 16:23:38 +0200 Subject: [PATCH 01/10] Remove cart v1 --- pydoof/search_api/stats.py | 38 ---------------------------------- tests/search_api/test_stats.py | 30 +-------------------------- 2 files changed, 1 insertion(+), 67 deletions(-) diff --git a/pydoof/search_api/stats.py b/pydoof/search_api/stats.py index b897d32..0a4e811 100644 --- a/pydoof/search_api/stats.py +++ b/pydoof/search_api/stats.py @@ -143,41 +143,3 @@ def add_to_cart( api_client = client or SearchAPIClient(**opts) return api_client.put(f"/6/{hashid}/stats/cart/{session_id}", query_params=query_params) - - -def remove_from_cart( - hashid: str, - index_name: str, - session_id: str, - item_id: str, - amount: int, - client=None, - **opts, -): - """ - Removes amount from the given item in the cart, and deletes if the result - is lower than 0. - - Args: - hashid: Unique search engine id. Indicates to which search engine we are doing the query. - session_id (<= 32 characters): The current session ID, must be unique for each user. - index_name: The index used for this product in Doofinder. - item_id: The ID of the item to be added (this refers to the ID in the shop database). - amount: Amount of items to add to the cart. - """ - query_params = {"index": index_name, "id": item_id, "amount": amount} - - api_client = client or SearchAPIClient(**opts) - return api_client.patch(f"/6/{hashid}/stats/cart/{session_id}", query_params=query_params) - - -def clear_cart(hashid: str, session_id: str, client=None, **opts): - """ - Deletes the cart with all its content. - - Args: - hashid: Unique search engine id. Indicates to which search engine we are doing the query. - session_id (<= 32 characters): The current session ID, must be unique for each user. - """ - api_client = client or SearchAPIClient(**opts) - return api_client.delete(f"/6/{hashid}/stats/cart/{session_id}") diff --git a/tests/search_api/test_stats.py b/tests/search_api/test_stats.py index 9853a10..655c7ce 100644 --- a/tests/search_api/test_stats.py +++ b/tests/search_api/test_stats.py @@ -151,32 +151,4 @@ def test_add_to_cart(self, APIClientMock): query_params={ 'index': index_name, 'id': item_id, 'amount': amount, 'title': title, 'price': price} - ) - - @mock.patch('pydoof.search_api.stats.SearchAPIClient') - def test_remove_from_cart(self, APIClientMock): - hashid = 'aab32d8' - index_name = 'product' - session_id = '4affa6' - amount = 2 - item_id = 1235 - - stats.remove_from_cart( - hashid, index_name, session_id, item_id, amount - ) - - APIClientMock.return_value.patch.assert_called_once_with( - f'/6/{hashid}/stats/cart/{session_id}', - query_params={'index': index_name, 'id': item_id, 'amount': amount} - ) - - @mock.patch('pydoof.search_api.stats.SearchAPIClient') - def test_clear_cart(self, APIClientMock): - hashid = 'aab32d8' - session_id = '4affa6' - - stats.clear_cart(hashid, session_id) - - APIClientMock.return_value.delete.assert_called_once_with( - f'/6/{hashid}/stats/cart/{session_id}' - ) + ) \ No newline at end of file From f2375a9c42b8acc897e68f17c7a083cc1e8a53a3 Mon Sep 17 00:00:00 2001 From: Manuel Irazabal Date: Thu, 2 Oct 2025 17:43:36 +0200 Subject: [PATCH 02/10] Remove cart v1 --- pydoof/helpers.py | 5 +++-- pydoof/search_api/search.py | 18 +++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pydoof/helpers.py b/pydoof/helpers.py index 624b700..4f25ba9 100644 --- a/pydoof/helpers.py +++ b/pydoof/helpers.py @@ -1,9 +1,10 @@ """ Collection of functions to assist PyDoof modules. """ +from collections.abc import Iterable from datetime import date from enum import Enum -from typing import Any, Iterable, List +from typing import Any def parse_query_params(params): @@ -28,7 +29,7 @@ def parse_query_params(params): return query_params -def _has_dicts(values: List[Any]): +def _has_dicts(values: list[Any]): # Could be possible to check only the first element. # Is used on facets and sort, for example. return any(isinstance(value, dict) for value in values) diff --git a/pydoof/search_api/search.py b/pydoof/search_api/search.py index 9c58392..222cf56 100644 --- a/pydoof/search_api/search.py +++ b/pydoof/search_api/search.py @@ -1,5 +1,5 @@ from enum import Enum, unique -from typing import Any, Dict, List, Optional +from typing import Any, Optional from pydoof.helpers import parse_query_params from pydoof.search_api.api_client import SearchAPIClient @@ -24,19 +24,19 @@ def query( auto_filters: Optional[bool] = None, custom_results: Optional[bool] = None, excluded_results: Optional[bool] = None, - filter: Dict[str, Any] = {}, - exclude: Dict[str, Any] = {}, - indices: List[str] = [], + filter: dict[str, Any] = {}, + exclude: dict[str, Any] = {}, + indices: list[str] = [], query_name: Optional[QueryNames] = None, - sort: List[Dict[str, str]] = [], + sort: list[dict[str, str]] = [], page: Optional[int] = None, rpp: Optional[int] = None, - facets: List[Dict[str, Any]] = [], + facets: list[dict[str, Any]] = [], filter_execution: Optional[SearchFilterExecution] = None, session_id: Optional[str] = None, stats: Optional[bool] = None, - skip_auto_filters: List[str] = [], - skip_top_facet: List[str] = [], + skip_auto_filters: list[str] = [], + skip_top_facet: list[str] = [], title_facet: Optional[bool] = None, top_facet: Optional[bool] = None, client:Optional[SearchAPIClient]=None, @@ -123,7 +123,7 @@ def query( def suggest( hashid: str, query: str = "", - indices: List[str] = [], + indices: list[str] = [], stats: Optional[bool] = None, session_id: Optional[str] = None, client: Optional[SearchAPIClient] = None, From 70a544314a0ce1e673f86e2d9f06458d004913d8 Mon Sep 17 00:00:00 2001 From: Manuel Irazabal Date: Thu, 2 Oct 2025 17:46:30 +0200 Subject: [PATCH 03/10] Remove cart v1 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a96c54e..17af8b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: build: strategy: matrix: - python-version: [3.7, 3.8, 3.9, "3.10", 3.11] + python-version: [3.8, 3.9, "3.10", 3.11, 3.12] runs-on: ubuntu-latest From 550bec35f1ff78d6ff2d9b2b442fcd3d2684e028 Mon Sep 17 00:00:00 2001 From: Manuel Irazabal Date: Thu, 2 Oct 2025 17:47:25 +0200 Subject: [PATCH 04/10] Remove cart v1 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17af8b8..fcb602a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: build: strategy: matrix: - python-version: [3.8, 3.9, "3.10", 3.11, 3.12] + python-version: [3.8, 3.9] runs-on: ubuntu-latest From 5671cdf482c0c205540d704eb198aaa9558c6dfe Mon Sep 17 00:00:00 2001 From: Manuel Irazabal Date: Thu, 2 Oct 2025 17:55:18 +0200 Subject: [PATCH 05/10] Remove cart v1 --- pydoof/helpers.py | 5 ++--- pydoof/search_api/search.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pydoof/helpers.py b/pydoof/helpers.py index 4f25ba9..624b700 100644 --- a/pydoof/helpers.py +++ b/pydoof/helpers.py @@ -1,10 +1,9 @@ """ Collection of functions to assist PyDoof modules. """ -from collections.abc import Iterable from datetime import date from enum import Enum -from typing import Any +from typing import Any, Iterable, List def parse_query_params(params): @@ -29,7 +28,7 @@ def parse_query_params(params): return query_params -def _has_dicts(values: list[Any]): +def _has_dicts(values: List[Any]): # Could be possible to check only the first element. # Is used on facets and sort, for example. return any(isinstance(value, dict) for value in values) diff --git a/pydoof/search_api/search.py b/pydoof/search_api/search.py index 222cf56..9c58392 100644 --- a/pydoof/search_api/search.py +++ b/pydoof/search_api/search.py @@ -1,5 +1,5 @@ from enum import Enum, unique -from typing import Any, Optional +from typing import Any, Dict, List, Optional from pydoof.helpers import parse_query_params from pydoof.search_api.api_client import SearchAPIClient @@ -24,19 +24,19 @@ def query( auto_filters: Optional[bool] = None, custom_results: Optional[bool] = None, excluded_results: Optional[bool] = None, - filter: dict[str, Any] = {}, - exclude: dict[str, Any] = {}, - indices: list[str] = [], + filter: Dict[str, Any] = {}, + exclude: Dict[str, Any] = {}, + indices: List[str] = [], query_name: Optional[QueryNames] = None, - sort: list[dict[str, str]] = [], + sort: List[Dict[str, str]] = [], page: Optional[int] = None, rpp: Optional[int] = None, - facets: list[dict[str, Any]] = [], + facets: List[Dict[str, Any]] = [], filter_execution: Optional[SearchFilterExecution] = None, session_id: Optional[str] = None, stats: Optional[bool] = None, - skip_auto_filters: list[str] = [], - skip_top_facet: list[str] = [], + skip_auto_filters: List[str] = [], + skip_top_facet: List[str] = [], title_facet: Optional[bool] = None, top_facet: Optional[bool] = None, client:Optional[SearchAPIClient]=None, @@ -123,7 +123,7 @@ def query( def suggest( hashid: str, query: str = "", - indices: list[str] = [], + indices: List[str] = [], stats: Optional[bool] = None, session_id: Optional[str] = None, client: Optional[SearchAPIClient] = None, From d8e3a3d146521e9aef97ed31f0b8a8e42da71b7c Mon Sep 17 00:00:00 2001 From: Manuel Irazabal Date: Thu, 2 Oct 2025 17:59:04 +0200 Subject: [PATCH 06/10] Remove cart v1 --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 137d3b2..b259fbd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,7 @@ [tool.ruff] line-length = 119 indent-width = 4 +target-version = "py38" [tool.ruff.lint] extend-select = [ @@ -9,3 +10,7 @@ extend-select = [ "E", # pyflakes "TRY", ] + +[tool.ruff.lint.pyupgrade] +# Keep compatibility with Python 3.8 +keep-runtime-typing = true From c4ff4fd78d88e7e5cda8e6befe64fd1b2cbcab16 Mon Sep 17 00:00:00 2001 From: Manuel Irazabal Date: Thu, 2 Oct 2025 18:00:31 +0200 Subject: [PATCH 07/10] Remove cart v1 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fcb602a..6406358 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: build: strategy: matrix: - python-version: [3.8, 3.9] + python-version: [3.7, 3.8, 3.9, 3.10, 3.11, 3.12] runs-on: ubuntu-latest From ea02d001701b0e2b5e8f9ea3fa7295b59a8ffdf5 Mon Sep 17 00:00:00 2001 From: Manuel Irazabal Date: Thu, 2 Oct 2025 18:01:26 +0200 Subject: [PATCH 08/10] Remove cart v1 --- .github/workflows/ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6406358..d0b6da1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,8 +7,7 @@ jobs: build: strategy: matrix: - python-version: [3.7, 3.8, 3.9, 3.10, 3.11, 3.12] - + python-version: [3.7, 3.8, 3.9, "3.10", 3.11] runs-on: ubuntu-latest steps: From f693648445f6a475e460d245c09291f9c55d08af Mon Sep 17 00:00:00 2001 From: Manuel Irazabal Date: Thu, 2 Oct 2025 18:02:23 +0200 Subject: [PATCH 09/10] Remove cart v1 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0b6da1..5acbc5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: build: strategy: matrix: - python-version: [3.7, 3.8, 3.9, "3.10", 3.11] + python-version: [3.8, 3.9, 3.10, 3.11] runs-on: ubuntu-latest steps: From 9881764de81b13865e3abfea7c62a56537d458bc Mon Sep 17 00:00:00 2001 From: Manuel Irazabal Date: Thu, 2 Oct 2025 18:03:21 +0200 Subject: [PATCH 10/10] Remove cart v1 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5acbc5b..177a20e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: build: strategy: matrix: - python-version: [3.8, 3.9, 3.10, 3.11] + python-version: [3.8, 3.9, "3.10", 3.11] runs-on: ubuntu-latest steps: