Skip to content

Commit d5b420c

Browse files
committed
Add support for filters query params in 'purge_history()'
1 parent ec835fd commit d5b420c

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ The history of a bucket can also be purged with:
421421

422422
.. code-block:: python
423423
424-
client.purge_history(bucket='default')
424+
client.purge_history(bucket='default', _before='"1743671651423"', user_id="account:fulanito")
425425
426426
427427
Attachments

src/kinto_http/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,11 +878,11 @@ def get_history(self, *, bucket=None, **kwargs) -> List[Dict]:
878878
return self._paginated(endpoint, **kwargs)
879879

880880
@retry_timeout
881-
def purge_history(self, *, bucket=None, safe=True, if_match=None) -> List[Dict]:
881+
def purge_history(self, *, bucket=None, safe=True, if_match=None, **kwargs) -> List[Dict]:
882882
endpoint = self._get_endpoint("history", bucket=bucket)
883883
headers = self._get_cache_headers(safe, if_match=if_match)
884884
logger.info("Purge History of bucket %r" % bucket or self.bucket_name)
885-
resp, _ = self.session.request("delete", endpoint, headers=headers)
885+
resp, _ = self.session.request("delete", endpoint, headers=headers, params=kwargs)
886886
return resp["data"]
887887

888888
@retry_timeout

tests/test_async_client.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,4 +1237,19 @@ async def test_purging_of_history(async_client_setup: Client):
12371237
mock_response(client.session)
12381238
await client.purge_history(bucket="mybucket")
12391239
url = "/buckets/mybucket/history"
1240-
client.session.request.assert_called_with("delete", url, headers=None)
1240+
client.session.request.assert_called_with("delete", url, headers=None, params={})
1241+
1242+
1243+
async def test_purging_of_history_with_params(async_client_setup: Client):
1244+
client = async_client_setup
1245+
mock_response(client.session)
1246+
await client.purge_history(
1247+
bucket="mybucket", user_id="plugin:remote-settings", _before='"1337"'
1248+
)
1249+
url = "/buckets/mybucket/history"
1250+
client.session.request.assert_called_with(
1251+
"delete",
1252+
url,
1253+
headers=None,
1254+
params={"user_id": "plugin:remote-settings", "_before": '"1337"'},
1255+
)

tests/test_client.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,20 @@ def test_purging_of_history(client_setup: Client):
13931393
mock_response(client.session)
13941394
client.purge_history(bucket="mybucket")
13951395
url = "/buckets/mybucket/history"
1396-
client.session.request.assert_called_with("delete", url, headers=None)
1396+
client.session.request.assert_called_with("delete", url, headers=None, params={})
1397+
1398+
1399+
def test_purging_of_history_with_params(client_setup: Client):
1400+
client = client_setup
1401+
mock_response(client.session)
1402+
client.purge_history(bucket="mybucket", user_id="plugin:remote-settings", _before='"1337"')
1403+
url = "/buckets/mybucket/history"
1404+
client.session.request.assert_called_with(
1405+
"delete",
1406+
url,
1407+
headers=None,
1408+
params={"user_id": "plugin:remote-settings", "_before": '"1337"'},
1409+
)
13971410

13981411

13991412
def test_download_attachment(client_setup: Client, mocker: MockerFixture):

0 commit comments

Comments
 (0)