summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.coveragerc1
-rw-r--r--yaksh/evaluator_tests/test_simple_question_types.py2
-rw-r--r--yaksh/forms.py2
-rw-r--r--yaksh/models.py4
-rw-r--r--yaksh/templatetags/test_custom_filters.py157
-rw-r--r--yaksh/views.py2
6 files changed, 161 insertions, 7 deletions
diff --git a/.coveragerc b/.coveragerc
index 1ddb3fc..a762d08 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -17,6 +17,7 @@ omit =
yaksh/pipeline/*
yaksh/migrations/*
yaksh/templatetags/__init__.py
+ yaksh/templatetags/test_custom_filters.py
yaksh/middleware/__init__.py
setup.py
tasks.py
diff --git a/yaksh/evaluator_tests/test_simple_question_types.py b/yaksh/evaluator_tests/test_simple_question_types.py
index d9d60fe..c113cc8 100644
--- a/yaksh/evaluator_tests/test_simple_question_types.py
+++ b/yaksh/evaluator_tests/test_simple_question_types.py
@@ -602,7 +602,7 @@ class ArrangeQuestionTestCases(unittest.TestCase):
)
self.question1.language = 'python'
self.question1.type = "arrange"
- self.question1.description = "Arrange the alphabets in ascending order"
+ self.question1.description = "Arrange alphabets in ascending order"
self.question1.test_case_type = 'arrangetestcase'
self.question1.save()
diff --git a/yaksh/forms.py b/yaksh/forms.py
index 7eae673..9317a8e 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -36,8 +36,6 @@ question_types = (
("string", "Answer in String"),
("float", "Answer in Float"),
("arrange", "Arrange Options in Order"),
-
-
)
test_case_types = (
diff --git a/yaksh/models.py b/yaksh/models.py
index a79f2f6..624f776 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -1221,8 +1221,8 @@ class QuestionPaper(models.Model):
question_ids = []
for question in questions:
question_ids.append(str(question.id))
- if self.shuffle_testcases and \
- question.type in ["mcq", "mcc"]:
+ if (question.type == "arrange") or (self.shuffle_testcases
+ and question.type in ["mcq", "mcc"]):
testcases = question.get_test_cases()
random.shuffle(testcases)
testcases_ids = ",".join([str(tc.id) for tc in testcases]
diff --git a/yaksh/templatetags/test_custom_filters.py b/yaksh/templatetags/test_custom_filters.py
new file mode 100644
index 0000000..5a73ae0
--- /dev/null
+++ b/yaksh/templatetags/test_custom_filters.py
@@ -0,0 +1,157 @@
+import unittest
+from datetime import datetime, timedelta
+from django.utils import timezone
+import pytz
+
+# local imports
+from yaksh.models import (User, Profile, Question, Quiz, QuestionPaper,
+ QuestionSet, AnswerPaper, Answer, Course,
+ IntegerTestCase, FloatTestCase,
+ StringTestCase, McqTestCase, ArrangeTestCase,
+ TestCaseOrder
+ )
+
+from yaksh.templatetags.custom_filters import (completed, inprogress,
+ get_ordered_testcases,
+ get_arrange_user_answer
+ )
+
+
+def setUpModule():
+ # Create user profile
+ teacher = User.objects.create_user(username='teacher2000',
+ password='demo',
+ email='teacher2000@test.com')
+ Profile.objects.create(user=teacher, roll_number=2000, institute='IIT',
+ department='Chemical', position='Teacher')
+ # Create a course
+ course = Course.objects.create(name="Python Course 2000",
+ enrollment="Enroll Request",
+ creator=teacher)
+ # Create a quiz
+ 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 2000',
+ pass_criteria=0,
+ instructions="Demo Instructions",
+ creator=teacher
+ )
+ # Create a question paper
+ question_paper = QuestionPaper.objects.create(quiz=quiz,
+ total_marks=1.0)
+ # Create an answer paper
+ answerpaper = AnswerPaper.objects.create(user=teacher,
+ 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="teacher2000").delete()
+
+
+class CustomFiltersTestCases(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(self):
+ self.course = Course.objects.get(name="Python Course 2000")
+ self.quiz = Quiz.objects.get(description="demo quiz 2000")
+ self.question_paper = QuestionPaper.objects.get(quiz=self.quiz)
+ self.user = User.objects.get(username='teacher2000')
+ self.question1 = Question.objects.create(summary='int1', points=1,
+ type='code', user=self.user)
+ self.question1.language = 'python'
+ self.question1.type = "arrange"
+ self.question1.description = "Arrange alphabets in ascending order"
+ self.question1.test_case_type = 'arrangetestcase'
+ self.question1.save()
+ self.question_paper.fixed_questions.add(self.question1)
+ self.question_paper.save()
+ #Creating answerpaper
+
+ 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
+ self.arrange_testcase_1 = ArrangeTestCase(question=self.question1,
+ options="A",
+ type = 'arrangetestcase',
+ )
+ self.arrange_testcase_1.save()
+ self.testcase_1_id = self.arrange_testcase_1.id
+ self.arrange_testcase_2 = ArrangeTestCase(question=self.question1,
+ options="B",
+ type = 'arrangetestcase',
+ )
+ self.arrange_testcase_2.save()
+ self.testcase_2_id = self.arrange_testcase_2.id
+ self.arrange_testcase_3 = ArrangeTestCase(question=self.question1,
+ options="C",
+ type = 'arrangetestcase',
+ )
+ self.arrange_testcase_3.save()
+ self.testcase_3_id = self.arrange_testcase_3.id
+
+ @classmethod
+ def tearDownClass(self):
+ self.question1.delete()
+ self.answerpaper.delete()
+
+ def test_completed_inprogress(self):
+ # Test in progress
+ answerpaper = AnswerPaper.objects.filter(id=self.answerpaper.id)
+
+ self.assertEqual(inprogress(answerpaper), 1)
+ self.assertEqual(completed(answerpaper), 0)
+ # Test completed
+ self.answerpaper.status='completed'
+ self.answerpaper.save()
+ self.assertEqual(inprogress(answerpaper), 0)
+ self.assertEqual(completed(answerpaper), 1)
+
+ def test_get_arrange_user_answer(self):
+ arrange_ans = [self.arrange_testcase_3,
+ self.arrange_testcase_2,
+ self.arrange_testcase_1,
+ ]
+ arrange_ans_id = [tc.id for tc in arrange_ans]
+ user_ans_order = get_arrange_user_answer(arrange_ans_id,
+ self.question1
+ )
+ self.assertSequenceEqual(arrange_ans, user_ans_order)
+
+ def test_get_ordered_testcases(self):
+ new_answerpaper = self.question_paper.make_answerpaper(self.user,
+ "101.0.0.1",2,
+ self.course.id
+ )
+ tc = TestCaseOrder.objects.get(answer_paper=new_answerpaper,
+ question=self.question1
+ )
+ tc_list = [self.question1.get_test_case(id=ids)
+ for ids in tc.order.split(",")
+ ]
+
+ ordered_testcases = get_ordered_testcases(self.question1,
+ new_answerpaper
+ )
+ self.assertSequenceEqual(tc_list, ordered_testcases)
+
+ new_answerpaper.delete()
diff --git a/yaksh/views.py b/yaksh/views.py
index 9a66f09..f644ac9 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -242,8 +242,6 @@ def add_question(request, question_id=None):
if qform.is_valid():
question = qform.save(commit=False)
question.user = user
- if question.type == "arrange":
- question.shuffle_testcases = True
question.save()
# many-to-many field save function used to save the tags
qform.save_m2m()