summaryrefslogtreecommitdiff
path: root/yaksh/test_models.py
diff options
context:
space:
mode:
authoradityacp2020-04-27 14:50:28 +0530
committeradityacp2020-04-27 14:50:28 +0530
commit9fe624415d15f63f45a5327d74fe8c2432b03d13 (patch)
tree8781ccf6c01c8e124a0c836b487a23499e441bf1 /yaksh/test_models.py
parentd5cdfe91335af6c79231d41453991af29a39e96e (diff)
parent53a0c4ad3e733f3960000527f83565f2fd8fc412 (diff)
downloadonline_test-9fe624415d15f63f45a5327d74fe8c2432b03d13.tar.gz
online_test-9fe624415d15f63f45a5327d74fe8c2432b03d13.tar.bz2
online_test-9fe624415d15f63f45a5327d74fe8c2432b03d13.zip
Resolve conflict
Diffstat (limited to 'yaksh/test_models.py')
-rw-r--r--yaksh/test_models.py131
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