diff options
author | adityacp | 2020-04-27 15:04:31 +0530 |
---|---|---|
committer | adityacp | 2020-04-27 15:31:37 +0530 |
commit | b8636965de8a86e68fd542754678e6826c7e5eac (patch) | |
tree | 638930dd42140d760e443c0d35874de6e27b3ef9 /yaksh/test_models.py | |
parent | e3f73db877aaf2f6406bef39aee590530bcb503b (diff) | |
parent | 53a0c4ad3e733f3960000527f83565f2fd8fc412 (diff) | |
download | online_test-b8636965de8a86e68fd542754678e6826c7e5eac.tar.gz online_test-b8636965de8a86e68fd542754678e6826c7e5eac.tar.bz2 online_test-b8636965de8a86e68fd542754678e6826c7e5eac.zip |
Resolve conflicts in travis, requirements and views
Diffstat (limited to 'yaksh/test_models.py')
-rw-r--r-- | yaksh/test_models.py | 131 |
1 files changed, 128 insertions, 3 deletions
diff --git a/yaksh/test_models.py b/yaksh/test_models.py index a60a1d6..4e6b1ae 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,129 @@ 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() + + +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()
\ No newline at end of file |