@@ -188,6 +188,111 @@ def test_start_checking(
188
188
the_solution = Solution .get_by_id (solution .id )
189
189
assert the_solution .state == Solution .STATES .IN_CHECKING .name
190
190
191
+ @staticmethod
192
+ def test_user_comments (
193
+ exercise : Exercise ,
194
+ student_user : User ,
195
+ ):
196
+ solution = conftest .create_solution (exercise , student_user )
197
+
198
+ client = conftest .get_logged_user (student_user .username )
199
+ # Creating a comment
200
+ comment_response = client .post ('/comments' , data = json .dumps (dict (
201
+ fileId = solution .files [0 ].id , act = 'create' , kind = 'text' ,
202
+ comment = 'hey' , line = 1 ,
203
+ )), content_type = 'application/json' )
204
+ assert comment_response .status_code == 200
205
+
206
+ # Creating another comment
207
+ another_comment_response = client .post (
208
+ '/comments' , data = json .dumps (dict (
209
+ fileId = solution .files [0 ].id , act = 'create' , kind = 'text' ,
210
+ comment = 'noice' , line = 2 ,
211
+ )), content_type = 'application/json' ,
212
+ )
213
+ assert another_comment_response .status_code == 200
214
+
215
+ # Removing the second comment
216
+ json_response_another_comment = json .loads (
217
+ another_comment_response .get_data (as_text = True ),
218
+ )
219
+ delete_response = client .get ('/comments' , query_string = dict (
220
+ fileId = solution .files [0 ].id , act = 'delete' ,
221
+ commentId = json_response_another_comment ['id' ],
222
+ ), content_type = 'application/json' )
223
+ assert delete_response .status_code == 200
224
+
225
+ # Disabling users comments option
226
+ conftest .disable_users_comments ()
227
+
228
+ # Trying to remove a comment
229
+ json_response_comment = json .loads (
230
+ comment_response .get_data (as_text = True ),
231
+ )
232
+ delete_response = client .get ('/comments' , query_string = dict (
233
+ fileId = solution .files [0 ].id , act = 'delete' ,
234
+ commentId = json_response_comment ['id' ],
235
+ ), content_type = 'application/json' )
236
+ assert delete_response .status_code == 403
237
+
238
+ # Trying to create a comment
239
+ disable_comment_response = client .post (
240
+ '/comments' , data = json .dumps (dict (
241
+ fileId = solution .files [0 ].id , act = 'create' , kind = 'text' ,
242
+ comment = 'well well well' , line = 2 ,
243
+ )), content_type = 'application/json' ,
244
+ )
245
+ assert disable_comment_response .status_code == 403
246
+
247
+ @staticmethod
248
+ def test_staff_and_user_comments (
249
+ exercise : Exercise ,
250
+ student_user : User ,
251
+ staff_user : User ,
252
+ ):
253
+ solution = conftest .create_solution (exercise , student_user )
254
+
255
+ client = conftest .get_logged_user (staff_user .username )
256
+ # Enabling user comments option
257
+ conftest .enable_users_comments ()
258
+ # Creating a comment
259
+ comment_response = client .post ('/comments' , data = json .dumps (dict (
260
+ fileId = solution .files [0 ].id , act = 'create' , kind = 'text' ,
261
+ comment = 'try again' , line = 1 ,
262
+ )), content_type = 'application/json' )
263
+ assert comment_response .status_code == 200
264
+
265
+ # Creating another comment
266
+ another_comment_response = client .post (
267
+ '/comments' , data = json .dumps (dict (
268
+ fileId = solution .files [0 ].id , act = 'create' , kind = 'text' ,
269
+ comment = 'hey' , line = 1 ,
270
+ )), content_type = 'application/json' ,
271
+ )
272
+ assert another_comment_response .status_code == 200
273
+
274
+ # Removing the second comment
275
+ json_response_another_comment = json .loads (
276
+ another_comment_response .get_data (as_text = True ),
277
+ )
278
+ delete_response = client .get ('/comments' , query_string = dict (
279
+ fileId = solution .files [0 ].id , act = 'delete' ,
280
+ commentId = json_response_another_comment ['id' ],
281
+ ), content_type = 'application/json' )
282
+ assert delete_response .status_code == 200
283
+
284
+ conftest .logout_user (client )
285
+ client2 = conftest .get_logged_user (student_user .username )
286
+ # Trying to remove a comment
287
+ json_response_comment = json .loads (
288
+ comment_response .get_data (as_text = True ),
289
+ )
290
+ delete_response = client2 .get ('/comments' , query_string = dict (
291
+ fileId = solution .files [0 ].id , act = 'delete' ,
292
+ commentId = json_response_comment ['id' ],
293
+ ), content_type = 'application/json' )
294
+ assert delete_response .status_code == 403
295
+
191
296
@staticmethod
192
297
def test_share_solution_by_another_user (
193
298
exercise : Exercise ,
0 commit comments