diff options
Diffstat (limited to 'yaksh/test_models.py')
-rw-r--r-- | yaksh/test_models.py | 84 |
1 files changed, 13 insertions, 71 deletions
diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 7ef1ca7..fe0d3b5 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -1,5 +1,6 @@ import unittest from django.contrib.auth.models import Group +from django.contrib.contenttypes.models import ContentType from django.core.files.uploadedfile import SimpleUploadedFile from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\ QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\ @@ -336,7 +337,7 @@ class LearningModuleTestCases(unittest.TestCase): def test_learning_module(self): self.assertEqual(self.learning_module.description, 'module one') self.assertEqual(self.learning_module.creator, self.creator) - self.assertTrue(self.learning_module.check_prerequisite) + self.assertFalse(self.learning_module.check_prerequisite) self.assertEqual(self.learning_module.order, 0) def test_prerequisite_passes(self): @@ -371,16 +372,16 @@ class LearningModuleTestCases(unittest.TestCase): self.assertEqual(module_quiz_lesson, quiz_lessons) def test_toggle_check_prerequisite(self): - self.assertTrue(self.learning_module.check_prerequisite) + self.assertFalse(self.learning_module.check_prerequisite) # When self.learning_module.toggle_check_prerequisite() # Then - self.assertFalse(self.learning_module.check_prerequisite) + self.assertTrue(self.learning_module.check_prerequisite) # When self.learning_module.toggle_check_prerequisite() # Then - self.assertTrue(self.learning_module.check_prerequisite) + self.assertFalse(self.learning_module.check_prerequisite) def test_get_next_unit(self): # Given @@ -466,8 +467,8 @@ class LearningUnitTestCases(unittest.TestCase): ) self.assertIsNone(self.learning_unit_one.quiz) self.assertIsNone(self.learning_unit_two.lesson) - self.assertTrue(self.learning_unit_one.check_prerequisite) - self.assertTrue(self.learning_unit_two.check_prerequisite) + self.assertFalse(self.learning_unit_one.check_prerequisite) + self.assertFalse(self.learning_unit_two.check_prerequisite) class ProfileTestCases(unittest.TestCase): @@ -994,7 +995,7 @@ class QuestionPaperTestCases(unittest.TestCase): # create two QuestionSet for random questions # QuestionSet 1 self.question_set_1 = QuestionSet.objects.create( - marks=2, num_questions=2 + marks=1, num_questions=2 ) # add pool of questions for random sampling @@ -1007,7 +1008,7 @@ class QuestionPaperTestCases(unittest.TestCase): # QuestionSet 2 self.question_set_2 = QuestionSet.objects.create( - marks=3, num_questions=3 + marks=1, num_questions=3 ) # add pool of questions @@ -1074,7 +1075,7 @@ class QuestionPaperTestCases(unittest.TestCase): """ Test update_total_marks() method of Question Paper""" self.assertEqual(self.question_paper.total_marks, 0) self.question_paper.update_total_marks() - self.assertEqual(self.question_paper.total_marks, 15) + self.assertEqual(self.question_paper.total_marks, 7.0) def test_get_random_questions(self): """ Test get_random_questions() method of Question Paper""" @@ -1787,20 +1788,7 @@ class AnswerPaperTestCases(unittest.TestCase): """ Test get_question_answer() method of Answer Paper""" questions = self.answerpaper.questions.all() answered = self.answerpaper.get_question_answers() - for question in questions: - answers_saved = Answer.objects.filter(question=question) - error_list = [json.loads(ans.error) for ans in answers_saved] - if answers_saved: - self.assertGreater(len(answered[question]), len(answers_saved)) - ans = [] - err = [] - for val in answered[question]: - if val.get('answer') is not None: - ans.append(val.get('answer')) - if val.get('error_list') is not None: - err.append(val.get('error_list')) - self.assertEqual(set(ans), set(answers_saved)) - self.assertEqual(error_list, err) + self.assertEqual(list(questions), list(answered.keys())) def test_is_answer_correct(self): self.assertTrue(self.answerpaper.is_answer_correct(self.questions[0])) @@ -2431,9 +2419,10 @@ class PostModelTestCases(unittest.TestCase): enrollment='Enroll Request', creator=self.user3 ) + course_ct = ContentType.objects.get_for_model(self.course) self.post1 = Post.objects.create( title='Post 1', - course=self.course, + target_ct=course_ct, target_id=self.course.id, creator=self.user1, description='Post 1 description' ) @@ -2456,56 +2445,9 @@ class PostModelTestCases(unittest.TestCase): count = self.post1.get_comments_count() self.assertEquals(count, 2) - def test__str__(self): - self.assertEquals(str(self.post1.title), self.post1.title) - def tearDown(self): self.user1.delete() self.user2.delete() self.user3.delete() self.course.delete() self.post1.delete() - - -class CommentModelTestCases(unittest.TestCase): - def setUp(self): - self.user1 = User.objects.create( - username='bart', - password='bart', - email='bart@test.com' - ) - Profile.objects.create( - user=self.user1, - roll_number=1, - institute='IIT', - department='Chemical', - position='Student' - ) - self.course = Course.objects.create( - name='Python Course', - enrollment='Enroll Request', - creator=self.user1 - ) - self.post1 = Post.objects.create( - title='Post 1', - course=self.course, - creator=self.user1, - description='Post 1 description' - ) - self.comment1 = Comment.objects.create( - post_field=self.post1, - creator=self.user1, - description='Post 1 comment 1' - ) - - def test__str__(self): - self.assertEquals( - str(self.comment1.post_field.title), - self.comment1.post_field.title - ) - - def tearDown(self): - self.user1.delete() - self.course.delete() - self.post1.delete() - self.comment1.delete() |