Skip to content

Commit a78a9cf

Browse files
add some tests
1 parent 9c3c65c commit a78a9cf

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed

stream/tests/test_async_client.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,93 @@ async def test_reaction_filter(async_client):
11471147
_first_result_should_be(r, reaction_comment)
11481148

11491149

1150+
@pytest.mark.asyncio
1151+
async def test_reaction_add_with_moderation_template(async_client):
1152+
"""Test adding a reaction with moderation template"""
1153+
try:
1154+
response = await async_client.reactions.add(
1155+
"like",
1156+
"54a60c1e-4ee3-494b-a1e3-50c06acb5ed4",
1157+
"mike",
1158+
moderation_template="test_moderation_template",
1159+
)
1160+
# If moderation is enabled, verify the reaction was created
1161+
assert "id" in response
1162+
reaction = await async_client.reactions.get(response["id"])
1163+
assert reaction["kind"] == "like"
1164+
assert reaction["user_id"] == "mike"
1165+
except Exception as e:
1166+
# If moderation is not enabled, we expect a specific error
1167+
# The important thing is that the moderation_template parameter
1168+
# was accepted and passed to the API without causing a client-side error
1169+
error_message = str(e)
1170+
assert (
1171+
"moderation not enabled" in error_message
1172+
), f"Expected moderation error, but got: {error_message}"
1173+
1174+
1175+
@pytest.mark.asyncio
1176+
async def test_reaction_add_child_with_moderation_template(async_client):
1177+
"""Test adding a child reaction with moderation template"""
1178+
# First create a parent reaction
1179+
parent_response = await async_client.reactions.add(
1180+
"like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike"
1181+
)
1182+
1183+
try:
1184+
# Add child with moderation template
1185+
child_response = await async_client.reactions.add_child(
1186+
"reply",
1187+
parent_response["id"],
1188+
"rob",
1189+
data={"text": "Great post!"},
1190+
moderation_template="child_moderation_template",
1191+
)
1192+
# If moderation is enabled, verify the child reaction was created
1193+
assert "id" in child_response
1194+
child_reaction = await async_client.reactions.get(child_response["id"])
1195+
assert child_reaction["kind"] == "reply"
1196+
assert child_reaction["user_id"] == "rob"
1197+
assert child_reaction["parent"] == parent_response["id"]
1198+
except Exception as e:
1199+
# If moderation is not enabled, we expect a specific error
1200+
# The important thing is that the moderation_template parameter
1201+
# was accepted and passed to the API without causing a client-side error
1202+
error_message = str(e)
1203+
assert (
1204+
"moderation not enabled" in error_message
1205+
), f"Expected moderation error, but got: {error_message}"
1206+
1207+
1208+
@pytest.mark.asyncio
1209+
async def test_reaction_add_without_moderation_template_backwards_compatibility(
1210+
async_client,
1211+
):
1212+
"""Test that existing functionality still works without moderation template"""
1213+
response = await async_client.reactions.add(
1214+
"like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike"
1215+
)
1216+
assert "id" in response
1217+
reaction = await async_client.reactions.get(response["id"])
1218+
assert reaction["kind"] == "like"
1219+
1220+
1221+
@pytest.mark.asyncio
1222+
async def test_reaction_add_child_without_moderation_template_backwards_compatibility(
1223+
async_client,
1224+
):
1225+
"""Test that existing child functionality still works without moderation template"""
1226+
parent_response = await async_client.reactions.add(
1227+
"like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike"
1228+
)
1229+
child_response = await async_client.reactions.add_child(
1230+
"reply", parent_response["id"], "rob"
1231+
)
1232+
assert "id" in child_response
1233+
child_reaction = await async_client.reactions.get(child_response["id"])
1234+
assert child_reaction["parent"] == parent_response["id"]
1235+
1236+
11501237
@pytest.mark.asyncio
11511238
async def test_user_add(async_client):
11521239
await async_client.users.add(str(uuid1()))

stream/tests/test_client.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,83 @@ def test_reaction_add_child(self):
14761476
)
14771477
self.c.reactions.add_child("like", response["id"], "rob")
14781478

1479+
def test_reaction_add_with_moderation_template(self):
1480+
"""Test adding a reaction with moderation template"""
1481+
try:
1482+
response = self.c.reactions.add(
1483+
"like",
1484+
"54a60c1e-4ee3-494b-a1e3-50c06acb5ed4",
1485+
"mike",
1486+
moderation_template="test_moderation_template",
1487+
)
1488+
# If moderation is enabled, verify the reaction was created
1489+
self.assertTrue("id" in response)
1490+
reaction = self.c.reactions.get(response["id"])
1491+
self.assertEqual(reaction["kind"], "like")
1492+
self.assertEqual(reaction["user_id"], "mike")
1493+
except Exception as e:
1494+
# If moderation is not enabled, we expect a specific error
1495+
# The important thing is that the moderation_template parameter
1496+
# was accepted and passed to the API without causing a client-side error
1497+
error_message = str(e)
1498+
self.assertTrue(
1499+
"moderation not enabled" in error_message,
1500+
f"Expected moderation error, but got: {error_message}",
1501+
)
1502+
1503+
def test_reaction_add_child_with_moderation_template(self):
1504+
"""Test adding a child reaction with moderation template"""
1505+
# First create a parent reaction
1506+
parent_response = self.c.reactions.add(
1507+
"like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike"
1508+
)
1509+
1510+
try:
1511+
# Add child with moderation template
1512+
child_response = self.c.reactions.add_child(
1513+
"reply",
1514+
parent_response["id"],
1515+
"rob",
1516+
data={"text": "Great post!"},
1517+
moderation_template="child_moderation_template",
1518+
)
1519+
# If moderation is enabled, verify the child reaction was created
1520+
self.assertTrue("id" in child_response)
1521+
child_reaction = self.c.reactions.get(child_response["id"])
1522+
self.assertEqual(child_reaction["kind"], "reply")
1523+
self.assertEqual(child_reaction["user_id"], "rob")
1524+
self.assertEqual(child_reaction["parent"], parent_response["id"])
1525+
except Exception as e:
1526+
# If moderation is not enabled, we expect a specific error
1527+
# The important thing is that the moderation_template parameter
1528+
# was accepted and passed to the API without causing a client-side error
1529+
error_message = str(e)
1530+
self.assertTrue(
1531+
"moderation not enabled" in error_message,
1532+
f"Expected moderation error, but got: {error_message}",
1533+
)
1534+
1535+
def test_reaction_add_without_moderation_template(self):
1536+
"""Test that existing functionality still works without moderation template"""
1537+
response = self.c.reactions.add(
1538+
"like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike"
1539+
)
1540+
self.assertTrue("id" in response)
1541+
reaction = self.c.reactions.get(response["id"])
1542+
self.assertEqual(reaction["kind"], "like")
1543+
1544+
def test_reaction_add_child_without_moderation_template(self):
1545+
"""Test that existing child functionality still works without moderation template"""
1546+
parent_response = self.c.reactions.add(
1547+
"like", "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4", "mike"
1548+
)
1549+
child_response = self.c.reactions.add_child(
1550+
"reply", parent_response["id"], "rob"
1551+
)
1552+
self.assertTrue("id" in child_response)
1553+
child_reaction = self.c.reactions.get(child_response["id"])
1554+
self.assertEqual(child_reaction["parent"], parent_response["id"])
1555+
14791556
def test_reaction_filter_random(self):
14801557
self.c.reactions.filter(
14811558
kind="like",

0 commit comments

Comments
 (0)