diff options
author | adityacp | 2020-09-23 18:01:04 +0530 |
---|---|---|
committer | adityacp | 2020-09-23 18:01:04 +0530 |
commit | 7589f9838ac5080a5f2fb5f9c92522bc722ab80b (patch) | |
tree | 8f7739f823914a77bce0bfebeeb9e2a8af1a0c98 /yaksh | |
parent | 3130680c9a405cbaa77108a48d3923790920b2e3 (diff) | |
download | online_test-7589f9838ac5080a5f2fb5f9c92522bc722ab80b.tar.gz online_test-7589f9838ac5080a5f2fb5f9c92522bc722ab80b.tar.bz2 online_test-7589f9838ac5080a5f2fb5f9c92522bc722ab80b.zip |
Add more tests
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/models.py | 1 | ||||
-rw-r--r-- | yaksh/test_views.py | 253 | ||||
-rw-r--r-- | yaksh/views.py | 21 |
3 files changed, 264 insertions, 11 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index f46ddda..8db054d 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -2888,7 +2888,6 @@ class LessonQuizAnswer(models.Model): elif question.type == 'float': user_answer = float(user_answer) tc_status = [] - user_answer = float(user_answer) for tc in question.get_test_cases(): if abs(tc.correct - user_answer) <= tc.error_margin: tc_status.append(True) diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 255ff76..16f1a98 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -6602,6 +6602,54 @@ class TestLessons(TestCase): lesson=self.lesson).first() self.assertIn("test", lesson_files.file.name) lesson_file_path = lesson_files.file.path + + # Teacher adds multiple videos in video path + response = self.client.post( + reverse('yaksh:edit_lesson', + kwargs={"lesson_id": self.lesson.id, + "course_id": self.course.id, + "module_id": self.learning_module.id}), + data={"name": "updated lesson", + "description": "updated description", + "video_path": "{'youtube': 'test', 'others': 'test'}", + "Save": "Save"} + ) + self.assertEqual(response.status_code, 200) + self.assertIn( + "Video path : Only one of the video name should be entered", + str(response.content) + ) + + # Teacher adds wrong pattern in video path + response = self.client.post( + reverse('yaksh:edit_lesson', + kwargs={"lesson_id": self.lesson.id, + "course_id": self.course.id, + "module_id": self.learning_module.id}), + data={"name": "updated lesson", + "description": "updated description", + "video_path": "test", + "Save": "Save"} + ) + self.assertEqual(response.status_code, 200) + self.assertIn( + "Video path : Value must be dictionary as shown in sample", + str(response.content) + ) + + # Teacher adds correct path in video path + response = self.client.post( + reverse('yaksh:edit_lesson', + kwargs={"lesson_id": self.lesson.id, + "course_id": self.course.id, + "module_id": self.learning_module.id}), + data={"name": "updated lesson", + "description": "updated description", + "video_path": "{'others': 'test'}", + "Save": "Save"} + ) + self.assertEqual(response.status_code, 302) + # Teacher removes the lesson file response = self.client.post( reverse('yaksh:edit_lesson', @@ -8203,3 +8251,208 @@ class TestLessonContents(TestCase): next(iter(response_data.get("data").keys())).id, toc.id ) self.assertEqual(student_info.get("student_id"), self.student.id) + + def test_multiple_lesson_question_types(self): + self.client.login( + username=self.user1.username, + password=self.user1_plaintext_pass + ) + + # Create float based question + response = self.client.post( + reverse('yaksh:add_marker_quiz', + kwargs={"content_type": '3', + "course_id": self.user1_course1.id, + "lesson_id": self.lesson1.id}), + data={'timer': '00:00:00', 'summary': 'Float_Lesson', + 'description': 'My lesson question description', + 'language': 'other', 'type': 'float', 'topic': 'test', + 'points': '1', 'form-TOTAL_FORMS': 1, + 'form-MAX_NUM_FORMS': '', + 'form-INITIAL_FORMS': 0, + 'floattestcase_set-TOTAL_FORMS': 1, + 'floattestcase_set-INITIAL_FORMS': 0, + 'floattestcase_set-MIN_NUM_FORMS': 0, + 'floattestcase_set-MAX_NUM_FORMS': 0, + 'floattestcase_set-0-type': 'floattestcase', + 'floattestcase_set-0-correct': "1", + 'floattestcase_set-0-error_margin': "0.1" + } + ) + json_response = json.loads(response.content) + self.assertEqual(response.status_code, 200) + self.assertTrue(json_response.get("success")) + self.assertEqual( + json_response.get("message"), "Saved question successfully" + ) + + + # Create a mcq question + response = self.client.post( + reverse('yaksh:add_marker_quiz', + kwargs={"content_type": '3', + "course_id": self.user1_course1.id, + "lesson_id": self.lesson1.id}), + data={'timer': '00:00:00', 'summary': 'Mcq_Lesson', + 'description': 'My lesson question description', + 'language': 'other', 'type': 'mcq', 'topic': 'test', + 'points': '1', 'form-TOTAL_FORMS': 2, + 'form-MAX_NUM_FORMS': '', + 'form-INITIAL_FORMS': 0, + 'mcqtestcase_set-TOTAL_FORMS': 2, + 'mcqtestcase_set-INITIAL_FORMS': 0, + 'mcqtestcase_set-MIN_NUM_FORMS': 0, + 'mcqtestcase_set-MAX_NUM_FORMS': 0, + 'mcqtestcase_set-0-type': 'mcqtestcase', + 'mcqtestcase_set-0-options': "1", + 'mcqtestcase_set-0-correct': True, + 'mcqtestcase_set-1-type': 'mcqtestcase', + 'mcqtestcase_set-1-options': "2", + 'mcqtestcase_set-1-correct': False + } + ) + json_response = json.loads(response.content) + self.assertEqual(response.status_code, 200) + self.assertTrue(json_response.get("success")) + self.assertEqual( + json_response.get("message"), "Saved question successfully" + ) + + # Create a mcc question + response = self.client.post( + reverse('yaksh:add_marker_quiz', + kwargs={"content_type": '3', + "course_id": self.user1_course1.id, + "lesson_id": self.lesson1.id}), + data={'timer': '00:00:00', 'summary': 'Mcc_Lesson', + 'description': 'My lesson question description', + 'language': 'other', 'type': 'mcc', 'topic': 'test', + 'points': '1', 'form-TOTAL_FORMS': 2, + 'form-MAX_NUM_FORMS': '', + 'form-INITIAL_FORMS': 0, + 'mcqtestcase_set-TOTAL_FORMS': 2, + 'mcqtestcase_set-INITIAL_FORMS': 0, + 'mcqtestcase_set-MIN_NUM_FORMS': 0, + 'mcqtestcase_set-MAX_NUM_FORMS': 0, + 'mcqtestcase_set-0-type': 'mcqtestcase', + 'mcqtestcase_set-0-options': "1", + 'mcqtestcase_set-0-correct': True, + 'mcqtestcase_set-1-type': 'mcqtestcase', + 'mcqtestcase_set-1-options': "2", + 'mcqtestcase_set-1-correct': False + } + ) + json_response = json.loads(response.content) + self.assertEqual(response.status_code, 200) + self.assertTrue(json_response.get("success")) + self.assertEqual( + json_response.get("message"), "Saved question successfully" + ) + + + # Create a string based question + response = self.client.post( + reverse('yaksh:add_marker_quiz', + kwargs={"content_type": '3', + "course_id": self.user1_course1.id, + "lesson_id": self.lesson1.id}), + data={'timer': '00:00:00', 'summary': 'String_Lesson', + 'description': 'My lesson question description', + 'language': 'other', 'type': 'string', 'topic': 'test', + 'points': '1', 'form-TOTAL_FORMS': 1, + 'form-MAX_NUM_FORMS': '', + 'form-INITIAL_FORMS': 0, + 'stringtestcase_set-TOTAL_FORMS': 1, + 'stringtestcase_set-INITIAL_FORMS': 0, + 'stringtestcase_set-MIN_NUM_FORMS': 0, + 'stringtestcase_set-MAX_NUM_FORMS': 0, + 'stringtestcase_set-0-type': 'stringtestcase', + 'stringtestcase_set-0-correct': "test", + 'stringtestcase_set-0-string_check': "lower" + } + ) + json_response = json.loads(response.content) + self.assertEqual(response.status_code, 200) + self.assertTrue(json_response.get("success")) + self.assertEqual( + json_response.get("message"), "Saved question successfully" + ) + + ques = Question.objects.filter( + summary__in=["Mcq_Lesson", "Mcc_Lesson", + "Float_Lesson", "String_Lesson"] + ).values_list("id", flat=True) + self.assertTrue(ques.exists()) + tocs = TableOfContents.objects.filter( + course_id=self.user1_course1.id, lesson_id=self.lesson1.id, + object_id__in=ques + ).values_list("id", flat=True) + self.assertTrue(tocs.exists()) + + # Student submits answers to all the questions + self.user1_course1.students.add(self.student) + self.client.login( + username=self.student.username, + password=self.student_plaintext_pass + ) + + # submit mcq question + response = self.client.post( + reverse('yaksh:submit_marker_quiz', + kwargs={"course_id": self.user1_course1.id, + "toc_id": tocs[0]}), + data={'answer': '1'} + ) + json_response = json.loads(response.content) + self.assertEqual(response.status_code, 200) + self.assertTrue(json_response.get("success")) + self.assertEqual( + json_response.get("message"), "You answered the question correctly" + ) + + # submit mcc question + response = self.client.post( + reverse('yaksh:submit_marker_quiz', + kwargs={"course_id": self.user1_course1.id, + "toc_id": tocs[1]}), + data={'answer': ['1']} + ) + json_response = json.loads(response.content) + self.assertEqual(response.status_code, 200) + self.assertFalse(json_response.get("success")) + self.assertIn( + "You have answered the question incorrectly", + json_response.get("message"), + ) + + # submit float question + response = self.client.post( + reverse('yaksh:submit_marker_quiz', + kwargs={"course_id": self.user1_course1.id, + "toc_id": tocs[2]}), + data={'answer': '1.0'} + ) + json_response = json.loads(response.content) + self.assertEqual(response.status_code, 200) + self.assertFalse(json_response.get("success")) + self.assertIn( + "You have answered the question incorrectly", + json_response.get("message"), + ) + + + # submit string question + response = self.client.post( + reverse('yaksh:submit_marker_quiz', + kwargs={"course_id": self.user1_course1.id, + "toc_id": tocs[3]}), + data={'answer': 'test'} + ) + json_response = json.loads(response.content) + self.assertEqual(response.status_code, 200) + self.assertTrue(json_response.get("success")) + self.assertEqual( + json_response.get("message"), "You answered the question correctly" + ) + + diff --git a/yaksh/views.py b/yaksh/views.py index d909627..4c3b4a6 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -3710,9 +3710,10 @@ def add_marker_quiz(request, content_type, course_id, lesson_id, context['message'] = 'Saved question successfully' context['content_type'] = content_type else: - status_code = 400 + status_code = 200 context['success'] = False - context['message'] = "Error in saving form" + context['message'] = "Error in saving."\ + " Please check the question test cases" else: status_code = 400 context['success'] = False @@ -3880,14 +3881,14 @@ def submit_marker_quiz(request, course_id, toc_id): # call check answer only for graded quiz and exercise if toc.content == 3 or toc.content == 2: result = lesson_ans.check_answer(user_answer) - # if exercise then show custom message - if toc.content == 3: - if result.get("success"): - msg = "You answered the question correctly" - else: - success = False - msg = "You have answered the question incorrectly. "\ - "Please refer the lesson again" + # if exercise then show custom message + if toc.content == 3: + if result.get("success"): + msg = "You answered the question correctly" + else: + success = False + msg = "You have answered the question incorrectly. "\ + "Please refer the lesson again" else: msg = "You have already submitted the answer" else: |