@@ -134,6 +134,188 @@ def test_list(client, room, user, user2, admin, mod, global_mod, global_admin):
134
134
assert r .json == {** r3_expected , ** exp_gadmin }
135
135
136
136
137
+ def test_updates (client , room , user , user2 , mod , admin , global_mod , global_admin ):
138
+ url_room = '/room/test-room'
139
+ r = sogs_get (client , url_room , user )
140
+ assert r .status_code == 200
141
+ expect_room = {
142
+ "token" : "test-room" ,
143
+ "name" : "Test room" ,
144
+ "description" : "Test suite testing room" ,
145
+ "info_updates" : 2 ,
146
+ "message_sequence" : 0 ,
147
+ "created" : room .created ,
148
+ "active_users" : 0 ,
149
+ "active_users_cutoff" : int (86400 * sogs .config .ROOM_DEFAULT_ACTIVE_THRESHOLD ),
150
+ "moderators" : [mod .session_id ],
151
+ "admins" : [admin .session_id ],
152
+ "read" : True ,
153
+ "write" : True ,
154
+ "upload" : True ,
155
+ }
156
+ assert r .json == expect_room
157
+
158
+ for u in (user , user2 , mod , global_mod ):
159
+ r = sogs_put (client , url_room , {"name" : "OMG ROOM!" }, u )
160
+ assert r .status_code == 403
161
+
162
+ assert sogs_get (client , url_room , user ).json == expect_room
163
+
164
+ r = sogs_put (client , url_room , {"name" : "OMG ROOM!" }, admin )
165
+ assert r .status_code == 200
166
+ expect_room ['name' ] = "OMG ROOM!"
167
+ expect_room ['info_updates' ] += 1
168
+
169
+ assert sogs_get (client , url_room , user ).json == expect_room
170
+
171
+ r = sogs_put (
172
+ client , url_room , {"name" : "rrr" , "description" : "Tharr be pirrrates!" }, global_admin
173
+ )
174
+ assert r .status_code == 200
175
+ expect_room ['name' ] = 'rrr'
176
+ expect_room ['description' ] = 'Tharr be pirrrates!'
177
+ expect_room ['info_updates' ] += 2
178
+
179
+ assert sogs_get (client , url_room , user ).json == expect_room
180
+
181
+ r = sogs_put (client , url_room , {"default_write" : False }, admin )
182
+ assert r .status_code == 200
183
+ expect_room ['write' ] = False
184
+ expect_room ['upload' ] = False # upload requires default_upload *and* write
185
+ # expect_room['info_updates'] += 0 # permission updates don't increment info_updates
186
+
187
+ assert sogs_get (client , url_room , user ).json == expect_room
188
+
189
+ expect_mod = {
190
+ 'read' : True ,
191
+ 'write' : True ,
192
+ 'upload' : True ,
193
+ 'default_read' : True ,
194
+ 'default_write' : False ,
195
+ 'default_upload' : True ,
196
+ 'moderator' : True ,
197
+ 'moderators' : [mod .session_id ],
198
+ 'admins' : [admin .session_id ],
199
+ 'hidden_moderators' : [global_mod .session_id ],
200
+ 'hidden_admins' : [global_admin .session_id ],
201
+ }
202
+ assert sogs_get (client , url_room , mod ).json == {** expect_room , ** expect_mod }
203
+
204
+ r = sogs_put (client , url_room , {"default_upload" : False , "default_read" : True }, admin )
205
+ assert r .status_code == 200
206
+ expect_mod ['default_upload' ] = False
207
+
208
+ assert sogs_get (client , url_room , user ).json == expect_room
209
+ assert sogs_get (client , url_room , mod ).json == {** expect_room , ** expect_mod }
210
+
211
+ r = sogs_put (client , url_room , {"default_read" : False }, admin )
212
+ assert r .status_code == 200
213
+ expect_room ['read' ] = False
214
+ expect_mod ['default_read' ] = False
215
+
216
+ assert sogs_get (client , url_room , user ).json == expect_room
217
+ assert sogs_get (client , url_room , mod ).json == {** expect_room , ** expect_mod }
218
+
219
+ r = sogs_put (
220
+ client ,
221
+ url_room ,
222
+ {
223
+ "default_read" : True ,
224
+ "default_write" : True ,
225
+ "default_upload" : True ,
226
+ "name" : "Gudaye, mytes!" ,
227
+ "description" : (
228
+ "Room for learning to speak Australian\n \n "
229
+ "Throw a shrimpie on the barbie and crack a coldie from the bottle-o!"
230
+ ),
231
+ },
232
+ admin ,
233
+ )
234
+ assert r .status_code == 200
235
+ for x in ('read' , 'write' , 'upload' ):
236
+ expect_room [x ] = True
237
+ expect_room ['name' ] = "Gudaye, mytes!"
238
+ expect_room ['description' ] = (
239
+ "Room for learning to speak Australian\n \n "
240
+ "Throw a shrimpie on the barbie and crack a coldie from the bottle-o!"
241
+ )
242
+ expect_room ['info_updates' ] += 2
243
+ for x in ('read' , 'write' , 'upload' ):
244
+ expect_mod ['default_' + x ] = True
245
+
246
+ assert sogs_get (client , url_room , user ).json == expect_room
247
+ assert sogs_get (client , url_room , mod ).json == {** expect_room , ** expect_mod }
248
+
249
+ r = sogs_put (client , url_room , {"description" : None }, admin )
250
+ assert r .status_code == 200
251
+
252
+ del expect_room ['description' ]
253
+ expect_room ['info_updates' ] += 1
254
+
255
+ assert sogs_get (client , url_room , user ).json == expect_room
256
+ assert sogs_get (client , url_room , mod ).json == {** expect_room , ** expect_mod }
257
+
258
+ r = sogs_put (client , url_room , {"description" : "ddd" }, admin )
259
+ expect_room ['description' ] = 'ddd'
260
+ expect_room ['info_updates' ] += 1
261
+ assert sogs_get (client , url_room , user ).json == expect_room
262
+
263
+ # empty string description should be treated as null
264
+ r = sogs_put (client , url_room , {"description" : "" }, admin )
265
+ del expect_room ['description' ]
266
+ expect_room ['info_updates' ] += 1
267
+ assert sogs_get (client , url_room , user ).json == expect_room
268
+
269
+ # Name strips out all control chars (i.e. anything below \x20); description strips out all
270
+ # except newline (\x0a) and tab (\x09).
271
+ r = sogs_put (
272
+ client ,
273
+ url_room ,
274
+ {
275
+ "description" : f"a{ '' .join (chr (c ) for c in range (33 ))} z" ,
276
+ "name" : f"a{ '' .join (chr (c ) for c in range (33 ))} z" ,
277
+ },
278
+ admin ,
279
+ )
280
+ expect_room ['description' ] = 'a\x09 \x0a z'
281
+ expect_room ['name' ] = 'a z'
282
+ expect_room ['info_updates' ] += 2
283
+
284
+ assert sogs_get (client , url_room , user ).json == expect_room
285
+ assert sogs_get (client , url_room , mod ).json == {** expect_room , ** expect_mod }
286
+
287
+ # Test bad arguments properly err:
288
+ assert [
289
+ sogs_put (client , url_room , data , admin ).status_code
290
+ for data in (
291
+ {},
292
+ {'name' : 42 },
293
+ {'name' : None },
294
+ {'description' : 42 },
295
+ {'default_read' : "foo" },
296
+ {'default_write' : "bar" },
297
+ {'default_upload' : None },
298
+ )
299
+ ] == [400 ] * 7
300
+
301
+ assert sogs_get (client , url_room , user ).json == expect_room
302
+ assert sogs_get (client , url_room , mod ).json == {** expect_room , ** expect_mod }
303
+
304
+ # Last but not least let's fill up name and description with emoji!
305
+ emoname = "💰 🐈 🍌 🌋 ‽"
306
+ emodesc = (
307
+ "💾 🚌 🗑 📱 🆗 😴 👖 💲 🍹 📉 🍩 🛎 🚣 ⚫️ 🐕 🕒 🏕 🎩 🆕 🍭 💋 🐌 📡 🚫 "
308
+ "🕢 🚮 🎳 🚠 📦 😛 ♋️ 🌼 🏭 👼 🙆 👗 🏡 😞 🎠 ⭕️ 💚 💁 💸 🌟 ☀️ 🍀 🎶 🍿"
309
+ )
310
+ r = sogs_put (client , url_room , {"description" : emodesc , "name" : emoname }, admin )
311
+ expect_room ['description' ] = emodesc
312
+ expect_room ['name' ] = emoname
313
+ expect_room ['info_updates' ] += 2
314
+
315
+ assert sogs_get (client , url_room , user ).json == expect_room
316
+ assert sogs_get (client , url_room , mod ).json == {** expect_room , ** expect_mod }
317
+
318
+
137
319
def test_polling (client , room , user , user2 , mod , admin , global_mod , global_admin ):
138
320
r = sogs_get (client , "/room/test-room" , user )
139
321
assert r .status_code == 200
0 commit comments