Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 9e13c17

Browse files
committed
Add tests.
1 parent 1c408c3 commit 9e13c17

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

tests/rest/client/test_relations.py

+120
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from tests.server import FakeChannel
3131
from tests.test_utils import make_awaitable
3232
from tests.test_utils.event_injection import inject_event
33+
from tests.unittest import override_config
3334

3435

3536
class BaseRelationsTestCase(unittest.HomeserverTestCase):
@@ -949,6 +950,125 @@ def test_pagination_from_sync_and_messages(self) -> None:
949950
)
950951

951952

953+
class RecursiveRelationTestCase(BaseRelationsTestCase):
954+
@override_config({"experimental_features": {"msc3981_recurse_relations": True}})
955+
def test_recursive_relations(self) -> None:
956+
"""Generate a complex, multi-level relationship tree and query it."""
957+
# Create a thread with a few messages in it.
958+
channel = self._send_relation(RelationTypes.THREAD, "m.room.test")
959+
thread_1 = channel.json_body["event_id"]
960+
961+
channel = self._send_relation(RelationTypes.THREAD, "m.room.test")
962+
thread_2 = channel.json_body["event_id"]
963+
964+
# Add annotations.
965+
channel = self._send_relation(
966+
RelationTypes.ANNOTATION, "m.reaction", "a", parent_id=thread_2
967+
)
968+
annotation_1 = channel.json_body["event_id"]
969+
970+
channel = self._send_relation(
971+
RelationTypes.ANNOTATION, "m.reaction", "b", parent_id=thread_1
972+
)
973+
annotation_2 = channel.json_body["event_id"]
974+
975+
# Add a reference to part of the thread, then edit the reference and annotate it.
976+
channel = self._send_relation(
977+
RelationTypes.REFERENCE, "m.room.test", parent_id=thread_2
978+
)
979+
reference_1 = channel.json_body["event_id"]
980+
981+
channel = self._send_relation(
982+
RelationTypes.ANNOTATION, "m.reaction", "c", parent_id=reference_1
983+
)
984+
annotation_3 = channel.json_body["event_id"]
985+
986+
channel = self._send_relation(
987+
RelationTypes.REPLACE,
988+
"m.room.test",
989+
parent_id=reference_1,
990+
)
991+
edit = channel.json_body["event_id"]
992+
993+
# Also more events off the root.
994+
channel = self._send_relation(RelationTypes.ANNOTATION, "m.reaction", "d")
995+
annotation_4 = channel.json_body["event_id"]
996+
997+
channel = self.make_request(
998+
"GET",
999+
f"/_matrix/client/v1/rooms/{self.room}/relations/{self.parent_id}"
1000+
"?dir=f&limit=20&org.matrix.msc3981.recurse=true",
1001+
access_token=self.user_token,
1002+
)
1003+
self.assertEqual(200, channel.code, channel.json_body)
1004+
1005+
# The above events should be returned in creation order.
1006+
event_ids = [ev["event_id"] for ev in channel.json_body["chunk"]]
1007+
self.assertEqual(
1008+
event_ids,
1009+
[
1010+
thread_1,
1011+
thread_2,
1012+
annotation_1,
1013+
annotation_2,
1014+
reference_1,
1015+
annotation_3,
1016+
edit,
1017+
annotation_4,
1018+
],
1019+
)
1020+
1021+
@override_config({"experimental_features": {"msc3981_recurse_relations": True}})
1022+
def test_recursive_relations_with_filter(self) -> None:
1023+
"""The event_type and rel_type still apply."""
1024+
# Create a thread with a few messages in it.
1025+
channel = self._send_relation(RelationTypes.THREAD, "m.room.test")
1026+
thread_1 = channel.json_body["event_id"]
1027+
1028+
# Add annotations.
1029+
channel = self._send_relation(
1030+
RelationTypes.ANNOTATION, "m.reaction", "b", parent_id=thread_1
1031+
)
1032+
annotation_1 = channel.json_body["event_id"]
1033+
1034+
# Add a reference to part of the thread, then edit the reference and annotate it.
1035+
channel = self._send_relation(
1036+
RelationTypes.REFERENCE, "m.room.test", parent_id=thread_1
1037+
)
1038+
reference_1 = channel.json_body["event_id"]
1039+
1040+
channel = self._send_relation(
1041+
RelationTypes.ANNOTATION, "org.matrix.reaction", "c", parent_id=reference_1
1042+
)
1043+
annotation_2 = channel.json_body["event_id"]
1044+
1045+
# Fetch only annotations, but recursively.
1046+
channel = self.make_request(
1047+
"GET",
1048+
f"/_matrix/client/v1/rooms/{self.room}/relations/{self.parent_id}/{RelationTypes.ANNOTATION}"
1049+
"?dir=f&limit=20&org.matrix.msc3981.recurse=true",
1050+
access_token=self.user_token,
1051+
)
1052+
self.assertEqual(200, channel.code, channel.json_body)
1053+
1054+
# The above events should be returned in creation order.
1055+
event_ids = [ev["event_id"] for ev in channel.json_body["chunk"]]
1056+
self.assertEqual(event_ids, [annotation_1, annotation_2])
1057+
1058+
# Fetch only m.reactions, but recursively.
1059+
channel = self.make_request(
1060+
"GET",
1061+
f"/_matrix/client/v1/rooms/{self.room}/relations/{self.parent_id}/{RelationTypes.ANNOTATION}/m.reaction"
1062+
"?dir=f&limit=20&org.matrix.msc3981.recurse=true",
1063+
access_token=self.user_token,
1064+
)
1065+
self.assertEqual(200, channel.code, channel.json_body)
1066+
1067+
# The above events should be returned in creation order.
1068+
event_ids = [ev["event_id"] for ev in channel.json_body["chunk"]]
1069+
self.assertEqual(event_ids, [annotation_1])
1070+
1071+
9521072
class BundledAggregationsTestCase(BaseRelationsTestCase):
9531073
"""
9541074
See RelationsTestCase.test_edit for a similar test for edits.

0 commit comments

Comments
 (0)