diff options
Diffstat (limited to 'yaksh/test_views.py')
-rw-r--r-- | yaksh/test_views.py | 95 |
1 files changed, 87 insertions, 8 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 274bcda..714fc67 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -420,10 +420,14 @@ class TestStudentDashboard(TestCase): response = self.client.get(reverse('yaksh:quizlist_user'), follow=True ) + courses_in_context = { + 'data': self.course, + 'completion_percentage': None, + } self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "yaksh/quizzes_user.html") self.assertEqual(response.context['title'], 'All Courses') - self.assertEqual(response.context['courses'][0], self.course) + self.assertEqual(response.context['courses'][0], courses_in_context) def test_student_dashboard_enrolled_courses_get(self): """ @@ -439,10 +443,14 @@ class TestStudentDashboard(TestCase): kwargs={'enrolled': "enrolled"}), follow=True ) + courses_in_context = { + 'data': self.course, + 'completion_percentage': 0, + } self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "yaksh/quizzes_user.html") self.assertEqual(response.context['title'], 'Enrolled Courses') - self.assertEqual(response.context['courses'][0], self.course) + self.assertEqual(response.context['courses'][0], courses_in_context) def test_student_dashboard_hidden_courses_post(self): """ @@ -456,10 +464,14 @@ class TestStudentDashboard(TestCase): response = self.client.post(reverse('yaksh:quizlist_user'), data={'course_code': 'hide'} ) + courses_in_context = { + 'data': self.hidden_course, + 'completion_percentage': None, + } self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "yaksh/quizzes_user.html") self.assertEqual(response.context['title'], 'Search') - self.assertEqual(response.context['courses'][0], self.hidden_course) + self.assertEqual(response.context['courses'][0], courses_in_context) class TestMonitor(TestCase): @@ -1925,7 +1937,7 @@ class TestCourses(TestCase): # Create a learning module to add to course self.learning_module = LearningModule.objects.create( order=0, name="test module", description="module", - check_prerequisite=False, creator=self.teacher) + check_prerequisite=True, creator=self.teacher) self.user1_course = Course.objects.create( name="Python Course", @@ -2520,6 +2532,10 @@ class TestCourseDetail(TestCase): name="Python Course", enrollment="Enroll Request", creator=self.user1 ) + self.user1_othercourse = Course.objects.create( + name="Python Course II", + enrollment="Enroll Request", creator=self.user1 + ) self.learning_module = LearningModule.objects.create( name="test module", description="test description module", html_data="test html description module", creator=self.user1, @@ -2538,6 +2554,7 @@ class TestCourseDetail(TestCase): self.user2.delete() self.student.delete() self.user1_course.delete() + self.user1_othercourse.delete() self.mod_group.delete() def test_upload_users_with_correct_csv(self): @@ -2562,7 +2579,63 @@ class TestCourseDetail(TestCase): self.assertEqual(uploaded_user.count(), 1) self.assertEqual(response.status_code, 200) self.assertIn('upload_details', response.context) + self.assertIn(uploaded_user.first(), self.user1_course.students.all()) + self.assertTemplateUsed(response, 'yaksh/course_detail.html') + + def test_upload_existing_user(self): + # Given + self.client.login( + username=self.user1.username, password=self.user1_plaintext_pass) + csv_file_path = os.path.join(FIXTURES_DIR_PATH, 'existing_user.csv') + csv_file = open(csv_file_path, 'rb') + upload_file = SimpleUploadedFile(csv_file_path, csv_file.read()) + csv_file.close() + + # When + response = self.client.post( + reverse('yaksh:upload_users', + kwargs={'course_id': self.user1_course.id}), + data={'csv_file': upload_file}) + + # Then + self.assertEqual(response.status_code, 200) + self.assertIn('upload_details', response.context) self.assertTemplateUsed(response, 'yaksh/course_detail.html') + self.assertIn(self.user2, self.user1_course.students.all()) + + def test_upload_same_user_multiple_course(self): + # Given + self.client.login( + username=self.user1.username, password=self.user1_plaintext_pass) + csv_file_path = os.path.join(FIXTURES_DIR_PATH, 'users_correct.csv') + csv_file = open(csv_file_path, 'rb') + upload_file1 = SimpleUploadedFile(csv_file_path, csv_file.read()) + csv_file.seek(0) + upload_file2 = SimpleUploadedFile(csv_file_path, csv_file.read()) + csv_file.close() + + # When + response1 = self.client.post( + reverse('yaksh:upload_users', + kwargs={'course_id': self.user1_course.id}), + data={'csv_file': upload_file1}) + + response2 = self.client.post( + reverse('yaksh:upload_users', + kwargs={'course_id': self.user1_othercourse.id}), + data={'csv_file': upload_file2}) + + # Then + uploaded_users = User.objects.filter(email='abc@xyz.com') + self.assertEqual(response1.status_code, 200) + self.assertIn('upload_details', response1.context) + self.assertTemplateUsed(response1, 'yaksh/course_detail.html') + self.assertEqual(response2.status_code, 200) + self.assertIn('upload_details', response2.context) + self.assertTemplateUsed(response2, 'yaksh/course_detail.html') + self.assertIn(uploaded_users.first(), self.user1_course.students.all()) + self.assertIn(uploaded_users.first(), + self.user1_othercourse.students.all()) def test_upload_users_add_update_reject(self): # Given @@ -2583,7 +2656,7 @@ class TestCourseDetail(TestCase): csv_file.close() # Then - uploaded_user = User.objects.filter(username="test") + uploaded_user = User.objects.filter(username="test2") user = uploaded_user[0] self.assertEqual(uploaded_user.count(), 1) self.assertEqual(user.first_name, "test2") @@ -5017,19 +5090,25 @@ class TestQuestionPaper(TestCase): ) self.assertEqual(response.status_code, 404) - def test_preview_qustionpaper_without_quiz_owner(self): + def test_preview_questionpaper_without_quiz_owner(self): self.client.login( username=self.teacher.username, password=self.teacher_plaintext_pass ) - # Should raise an HTTP 404 response + # Should pass successfully response = self.client.get( reverse('yaksh:preview_questionpaper', kwargs={"questionpaper_id": self.question_paper.id} ) ) - self.assertEqual(response.status_code, 404) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, 'yaksh/preview_questionpaper.html') + self.assertEqual( + response.context['questions'], + self.questions_list + ) + self.assertEqual(response.context['paper'], self.question_paper) def test_mcq_attempt_right_after_wrong(self): """ Case:- Check if answerpaper and answer marks are updated after |