diff options
Diffstat (limited to 'yaksh/test_models.py')
-rw-r--r-- | yaksh/test_models.py | 87 |
1 files changed, 84 insertions, 3 deletions
diff --git a/yaksh/test_models.py b/yaksh/test_models.py index a60a1d6..a57a61b 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -5,7 +5,7 @@ from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\ QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\ StdIOBasedTestCase, FileUpload, McqTestCase, AssignmentUpload,\ LearningModule, LearningUnit, Lesson, LessonFile, CourseStatus, \ - create_group, legend_display_types + create_group, legend_display_types, Post, Comment from yaksh.code_server import ( ServerPool, get_result as get_result_from_code_server ) @@ -191,7 +191,6 @@ class LearningModuleTestCases(unittest.TestCase): self.prereq_course.students.add(self.student) self.prereq_course.save() - def tearDown(self): # Remove unit from course status completed units self.course_status.completed_units.remove(self.learning_unit_one) @@ -495,7 +494,7 @@ class QuestionTestCases(unittest.TestCase): self.assertEqual(self.question1.snippet, 'def myfunc()') tag_list = [] for tag in self.question1.tags.all(): - tag_list.append(tag.name) + tag_list.append(tag.name) for tag in tag_list: self.assertIn(tag, ['python', 'function']) @@ -2239,3 +2238,85 @@ class FileUploadTestCases(unittest.TestCase): if os.path.isfile(self.file_upload.file.path): os.remove(self.file_upload.file.path) self.file_upload.delete() + + +class PostModelTestCases(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.user2 = User.objects.create( + username='dart', + password='dart', + email='dart@test.com' + ) + Profile.objects.create( + user=self.user2, + roll_number=2, + institute='IIT', + department='Chemical', + position='Student' + ) + + self.user3 = User.objects.create( + username='user3', + password='user3', + email='user3@test.com' + ) + Profile.objects.create( + user=self.user3, + roll_number=3, + is_moderator=True, + department='Chemical', + position='Teacher' + ) + + self.course = Course.objects.create( + name='Python Course', + enrollment='Enroll Request', + creator=self.user3 + ) + 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.user2, + description='Post 1 comment 1' + ) + self.comment2 = Comment.objects.create( + post_field=self.post1, + creator=self.user3, + description='Post 1 user3 comment 2' + ) + + def test_get_last_comment(self): + last_comment = self.post1.get_last_comment() + self.assertEquals(last_comment.description, 'Post 1 user3 comment 2') + + def test_get_comments_count(self): + 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() |