2121from synapse .api .constants import EventTypes , HistoryVisibility
2222from synapse .rest .client import login , room , sync
2323from synapse .server import HomeServer
24- from synapse .types import UserID
24+ from synapse .types import JsonDict , UserID
2525from synapse .util .clock import Clock
2626
2727from tests .rest .client .sliding_sync .test_sliding_sync import SlidingSyncBase
@@ -66,14 +66,39 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
6666 self .storage_controllers = hs .get_storage_controllers ()
6767
6868 super ().prepare (reactor , clock , hs )
69+ self .room_version = hs .config .server .default_room_version
70+
71+ def assertHasSubset (
72+ self ,
73+ container : list [JsonDict ],
74+ contains_these : list [JsonDict ],
75+ ) -> None :
76+ assert contains_these , "`contains_these` was empty"
77+ assert container , "`container` was empty"
78+
79+ for dict_to_search_for in contains_these :
80+ for container_entry in container :
81+ # The <= operator is a subset comparison operator when used on
82+ # 'set-like' containers
83+ if dict_to_search_for .items () <= container_entry .items ():
84+ # The searched for item was found, move on. Break will skip the
85+ # else statement below
86+ break
87+ else :
88+ # Searching the 'container' for this subset yielded nothing, that is
89+ # an error.
90+ raise AssertionError (
91+ "The searched for dict was not present in the container:\n \n "
92+ f"Searched for { dict_to_search_for } \n \n Container: { container } "
93+ )
6994
7095 def test_rooms_invite_shared_history_initial_sync (self ) -> None :
7196 """
7297 Test that `rooms` we are invited to have some stripped `invite_state` during an
7398 initial sync.
7499
75100 This is an `invite` room so we should only have `stripped_state` (no `timeline`)
76- but we also shouldn't see any timeline events because the history visiblity is
101+ but we also shouldn't see any timeline events because the history visibility is
77102 `shared` and we haven't joined the room yet.
78103 """
79104 user1_id = self .register_user ("user1" , "pass" )
@@ -85,7 +110,7 @@ def test_rooms_invite_shared_history_initial_sync(self) -> None:
85110
86111 room_id1 = self .helper .create_room_as (user2_id , tok = user2_tok )
87112 # Ensure we're testing with a room with `shared` history visibility which means
88- # history visible until you actually join the room.
113+ # history won't be visible until you actually join the room.
89114 history_visibility_response = self .helper .get_state (
90115 room_id1 , EventTypes .RoomHistoryVisibility , tok = user2_tok
91116 )
@@ -138,12 +163,15 @@ def test_rooms_invite_shared_history_initial_sync(self) -> None:
138163 response_body ["rooms" ][room_id1 ],
139164 )
140165 # We should have some `stripped_state` so the potential joiner can identify the
141- # room (we don't care about the order).
142- self .assertCountEqual (
166+ # room (we don't care about the order). The exception is the creation event
167+ # which is a full PDU format from room v12 and newer
168+ self .assertHasSubset (
143169 response_body ["rooms" ][room_id1 ]["invite_state" ],
144170 [
145171 {
146- "content" : {"creator" : user2_id , "room_version" : "10" },
172+ "content" : {
173+ "room_version" : self .room_version .identifier ,
174+ },
147175 "sender" : user2_id ,
148176 "state_key" : "" ,
149177 "type" : "m.room.create" ,
@@ -167,7 +195,6 @@ def test_rooms_invite_shared_history_initial_sync(self) -> None:
167195 "type" : "m.room.member" ,
168196 },
169197 ],
170- response_body ["rooms" ][room_id1 ]["invite_state" ],
171198 )
172199
173200 def test_rooms_invite_shared_history_incremental_sync (self ) -> None :
@@ -248,12 +275,15 @@ def test_rooms_invite_shared_history_incremental_sync(self) -> None:
248275 response_body ["rooms" ][room_id1 ],
249276 )
250277 # We should have some `stripped_state` so the potential joiner can identify the
251- # room (we don't care about the order).
252- self .assertCountEqual (
278+ # room (we don't care about the order). The exception is the creation event
279+ # which is a full PDU format from room v12 and newer
280+ self .assertHasSubset (
253281 response_body ["rooms" ][room_id1 ]["invite_state" ],
254282 [
255283 {
256- "content" : {"creator" : user2_id , "room_version" : "10" },
284+ "content" : {
285+ "room_version" : self .room_version .identifier ,
286+ },
257287 "sender" : user2_id ,
258288 "state_key" : "" ,
259289 "type" : "m.room.create" ,
@@ -277,7 +307,6 @@ def test_rooms_invite_shared_history_incremental_sync(self) -> None:
277307 "type" : "m.room.member" ,
278308 },
279309 ],
280- response_body ["rooms" ][room_id1 ]["invite_state" ],
281310 )
282311
283312 def test_rooms_invite_world_readable_history_initial_sync (self ) -> None :
@@ -369,12 +398,15 @@ def test_rooms_invite_world_readable_history_initial_sync(self) -> None:
369398 response_body ["rooms" ][room_id1 ],
370399 )
371400 # We should have some `stripped_state` so the potential joiner can identify the
372- # room (we don't care about the order).
373- self .assertCountEqual (
401+ # room (we don't care about the order). The exception is the creation event
402+ # which is a full PDU format from room v12 and newer
403+ self .assertHasSubset (
374404 response_body ["rooms" ][room_id1 ]["invite_state" ],
375405 [
376406 {
377- "content" : {"creator" : user2_id , "room_version" : "10" },
407+ "content" : {
408+ "room_version" : self .room_version .identifier ,
409+ },
378410 "sender" : user2_id ,
379411 "state_key" : "" ,
380412 "type" : "m.room.create" ,
@@ -398,7 +430,6 @@ def test_rooms_invite_world_readable_history_initial_sync(self) -> None:
398430 "type" : "m.room.member" ,
399431 },
400432 ],
401- response_body ["rooms" ][room_id1 ]["invite_state" ],
402433 )
403434
404435 def test_rooms_invite_world_readable_history_incremental_sync (self ) -> None :
@@ -495,12 +526,15 @@ def test_rooms_invite_world_readable_history_incremental_sync(self) -> None:
495526 response_body ["rooms" ][room_id1 ],
496527 )
497528 # We should have some `stripped_state` so the potential joiner can identify the
498- # room (we don't care about the order).
499- self .assertCountEqual (
529+ # room (we don't care about the order). The exception is the creation event
530+ # which is a full PDU format from room v12 and newer
531+ self .assertHasSubset (
500532 response_body ["rooms" ][room_id1 ]["invite_state" ],
501533 [
502534 {
503- "content" : {"creator" : user2_id , "room_version" : "10" },
535+ "content" : {
536+ "room_version" : self .room_version .identifier ,
537+ },
504538 "sender" : user2_id ,
505539 "state_key" : "" ,
506540 "type" : "m.room.create" ,
@@ -524,5 +558,4 @@ def test_rooms_invite_world_readable_history_incremental_sync(self) -> None:
524558 "type" : "m.room.member" ,
525559 },
526560 ],
527- response_body ["rooms" ][room_id1 ]["invite_state" ],
528561 )
0 commit comments