@@ -54,61 +54,62 @@ def test_shared_room_list_public(self):
5454 A room should show up in the shared list of rooms between two users
5555 if it is public.
5656 """
57- u1 = self .register_user ("user1" , "pass" )
58- u1_token = self .login (u1 , "pass" )
59- u2 = self .register_user ("user2" , "pass" )
60- u2_token = self .login (u2 , "pass" )
61-
62- room = self .helper .create_room_as (u1 , is_public = True , tok = u1_token )
63- self .helper .invite (room , src = u1 , targ = u2 , tok = u1_token )
64- self .helper .join (room , user = u2 , tok = u2_token )
65-
66- channel = self ._get_shared_rooms (u1_token , u2 )
67- self .assertEquals (200 , channel .code , channel .result )
68- self .assertEquals (len (channel .json_body ["joined" ]), 1 )
69- self .assertEquals (channel .json_body ["joined" ][0 ], room )
57+ self ._check_shared_rooms_with (room_one_is_public = True , room_two_is_public = True )
7058
7159 def test_shared_room_list_private (self ):
7260 """
7361 A room should show up in the shared list of rooms between two users
7462 if it is private.
7563 """
76- u1 = self .register_user ("user1" , "pass" )
77- u1_token = self .login (u1 , "pass" )
78- u2 = self .register_user ("user2" , "pass" )
79- u2_token = self .login (u2 , "pass" )
80-
81- room = self .helper .create_room_as (u1 , is_public = False , tok = u1_token )
82- self .helper .invite (room , src = u1 , targ = u2 , tok = u1_token )
83- self .helper .join (room , user = u2 , tok = u2_token )
84-
85- channel = self ._get_shared_rooms (u1_token , u2 )
86- self .assertEquals (200 , channel .code , channel .result )
87- self .assertEquals (len (channel .json_body ["joined" ]), 1 )
88- self .assertEquals (channel .json_body ["joined" ][0 ], room )
64+ self ._check_shared_rooms_with (
65+ room_one_is_public = False , room_two_is_public = False
66+ )
8967
9068 def test_shared_room_list_mixed (self ):
9169 """
9270 The shared room list between two users should contain both public and private
9371 rooms.
9472 """
73+ self ._check_shared_rooms_with (room_one_is_public = True , room_two_is_public = False )
74+
75+ def _check_shared_rooms_with (
76+ self , room_one_is_public : bool , room_two_is_public : bool
77+ ):
78+ """Checks that shared public or private rooms between two users appear in
79+ their shared room lists
80+ """
9581 u1 = self .register_user ("user1" , "pass" )
9682 u1_token = self .login (u1 , "pass" )
9783 u2 = self .register_user ("user2" , "pass" )
9884 u2_token = self .login (u2 , "pass" )
9985
100- room_public = self . helper . create_room_as ( u1 , is_public = True , tok = u1_token )
101- room_private = self .helper .create_room_as (u2 , is_public = False , tok = u2_token )
102- self . helper . invite ( room_public , src = u1 , targ = u2 , tok = u1_token )
103- self . helper . invite ( room_private , src = u2 , targ = u1 , tok = u2_token )
104- self .helper .join ( room_public , user = u2 , tok = u2_token )
105- self .helper .join (room_private , user = u1 , tok = u1_token )
86+ # Create a room. user1 invites user2, who joins
87+ room_id_one = self .helper .create_room_as (
88+ u1 , is_public = room_one_is_public , tok = u1_token
89+ )
90+ self .helper .invite ( room_id_one , src = u1 , targ = u2 , tok = u1_token )
91+ self .helper .join (room_id_one , user = u2 , tok = u2_token )
10692
93+ # Check shared rooms from user1's perspective.
94+ # We should see the one room in common
95+ channel = self ._get_shared_rooms (u1_token , u2 )
96+ self .assertEquals (200 , channel .code , channel .result )
97+ self .assertEquals (len (channel .json_body ["joined" ]), 1 )
98+ self .assertEquals (channel .json_body ["joined" ][0 ], room_id_one )
99+
100+ # Create another room and invite user2 to it
101+ room_id_two = self .helper .create_room_as (
102+ u1 , is_public = room_two_is_public , tok = u1_token
103+ )
104+ self .helper .invite (room_id_two , src = u1 , targ = u2 , tok = u1_token )
105+ self .helper .join (room_id_two , user = u2 , tok = u2_token )
106+
107+ # Check shared rooms again. We should now see both rooms.
107108 channel = self ._get_shared_rooms (u1_token , u2 )
108109 self .assertEquals (200 , channel .code , channel .result )
109110 self .assertEquals (len (channel .json_body ["joined" ]), 2 )
110- self . assertTrue ( room_public in channel .json_body ["joined" ])
111- self .assertTrue ( room_private in channel . json_body [ "joined" ])
111+ for room_id_id in channel .json_body ["joined" ]:
112+ self .assertIn ( room_id_id , [ room_id_one , room_id_two ])
112113
113114 def test_shared_room_list_after_leave (self ):
114115 """
@@ -132,6 +133,12 @@ def test_shared_room_list_after_leave(self):
132133
133134 self .helper .leave (room , user = u1 , tok = u1_token )
134135
136+ # Check user1's view of shared rooms with user2
137+ channel = self ._get_shared_rooms (u1_token , u2 )
138+ self .assertEquals (200 , channel .code , channel .result )
139+ self .assertEquals (len (channel .json_body ["joined" ]), 0 )
140+
141+ # Check user2's view of shared rooms with user1
135142 channel = self ._get_shared_rooms (u2_token , u1 )
136143 self .assertEquals (200 , channel .code , channel .result )
137144 self .assertEquals (len (channel .json_body ["joined" ]), 0 )
0 commit comments