diff options
author | adityacp | 2018-03-22 12:36:45 +0530 |
---|---|---|
committer | adityacp | 2018-03-22 12:36:45 +0530 |
commit | 30be89eef46a248fe6f7ff26a923593ea8371fb1 (patch) | |
tree | 7af1afd0a403e4c71579f9afe830c482e59c3add /yaksh/evaluator_tests | |
parent | e1c1d0d0d6ae170d3ce9966b98ec6d03ff35c062 (diff) | |
parent | 4b356aa2f6097cd0f46292218f31ded18b631e53 (diff) | |
download | online_test-30be89eef46a248fe6f7ff26a923593ea8371fb1.tar.gz online_test-30be89eef46a248fe6f7ff26a923593ea8371fb1.tar.bz2 online_test-30be89eef46a248fe6f7ff26a923593ea8371fb1.zip |
Resolve conflicts and update to latest changes
Diffstat (limited to 'yaksh/evaluator_tests')
-rw-r--r-- | yaksh/evaluator_tests/test_simple_question_types.py | 191 |
1 files changed, 164 insertions, 27 deletions
diff --git a/yaksh/evaluator_tests/test_simple_question_types.py b/yaksh/evaluator_tests/test_simple_question_types.py index b86a9d8..cbf2abd 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,105 @@ 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) + self.question_paper.shuffle_testcases = True + self.question_paper.save() + #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.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() + self.answerpaper.delete() + self.answerpaper2.delete() + + def test_shuffle_test_cases(self): + # Given + # 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] + self.question_paper.shuffle_testcases = False + self.question_paper.save() + answerpaper3 = self.question_paper.make_answerpaper( + user=self.user2, ip=self.user_ip, + attempt_num=self.answerpaper.attempt_number+1, + course_id=self.course.id + ) + not_ordered_testcase = self.question1.get_ordered_test_cases( + answerpaper3 + ) + get_test_cases = self.question1.get_test_cases() + # Then + self.assertNotEqual(order1, order2) + self.assertEqual(get_test_cases, not_ordered_testcase) + answerpaper3.delete() |