From 15d69b6d01f243eb9e53012f176cb1788430a1a6 Mon Sep 17 00:00:00 2001 From: Jimmy Pettersson Date: Mon, 23 Oct 2023 18:51:38 +0200 Subject: [PATCH] add tests for soft deletion --- stream/tests/test_async_client.py | 40 ++++++++++++++++++++++++++++++- stream/tests/test_client.py | 33 ++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/stream/tests/test_async_client.py b/stream/tests/test_async_client.py index bb1bc27..d4b0c0f 100644 --- a/stream/tests/test_async_client.py +++ b/stream/tests/test_async_client.py @@ -8,7 +8,7 @@ from dateutil.tz import tzlocal import stream -from stream.exceptions import ApiKeyException, InputException +from stream.exceptions import ApiKeyException, InputException, DoesNotExistException def assert_first_activity_id_equal(activities, correct_activity_id): @@ -1049,6 +1049,44 @@ async def test_reaction_delete(async_client): await async_client.reactions.delete(response["id"]) +@pytest.mark.asyncio +async def test_reaction_hard_delete(async_client): + response = await async_client.reactions.add( + "like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike" + ) + await async_client.reactions.delete(response["id"], soft=False) + + +@pytest.mark.asyncio +async def test_reaction_soft_delete(async_client): + response = await async_client.reactions.add( + "like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike" + ) + await async_client.reactions.delete(response["id"], soft=True) + + +@pytest.mark.asyncio +async def test_reaction_soft_delete_and_restore(async_client): + response = await async_client.reactions.add( + "like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike" + ) + await async_client.reactions.delete(response["id"], soft=True) + r1 = await async_client.reactions.get(response["id"]) + assert r1.get("deleted_at", None) is not None + await async_client.reactions.restore(response["id"]) + r1 = await async_client.reactions.get(response["id"]) + assert "deleted_at" not in r1 + + +@pytest.mark.asyncio +async def test_reaction_invalid_restore(async_client): + response = await async_client.reactions.add( + "like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike" + ) + with pytest.raises(DoesNotExistException): + await async_client.reactions.restore(response["id"]) + + @pytest.mark.asyncio async def test_reaction_add_child(async_client): response = await async_client.reactions.add( diff --git a/stream/tests/test_client.py b/stream/tests/test_client.py index aced337..442b726 100644 --- a/stream/tests/test_client.py +++ b/stream/tests/test_client.py @@ -17,7 +17,7 @@ import stream from stream import serializer -from stream.exceptions import ApiKeyException, InputException +from stream.exceptions import ApiKeyException, InputException, DoesNotExistException from stream.feed import Feed @@ -1439,6 +1439,37 @@ def test_reaction_delete(self): ) self.c.reactions.delete(response["id"]) + def test_reaction_hard_delete(self): + response = self.c.reactions.add( + "like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike" + ) + self.c.reactions.delete(response["id"], soft=False) + + def test_reaction_soft_delete(self): + response = self.c.reactions.add( + "like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike" + ) + self.c.reactions.delete(response["id"], soft=True) + + def test_reaction_soft_delete_and_restore(self): + response = self.c.reactions.add( + "like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike" + ) + self.c.reactions.delete(response["id"], soft=True) + r1 = self.c.reactions.get(response["id"]) + self.assertIsNot(r1["deleted_at"], None) + self.c.reactions.restore(response["id"]) + r1 = self.c.reactions.get(response["id"]) + self.assertTrue("deleted_at" not in r1) + + def test_reaction_invalid_restore(self): + response = self.c.reactions.add( + "like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike" + ) + self.assertRaises( + DoesNotExistException, lambda: self.c.reactions.restore(response["id"]) + ) + def test_reaction_add_child(self): response = self.c.reactions.add( "like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike"