@@ -263,3 +263,84 @@ def test_invalid_quiz_content_no_correct_answer(superadmin_client, create_course
263263 )
264264 assert response .status_code == 400
265265 assert "error" in response .json ()
266+
267+
268+ @pytest .mark .parametrize (
269+ "client" , ["superadmin" , "editor" , "viewer" ], indirect = ["client" ]
270+ )
271+ def test_list_course_content_access (client , create_course ):
272+ url = get_url ()
273+ response = client .get (url )
274+ assert response .status_code == 200
275+ data = response .json ()
276+ assert isinstance (data ["course_contents" ], list )
277+ assert len (data ["course_contents" ]) == 0
278+
279+
280+ def test_anonymous_user_cannot_list_course_content (anonymous_client , create_course ):
281+ url = get_url ()
282+ response = anonymous_client .get (url )
283+ assert response .status_code == 401
284+
285+
286+ def test_list_course_content_with_existing_contents (superadmin_client , create_course ):
287+ url = get_url ()
288+ # Create a lesson content
289+ lesson_payload = {
290+ "content" : {
291+ "title" : LESSON_TITLE ,
292+ "content" : LESSON_CONTENT ,
293+ "type" : "lesson" ,
294+ },
295+ "priority" : 1 ,
296+ "waiting_period" : {"period" : 2 , "type" : "days" },
297+ }
298+ superadmin_client .post (
299+ url , json .dumps (lesson_payload ), content_type = "application/json"
300+ )
301+
302+ # Create a quiz content
303+ quiz_payload = {
304+ "content" : {
305+ "type" : "quiz" ,
306+ "title" : "Quiz 1" ,
307+ "required_score" : 70 ,
308+ "questions" : [
309+ {
310+ "text" : "What is Python?" ,
311+ "priority" : 1 ,
312+ "answers" : [
313+ {"text" : "A programming language" , "is_correct" : True },
314+ {"text" : "A snake" , "is_correct" : False },
315+ ],
316+ }
317+ ],
318+ },
319+ "priority" : 2 ,
320+ "waiting_period" : {"period" : 1 , "type" : "hours" },
321+ }
322+ superadmin_client .post (
323+ url , json .dumps (quiz_payload ), content_type = "application/json"
324+ )
325+
326+ # Now list the course contents
327+ response = superadmin_client .get (url )
328+ assert response .status_code == 200
329+ data = response .json ()
330+ assert isinstance (data ["course_contents" ], list )
331+ assert len (data ["course_contents" ]) == 2
332+ assert data ["course_contents" ][0 ]["type" ] == "lesson"
333+ assert data ["course_contents" ][1 ]["type" ] == "quiz"
334+ assert data ["course_contents" ][0 ]["priority" ] == 1
335+ assert data ["course_contents" ][1 ]["priority" ] == 2
336+ assert data ["course_contents" ][0 ]["id" ] is not None
337+ assert data ["course_contents" ][1 ]["id" ] is not None
338+ assert data ["course_contents" ][0 ]["title" ] == LESSON_TITLE
339+ assert data ["course_contents" ][1 ]["title" ] == "Quiz 1"
340+ assert data ["course_contents" ][0 ]["waiting_period" ] == {"period" : 2 , "type" : "days" }
341+ assert data ["course_contents" ][1 ]["waiting_period" ] == {
342+ "period" : 1 ,
343+ "type" : "hours" ,
344+ }
345+ assert "lesson" not in data ["course_contents" ][0 ]
346+ assert "quiz" not in data ["course_contents" ][1 ]
0 commit comments