From 508e0e78bb0bd3e8ebbad81e948f13de5c01b20f Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Tue, 14 Apr 2020 20:13:52 +0530 Subject: Change model name Thread to Post to avoid conflicts - Thread class from threading conflicts with the forum Thread model. - Tests for models and views. - PEP8 fix. --- yaksh/test_models.py | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 3 deletions(-) (limited to 'yaksh/test_models.py') 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() -- cgit From 3a01e7eb424a0eadfe27386db275682b9d5ca5bd Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Wed, 22 Apr 2020 18:26:44 +0530 Subject: More Tests --- yaksh/test_models.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'yaksh/test_models.py') diff --git a/yaksh/test_models.py b/yaksh/test_models.py index a57a61b..4e6b1ae 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -2320,3 +2320,47 @@ class PostModelTestCases(unittest.TestCase): 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 -- cgit