summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormahesh2018-01-19 12:44:57 +0530
committermaheshgudi2018-03-16 15:15:50 +0530
commit03e74a964504e98cb0f01678ce12a626581a406b (patch)
tree1976acc4db1a1ceb94308b54a501bb22fe939c8f
parent98775e565c99fd6486fb5908a5ca9be491db9b1c (diff)
downloadonline_test-03e74a964504e98cb0f01678ce12a626581a406b.tar.gz
online_test-03e74a964504e98cb0f01678ce12a626581a406b.tar.bz2
online_test-03e74a964504e98cb0f01678ce12a626581a406b.zip
Add test cases for shuffle testcase
-rw-r--r--yaksh/evaluator_tests/test_simple_question_types.py203
-rw-r--r--yaksh/test_models.py3
2 files changed, 178 insertions, 28 deletions
diff --git a/yaksh/evaluator_tests/test_simple_question_types.py b/yaksh/evaluator_tests/test_simple_question_types.py
index b86a9d8..3fe27d4 100644
--- a/yaksh/evaluator_tests/test_simple_question_types.py
+++ b/yaksh/evaluator_tests/test_simple_question_types.py
@@ -4,49 +4,56 @@ from django.utils import timezone
import pytz
from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\
QuestionSet, AnswerPaper, Answer, Course, IntegerTestCase, FloatTestCase,\
- StringTestCase
+ StringTestCase, McqTestCase
def setUpModule():
- # create user profile
+ # Create user profile
+ # Create User 1
user = User.objects.create_user(username='demo_user_100',
password='demo',
email='demo@test.com')
+
Profile.objects.create(user=user, roll_number=1,
institute='IIT', department='Aerospace',
position='Student')
+ # Create User 2
+ user2 = User.objects.create_user(username='demo_user_101',
+ password='demo',
+ email='demo@test.com')
- # create a course
+ Profile.objects.create(user=user2, roll_number=2,
+ institute='IIT', department='Aerospace',
+ position='Student')
+
+ # Create a course
course = Course.objects.create(name="Python Course 100",
enrollment="Enroll Request", creator=user)
- quiz = Quiz.objects.create(start_date_time=datetime(2015, 10, 9, 10, 8, 15, 0,
- tzinfo=pytz.utc),
- end_date_time=datetime(2199, 10, 9, 10, 8, 15, 0,
- tzinfo=pytz.utc),
+ quiz = Quiz.objects.create(start_date_time=datetime\
+ (2015, 10, 9, 10, 8, 15, 0,
+ tzinfo=pytz.utc),
+ end_date_time=datetime\
+ (2199, 10, 9, 10, 8, 15, 0,
+ tzinfo=pytz.utc),
duration=30, active=True, attempts_allowed=1,
- time_between_attempts=0, description='demo quiz 100',
- pass_criteria=0,
+ time_between_attempts=0, pass_criteria=0,
+ description='demo quiz 100',
instructions="Demo Instructions"
)
question_paper = QuestionPaper.objects.create(quiz=quiz,
total_marks=1.0)
- answerpaper = AnswerPaper.objects.create(user=user, user_ip='101.0.0.1',
- start_time=timezone.now(),
- question_paper=question_paper,
- end_time=timezone.now()
- +timedelta(minutes=5),
- attempt_number=1,
- course=course
- )
-
+
def tearDownModule():
User.objects.get(username="demo_user_100").delete()
+ User.objects.get(username="demo_user_101").delete()
class IntegerQuestionTestCases(unittest.TestCase):
@classmethod
def setUpClass(self):
+ # Creating Course
+ self.course = Course.objects.get(name="Python Course 100")
# Creating Quiz
self.quiz = Quiz.objects.get(description="demo quiz 100")
# Creating Question paper
@@ -65,9 +72,16 @@ class IntegerQuestionTestCases(unittest.TestCase):
self.question1.save()
#Creating answerpaper
- self.answerpaper = AnswerPaper.objects.get(question_paper\
- =self.question_paper)
- self.answerpaper.attempt_number = 1
+
+ self.answerpaper = AnswerPaper.objects.create(user=self.user,
+ user_ip='101.0.0.1',
+ start_time=timezone.now(),
+ question_paper=self.question_paper,
+ end_time=timezone.now()
+ +timedelta(minutes=5),
+ attempt_number=1,
+ course=self.course
+ )
self.answerpaper.questions.add(self.question1)
self.answerpaper.save()
# For question
@@ -80,6 +94,7 @@ class IntegerQuestionTestCases(unittest.TestCase):
@classmethod
def tearDownClass(self):
self.question1.delete()
+ self.answerpaper.delete()
def test_validate_regrade_integer_correct_answer(self):
# Given
@@ -158,6 +173,8 @@ class IntegerQuestionTestCases(unittest.TestCase):
class StringQuestionTestCases(unittest.TestCase):
@classmethod
def setUpClass(self):
+ # Creating Course
+ self.course = Course.objects.get(name="Python Course 100")
# Creating Quiz
self.quiz = Quiz.objects.get(description="demo quiz 100")
# Creating Question paper
@@ -182,9 +199,16 @@ class StringQuestionTestCases(unittest.TestCase):
self.question2.save()
#Creating answerpaper
- self.answerpaper = AnswerPaper.objects.get(question_paper\
- =self.question_paper)
- self.answerpaper.attempt_number = 1
+
+ self.answerpaper = AnswerPaper.objects.create(user=self.user,
+ user_ip='101.0.0.1',
+ start_time=timezone.now(),
+ question_paper=self.question_paper,
+ end_time=timezone.now()
+ +timedelta(minutes=5),
+ attempt_number=1,
+ course=self.course
+ )
self.answerpaper.questions.add(*[self.question1, self.question2])
self.answerpaper.save()
@@ -207,6 +231,7 @@ class StringQuestionTestCases(unittest.TestCase):
def tearDownClass(self):
self.question1.delete()
self.question2.delete()
+ self.answerpaper.delete()
def test_validate_regrade_case_insensitive_string_correct_answer(self):
# Given
@@ -346,6 +371,8 @@ class StringQuestionTestCases(unittest.TestCase):
class FloatQuestionTestCases(unittest.TestCase):
@classmethod
def setUpClass(self):
+ # Creating Course
+ self.course = Course.objects.get(name="Python Course 100")
# Creating Quiz
self.quiz = Quiz.objects.get(description="demo quiz 100")
# Creating Question paper
@@ -362,9 +389,16 @@ class FloatQuestionTestCases(unittest.TestCase):
self.question1.save()
#Creating answerpaper
- self.answerpaper = AnswerPaper.objects.get(question_paper\
- =self.question_paper)
- self.answerpaper.attempt_number = 1
+
+ self.answerpaper = AnswerPaper.objects.create(user=self.user,
+ user_ip='101.0.0.1',
+ start_time=timezone.now(),
+ question_paper=self.question_paper,
+ end_time=timezone.now()
+ +timedelta(minutes=5),
+ attempt_number=1,
+ course=self.course
+ )
self.answerpaper.questions.add(self.question1)
self.answerpaper.save()
# For question
@@ -378,6 +412,7 @@ class FloatQuestionTestCases(unittest.TestCase):
@classmethod
def tearDownClass(self):
self.question1.delete()
+ self.answerpaper.delete()
def test_validate_regrade_float_correct_answer(self):
# Given
@@ -450,3 +485,117 @@ class FloatQuestionTestCases(unittest.TestCase):
self.assertTrue(details[0])
self.assertEqual(self.answer.marks, 1)
self.assertTrue(self.answer.correct)
+
+class MCQQuestionTestCases(unittest.TestCase):
+ @classmethod
+ def setUpClass(self):
+ #Creating User
+ self.user = User.objects.get(username='demo_user_100')
+ self.user2 = User.objects.get(username='demo_user_101')
+ self.user_ip = '127.0.0.1'
+
+ #Creating Course
+ self.course = Course.objects.get(name="Python Course 100")
+ # Creating Quiz
+ self.quiz = Quiz.objects.get(description="demo quiz 100")
+ # Creating Question paper
+ self.question_paper = QuestionPaper.objects.get(quiz=self.quiz)
+ #Creating Question
+ self.question1 = Question.objects.create(summary='mcq1', points=1,
+ type='code', user=self.user,
+ )
+ self.question1.language = 'python'
+ self.question1.type = "mcq"
+ self.question1.test_case_type = 'Mcqtestcase'
+ self.question1.description = 'Which option is Correct?'
+ self.question1.shuffle_testcases = True
+ self.question1.save()
+
+ # For questions
+ self.mcq_based_testcase_1 = McqTestCase(question=self.question1,
+ options="Correct",
+ correct=True,
+ type='mcqtestcase',
+ )
+ self.mcq_based_testcase_1.save()
+
+ self.mcq_based_testcase_2 = McqTestCase(question=self.question1,
+ options="Incorrect",
+ correct=False,
+ type='mcqtestcase',
+ )
+ self.mcq_based_testcase_2.save()
+
+ self.mcq_based_testcase_3 = McqTestCase(question=self.question1,
+ options="Incorrect",
+ correct=False,
+ type='mcqtestcase',
+ )
+ self.mcq_based_testcase_3.save()
+
+ self.mcq_based_testcase_4 = McqTestCase(question=self.question1,
+ options="Incorrect",
+ correct=False,
+ type='mcqtestcase',
+ )
+ self.mcq_based_testcase_4.save()
+
+ self.question_paper.fixed_questions.add(self.question1)
+
+ self.answerpaper = self.question_paper.make_answerpaper(
+ user=self.user, ip=self.user_ip,
+ attempt_num=1,
+ course_id=self.course.id
+ )
+
+ # Answerpaper for user 2
+ self.answerpaper2 = self.question_paper.make_answerpaper(
+ user=self.user2, ip=self.user_ip,
+ attempt_num=1,
+ course_id=self.course.id
+ )
+
+ @classmethod
+ def tearDownClass(self):
+ self.question1.delete()
+
+ def test_shuffle_test_cases(self):
+ # Given
+ # Answerpaper for user 1
+ # When
+ user_testcase = self.question1.get_ordered_test_cases(
+ self.answerpaper
+ )
+ order1 = [tc.id for tc in user_testcase]
+ user2_testcase = self.question1.get_ordered_test_cases(
+ self.answerpaper2
+ )
+ order2 = [tc.id for tc in user2_testcase]
+
+ # Then
+ self.assertNotEqual(order1, order2)
+
+ # def test_not_shuffle_test_cases(self):
+ # # Given
+ # self.question1.shuffle_testcases = False
+ # self.question1.save()
+ # answerpaper = self.question_paper.make_answerpaper(
+ # user=self.user, ip=self.user_ip,
+ # attempt_num=1,
+ # course_id=self.course.id
+ # )
+
+ # # Answerpaper for user 2
+ # answerpaper2 = self.question_paper.make_answerpaper(
+ # user=self.user2, ip=self.user_ip,
+ # attempt_num=1,
+ # course_id=self.course.id
+ # )
+
+ # user_testcase = self.question1.get_ordered_test_cases(answerpaper)
+ # order1 = [tc.id for tc in user_testcase]
+
+ # user2_testcase = self.question1.get_ordered_test_cases(answerpaper2)
+ # order2 = [tc.id for tc in user2_testcase]
+ # print(order2, order1)
+ # self.assertNotEqual(order1, order2) \ No newline at end of file
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index cd4279b..381a2f3 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -113,6 +113,7 @@ def tearDownModule():
Lesson.objects.all().delete()
LearningUnit.objects.all().delete()
LearningModule.objects.all().delete()
+ AnswerPaper.objects.all().delete()
###############################################################################
@@ -848,7 +849,7 @@ class AnswerPaperTestCases(unittest.TestCase):
)
self.qtn_paper_with_single_question.save()
- all_questions = Question.objects.all()
+ all_questions = Question.objects.filter(user=self.user)
self.questions = all_questions[0:3]
self.start_time = timezone.now()
self.end_time = self.start_time + timedelta(minutes=20)