summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/evaluator_tests/test_simple_question_types.py38
-rw-r--r--yaksh/models.py1
-rw-r--r--yaksh/test_models.py110
3 files changed, 74 insertions, 75 deletions
diff --git a/yaksh/evaluator_tests/test_simple_question_types.py b/yaksh/evaluator_tests/test_simple_question_types.py
index ca93220..1d0a1e2 100644
--- a/yaksh/evaluator_tests/test_simple_question_types.py
+++ b/yaksh/evaluator_tests/test_simple_question_types.py
@@ -9,20 +9,19 @@ from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\
def setUpModule():
# create user profile
- user = User.objects.create_user(pk=1,username='demo_user',
+ 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 2 questions
for i in range(101, 103):
Question.objects.create(summary='Q%d' % (i), points=1,
type='code', user=user)
# create a course
- course = Course.objects.create(name="Python 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,
@@ -30,12 +29,12 @@ def setUpModule():
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',
+ time_between_attempts=0, description='demo quiz 100',
pass_criteria=0,language='Python',
prerequisite=None,course=course,
instructions="Demo Instructions"
)
- question_paper = QuestionPaper.objects.create(pk=1, quiz=quiz,
+ question_paper = QuestionPaper.objects.create(quiz=quiz,
total_marks=1.0)
answerpaper = AnswerPaper.objects.create(user=user, user_ip='101.0.0.1',
@@ -46,24 +45,20 @@ def setUpModule():
attempt_number=1
)
- with open('/tmp/test.txt', 'wb') as f:
- f.write('2'.encode('ascii'))
-
def tearDownModule():
- User.objects.all().delete()
- Question.objects.all().delete()
- Quiz.objects.all().delete()
+ User.objects.get(username="demo_user_100").delete()
class IntegerQuestionTestCases(unittest.TestCase):
@classmethod
def setUpClass(self):
# Creating Quiz
+ self.quiz = Quiz.objects.get(description="demo quiz 100")
# Creating Question paper
- self.question_paper = QuestionPaper.objects.get(pk=1)
+ self.question_paper = QuestionPaper.objects.get(quiz=self.quiz)
#Creating User
- self.user = User.objects.get(pk=1)
+ self.user = User.objects.get(username='demo_user_100')
#Creating Question
self.question1 = Question.objects.get(summary='Q101')
@@ -125,12 +120,12 @@ class IntegerQuestionTestCases(unittest.TestCase):
class StringQuestionTestCases(unittest.TestCase):
@classmethod
def setUpClass(self):
+ # Creating Quiz
+ self.quiz = Quiz.objects.get(description="demo quiz 100")
# Creating Question paper
- self.question_paper = QuestionPaper.objects.get(pk=1)
-
+ self.question_paper = QuestionPaper.objects.get(quiz=self.quiz)
#Creating User
- self.user = User.objects.get(pk=1)
-
+ self.user = User.objects.get(username='demo_user_100')
#Creating Question
self.question1 = Question.objects.get(summary='Q101')
self.question1.language = 'python'
@@ -233,12 +228,13 @@ class StringQuestionTestCases(unittest.TestCase):
class FloatQuestionTestCases(unittest.TestCase):
@classmethod
def setUpClass(self):
- #Creating User
- self.user = User.objects.get(pk=1)
-
+ # Creating Quiz
+ self.quiz = Quiz.objects.get(description="demo quiz 100")
# Creating Question paper
- self.question_paper = QuestionPaper.objects.get(pk=1)
+ self.question_paper = QuestionPaper.objects.get(quiz=self.quiz)
+ #Creating User
+ self.user = User.objects.get(username='demo_user_100')
#Creating Question
self.question1 = Question.objects.get(summary='Q101')
self.question1.language = 'python'
diff --git a/yaksh/models.py b/yaksh/models.py
index a356ec1..d60a377 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -683,7 +683,6 @@ class QuestionPaper(models.Model):
# Total marks for the question paper.
total_marks = models.FloatField(default=0.0, blank=True)
-
objects = QuestionPaperManager()
def update_total_marks(self):
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index 91d8806..ada5a65 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -44,7 +44,7 @@ def setUpModule():
tzinfo=pytz.utc),
duration=30, active=True,
attempts_allowed=1, time_between_attempts=0,
- description='demo quiz', pass_criteria=0,
+ description='demo quiz 1', pass_criteria=0,
language='Python', prerequisite=None,
course=course, instructions="Demo Instructions")
@@ -54,7 +54,7 @@ def setUpModule():
tzinfo=pytz.utc),
duration=30, active=False,
attempts_allowed=-1, time_between_attempts=0,
- description='demo quiz', pass_criteria=40,
+ description='demo quiz 2', pass_criteria=40,
language='Python', prerequisite=quiz,
course=course, instructions="Demo Instructions")
@@ -65,6 +65,8 @@ def tearDownModule():
User.objects.all().delete()
Question.objects.all().delete()
Quiz.objects.all().delete()
+ Course.objects.all().delete()
+ QuestionPaper.objects.all().delete()
que_id_list = ["25", "22", "24", "27"]
for que_id in que_id_list:
@@ -75,9 +77,9 @@ def tearDownModule():
###############################################################################
class ProfileTestCases(unittest.TestCase):
def setUp(self):
- self.user1 = User.objects.get(pk=1)
- self.profile = Profile.objects.get(pk=1)
- self.user2 = User.objects.get(pk=3)
+ self.user1 = User.objects.get(username="demo_user")
+ self.profile = Profile.objects.get(user=self.user1)
+ self.user2 = User.objects.get(username='demo_user3')
def test_user_profile(self):
""" Test user profile"""
@@ -92,9 +94,9 @@ class ProfileTestCases(unittest.TestCase):
class QuestionTestCases(unittest.TestCase):
def setUp(self):
# Single question details
- self.user1 = User.objects.get(pk=1)
- self.user2 = User.objects.get(pk=2)
- self.question1 = Question(summary='Demo question',
+ self.user1 = User.objects.get(username="demo_user")
+ self.user2 = User.objects.get(username="demo_user2")
+ self.question1 = Question.objects.create(summary='Demo Python 1',
language='Python',
type='Code',
active=True,
@@ -103,9 +105,8 @@ class QuestionTestCases(unittest.TestCase):
snippet='def myfunc()',
user=self.user1
)
- self.question1.save()
- self.question2 = Question(summary='Demo Json',
+ self.question2 = Question.objects.create(summary='Demo Json',
language='python',
type='code',
active=True,
@@ -114,7 +115,6 @@ class QuestionTestCases(unittest.TestCase):
snippet='def fact()',
user=self.user2
)
- self.question2.save()
# create a temp directory and add files for loading questions test
file_path = "/tmp/test.txt"
@@ -161,7 +161,7 @@ class QuestionTestCases(unittest.TestCase):
def test_question(self):
""" Test question """
- self.assertEqual(self.question1.summary, 'Demo question')
+ self.assertEqual(self.question1.summary, 'Demo Python 1')
self.assertEqual(self.question1.language, 'Python')
self.assertEqual(self.question1.type, 'Code')
self.assertEqual(self.question1.description, 'Write a function')
@@ -203,8 +203,8 @@ class QuestionTestCases(unittest.TestCase):
""" Test load questions into database from json """
question = Question()
result = question.load_questions(self.json_questions_data, self.user1)
- question_data = Question.objects.get(pk=25)
- file = FileUpload.objects.get(question=25)
+ question_data = Question.objects.get(summary="Json Demo")
+ file = FileUpload.objects.get(question=question_data)
test_case = question_data.get_test_cases()
self.assertEqual(question_data.summary, 'Json Demo')
self.assertEqual(question_data.language, 'Python')
@@ -220,10 +220,10 @@ class QuestionTestCases(unittest.TestCase):
###############################################################################
class QuizTestCases(unittest.TestCase):
def setUp(self):
- self.creator = User.objects.get(pk=1)
- self.teacher = User.objects.get(pk=2)
- self.quiz1 = Quiz.objects.get(pk=1)
- self.quiz2 = Quiz.objects.get(pk=2)
+ self.creator = User.objects.get(username="demo_user")
+ self.teacher = User.objects.get(username="demo_user2")
+ self.quiz1 = Quiz.objects.get(description='demo quiz 1')
+ self.quiz2 = Quiz.objects.get(description='demo quiz 2')
self.trial_course = Course.objects.create_trial_course(self.creator)
def test_quiz(self):
@@ -234,7 +234,7 @@ class QuizTestCases(unittest.TestCase):
'10:08:15')
self.assertEqual(self.quiz1.duration, 30)
self.assertTrue(self.quiz1.active)
- self.assertEqual(self.quiz1.description, 'demo quiz')
+ self.assertEqual(self.quiz1.description, 'demo quiz 1')
self.assertEqual(self.quiz1.language, 'Python')
self.assertEqual(self.quiz1.pass_criteria, 0)
self.assertEqual(self.quiz1.prerequisite, None)
@@ -270,7 +270,9 @@ class QuizTestCases(unittest.TestCase):
self.creator,
True
)
- self.assertEqual(trial_quiz.description, "Trial_orig_id_1_godmode")
+ self.assertEqual(trial_quiz.description,
+ "Trial_orig_id_{}_godmode".format(self.quiz1.id)
+ )
self.assertTrue(trial_quiz.is_trial)
self.assertEqual(trial_quiz.duration, 1000)
self.assertTrue(trial_quiz.active)
@@ -285,7 +287,8 @@ class QuizTestCases(unittest.TestCase):
self.creator,
False
)
- self.assertEqual(trial_quiz.description, "Trial_orig_id_2_usermode")
+ self.assertEqual(trial_quiz.description,
+ "Trial_orig_id_{}_usermode".format(self.quiz2.id))
self.assertTrue(trial_quiz.is_trial)
self.assertEqual(trial_quiz.duration, self.quiz2.duration)
self.assertEqual(trial_quiz.active, self.quiz2.active)
@@ -316,7 +319,7 @@ class QuestionPaperTestCases(unittest.TestCase):
def setUpClass(self):
# All active questions
self.questions = Question.objects.filter(active=True)
- self.quiz = Quiz.objects.get(id=1)
+ self.quiz = Quiz.objects.get(description="demo quiz 1")
# create question paper
self.question_paper = QuestionPaper.objects.create(quiz=self.quiz,
@@ -359,7 +362,7 @@ class QuestionPaperTestCases(unittest.TestCase):
# ip address for AnswerPaper
self.ip = '127.0.0.1'
- self.user = User.objects.get(pk=1)
+ self.user = User.objects.get(username="demo_user")
self.attempted_papers = AnswerPaper.objects.filter(
question_paper=self.question_paper,
@@ -373,7 +376,7 @@ class QuestionPaperTestCases(unittest.TestCase):
def test_questionpaper(self):
""" Test question paper"""
- self.assertEqual(self.question_paper.quiz.description, 'demo quiz')
+ self.assertEqual(self.question_paper.quiz.description, 'demo quiz 1')
self.assertSequenceEqual(self.question_paper.fixed_questions.all(),
[self.questions[3], self.questions[5]])
self.assertTrue(self.question_paper.shuffle_questions)
@@ -453,17 +456,17 @@ class AnswerPaperTestCases(unittest.TestCase):
@classmethod
def setUpClass(self):
self.ip = '101.0.0.1'
- self.user = User.objects.get(id=1)
+ self.user = User.objects.get(username='demo_user')
self.profile = self.user.profile
- self.quiz = Quiz.objects.get(pk=1)
+ self.quiz = Quiz.objects.get(description='demo quiz 1')
self.question_paper = QuestionPaper(quiz=self.quiz, total_marks=3)
self.question_paper.save()
- self.questions = Question.objects.filter(id__in=[1,2,3])
+ self.questions = Question.objects.all()[0:3]
self.start_time = timezone.now()
self.end_time = self.start_time + timedelta(minutes=20)
- self.question1 = self.questions.get(id=1)
- self.question2 = self.questions.get(id=2)
- self.question3 = self.questions.get(id=3)
+ self.question1 = self.questions[0]
+ self.question2 = self.questions[1]
+ self.question3 = self.questions[2]
# create answerpaper
self.answerpaper = AnswerPaper(user=self.user,
@@ -483,12 +486,12 @@ class AnswerPaperTestCases(unittest.TestCase):
self.answerpaper.questions_unanswered.add(*self.questions)
self.answerpaper.save()
# answers for the Answer Paper
- self.answer_right = Answer(question=Question.objects.get(id=1),
+ self.answer_right = Answer(question=self.question1,
answer="Demo answer",
correct=True, marks=1,
error=json.dumps([])
)
- self.answer_wrong = Answer(question=Question.objects.get(id=2),
+ self.answer_wrong = Answer(question=self.question2,
answer="My answer",
correct=False,
marks=0,
@@ -501,14 +504,17 @@ class AnswerPaperTestCases(unittest.TestCase):
self.question1.language = 'python'
self.question1.test_case_type = 'standardtestcase'
+ self.question1.summary = "Question1"
self.question1.save()
self.question2.language = 'python'
self.question2.type = 'mcq'
self.question2.test_case_type = 'mcqtestcase'
+ self.question2.summary = "Question2"
self.question2.save()
self.question3.language = 'python'
self.question3.type = 'mcc'
self.question3.test_case_type = 'mcqtestcase'
+ self.question3.summary = "Question3"
self.question3.save()
self.assertion_testcase = StandardTestCase(
question=self.question1,
@@ -660,21 +666,21 @@ class AnswerPaperTestCases(unittest.TestCase):
self.assertEqual(self.answerpaper.questions_left(), 3)
# Test current_question() method of Answer Paper
current_question = self.answerpaper.current_question()
- self.assertEqual(current_question.id, 1)
+ self.assertEqual(current_question.summary, "Question1")
# Test completed_question() method of Answer Paper
- question = self.answerpaper.completed_question(1)
+ question = self.answerpaper.completed_question(self.question1.id)
self.assertEqual(self.answerpaper.questions_left(), 2)
# Test next_question() method of Answer Paper
current_question = self.answerpaper.current_question()
- self.assertEqual(current_question.id, 2)
+ self.assertEqual(current_question.summary, "Question2")
# When
next_question_id = self.answerpaper.next_question(current_question.id)
# Then
self.assertTrue(next_question_id is not None)
- self.assertEqual(next_question_id.id, 3)
+ self.assertEqual(next_question_id.summary, "Question3")
# Given, here question is already answered
current_question_id = 1
@@ -684,7 +690,7 @@ class AnswerPaperTestCases(unittest.TestCase):
# Then
self.assertTrue(next_question_id is not None)
- self.assertEqual(next_question_id.id, 2)
+ self.assertEqual(next_question_id.summary, "Question2")
# Given, wrong question id
current_question_id = 12
@@ -694,7 +700,7 @@ class AnswerPaperTestCases(unittest.TestCase):
# Then
self.assertTrue(next_question_id is not None)
- self.assertEqual(next_question_id.id, 2)
+ self.assertEqual(next_question_id.summary, "Question2")
# Given, last question in the list
current_question_id = 3
@@ -704,7 +710,7 @@ class AnswerPaperTestCases(unittest.TestCase):
# Then
self.assertTrue(next_question_id is not None)
- self.assertEqual(next_question_id.id, 2)
+ self.assertEqual(next_question_id.summary, "Question2")
# Test get_questions_answered() method
# When
@@ -724,14 +730,14 @@ class AnswerPaperTestCases(unittest.TestCase):
# Test completed_question and next_question
# When all questions are answered
- current_question = self.answerpaper.completed_question(2)
+ current_question = self.answerpaper.completed_question(self.question2.id)
# Then
self.assertEqual(self.answerpaper.questions_left(), 1)
- self.assertEqual(current_question.id, 3)
+ self.assertEqual(current_question.summary, "Question3")
# When
- current_question = self.answerpaper.completed_question(3)
+ current_question = self.answerpaper.completed_question(self.question3.id)
# Then
self.assertEqual(self.answerpaper.questions_left(), 0)
@@ -791,12 +797,12 @@ class AnswerPaperTestCases(unittest.TestCase):
###############################################################################
class CourseTestCases(unittest.TestCase):
def setUp(self):
- self.course = Course.objects.get(pk=1)
- self.creator = User.objects.get(pk=1)
- self.student1 = User.objects.get(pk=2)
- self.student2 = User.objects.get(pk=3)
- self.quiz1 = Quiz.objects.get(pk=1)
- self.quiz2 = Quiz.objects.get(pk=2)
+ self.course = Course.objects.get(name="Python Course")
+ self.creator = User.objects.get(username="demo_user")
+ self.student1 = User.objects.get(username="demo_user2")
+ self.student2 = User.objects.get(username="demo_user3")
+ self.quiz1 = Quiz.objects.get(description='demo quiz 1')
+ self.quiz2 = Quiz.objects.get(description='demo quiz 2')
def test_is_creator(self):
@@ -873,21 +879,19 @@ class CourseTestCases(unittest.TestCase):
def test_create_trial_course(self):
"""Test to check if trial course is created"""
- # Test for manager method create_trial_course
trial_course = Course.objects.create_trial_course(self.creator)
self.assertEqual(trial_course.name, "trial_course")
self.assertEqual(trial_course.enrollment, "open")
self.assertTrue(trial_course.active)
- self.assertEqual(trial_course.students.get(user=self.creator.id),
- self.creator
- )
+ self.assertEqual(self.creator, trial_course.creator)
+ self.assertIn(self.creator, trial_course.students.all())
self.assertTrue(trial_course.is_trial)
###############################################################################
class TestCaseTestCases(unittest.TestCase):
def setUp(self):
- self.user = User.objects.get(pk=1)
+ self.user = User.objects.get(username="demo_user")
self.question1 = Question(summary='Demo question 1',
language='Python',
type='Code',