Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +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:
Expand Down
38 changes: 0 additions & 38 deletions pydoof/search_api/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[tool.ruff]
line-length = 119
indent-width = 4
target-version = "py38"

[tool.ruff.lint]
extend-select = [
Expand All @@ -9,3 +10,7 @@ extend-select = [
"E", # pyflakes
"TRY",
]

[tool.ruff.lint.pyupgrade]
# Keep compatibility with Python 3.8
keep-runtime-typing = true
30 changes: 1 addition & 29 deletions tests/search_api/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
)
)