Skip to content

Commit

Permalink
add tests for soft deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyPettersson85 committed Oct 23, 2023
1 parent 7574ee1 commit 15d69b6
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
40 changes: 39 additions & 1 deletion stream/tests/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
33 changes: 32 additions & 1 deletion stream/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 15d69b6

Please sign in to comment.