diff options
author | prathamesh | 2014-06-25 10:45:22 +0530 |
---|---|---|
committer | prathamesh | 2014-06-25 10:45:22 +0530 |
commit | 5409b03f915c4569ccb17974e6c09660fa32d8bf (patch) | |
tree | 3bd33a1167053c74656061366e465f84a869ffee /testapp | |
parent | b1ecd46e3924cae0201bdf4bc16f34c7ae16b081 (diff) | |
download | online_test-5409b03f915c4569ccb17974e6c09660fa32d8bf.tar.gz online_test-5409b03f915c4569ccb17974e6c09660fa32d8bf.tar.bz2 online_test-5409b03f915c4569ccb17974e6c09660fa32d8bf.zip |
Added test for new model fields and new methods created in models.
Diffstat (limited to 'testapp')
-rw-r--r-- | testapp/exam/models.py | 39 | ||||
-rw-r--r-- | testapp/exam/tests.py | 25 |
2 files changed, 53 insertions, 11 deletions
diff --git a/testapp/exam/models.py b/testapp/exam/models.py index a6897a4..5bb94fd 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -153,7 +153,7 @@ class QuestionPaper(models.Model): total_marks = models.FloatField() def update_total_marks(self): - """ Returns the total marks for the Question Paper""" + """ Updates the total marks for the Question Paper""" marks = 0.0 questions = self.fixed_questions.all() for question in questions: @@ -243,11 +243,14 @@ class AnswerPaper(models.Model): # Teacher comments on the question paper. comments = models.TextField() - # Result of the quiz, either PASS or FAIL. - result = models.CharField(max_length=4) + # Total marks earned by the student in this paper. + marks_obtained = models.FloatField(null=True, default=None) # Marks percent scored by the user - percent = models.FloatField(null=True) + percent = models.FloatField(null=True, default=None) + + # Result of the quiz, either PASSED or FAILED. + result = models.CharField(max_length=8, null=True, default=None) def current_question(self): """Returns the current active question to display.""" @@ -317,9 +320,31 @@ class AnswerPaper(models.Model): answered = ', '.join(sorted(qa)) return answered if answered else 'None' - def get_marks_obtained(self): - """Returns the total marks earned by student for this paper.""" - return sum([x.marks for x in self.answers.filter(marks__gt=0.0)]) + def update_marks_obtained(self): + """Updates the total marks earned by student for this paper.""" + marks = sum([x.marks for x in self.answers.filter(marks__gt=0.0)]) + self.marks_obtained = marks + return None + + def update_percent(self): + """Updates the percent gained by the student for this paper.""" + total_marks = self.question_paper.total_marks + if self.marks_obtained is not None: + percent = self.marks_obtained/self.question_paper.total_marks*100 + self.percent = round(percent, 2) + return None + + def update_result(self): + """ + Updates the result. + It is either passed or failed, as per the quiz passing criteria + """ + if self.percent is not None: + if self.percent >= self.question_paper.quiz.pass_criteria: + self.result = "PASSED" + else: + self.result = "FAILED" + return None def get_question_answers(self): """ diff --git a/testapp/exam/tests.py b/testapp/exam/tests.py index b2ba36f..2cc208a 100644 --- a/testapp/exam/tests.py +++ b/testapp/exam/tests.py @@ -21,7 +21,8 @@ def setUpModule(): # create a quiz Quiz.objects.create(start_date='2014-06-16', duration=30, active=False, - description='demo quiz') + description='demo quiz', pass_criteria=40, + language='Python', prerequisite=None) def tearDownModule(): @@ -86,6 +87,9 @@ class QuizTestCases(unittest.TestCase): self.assertEqual(self.quiz.duration, 30) self.assertTrue(self.quiz.active is False) self.assertEqual(self.quiz.description, 'demo quiz') + self.assertEqual(self.quiz.language, 'Python') + self.assertEqual(self.quiz.pass_criteria, 40) + self.assertEqual(self.quiz.prerequisite, None) ############################################################################### @@ -98,7 +102,8 @@ class QuestionPaperTestCases(unittest.TestCase): # create question paper self.question_paper = QuestionPaper.objects.create(quiz=self.quiz, - total_marks=0.0) + total_marks=0.0, shuffle_questions=True) + # add fixed set of questions to the question paper self.question_paper.fixed_questions.add(self.questions[3], self.questions[5]) @@ -135,6 +140,7 @@ class QuestionPaperTestCases(unittest.TestCase): self.assertEqual(self.question_paper.quiz.description, 'demo quiz') self.assertEqual(list(self.question_paper.fixed_questions.all()), [self.questions[3], self.questions[5]]) + self.assertTrue(self.question_paper.shuffle_questions) def test_update_total_marks(self): """ Test update_total_marks() method of Question Paper""" @@ -257,9 +263,20 @@ class AnswerPaperTestCases(unittest.TestCase): answered_question = self.answerpaper.get_answered_str() self.assertEqual(answered_question, '1') - def test_get_marks_obtained(self): + def test_update_marks_obtained(self): """ Test get_marks_obtained() method of Answer Paper""" - self.assertEqual(self.answerpaper.get_marks_obtained(), 1.0) + self.answerpaper.update_marks_obtained() + self.assertEqual(self.answerpaper.marks_obtained, 1.0) + + def test_update_percent(self): + """ Test update_percent() method of Answerpaper""" + self.answerpaper.update_percent() + self.assertEqual(self.answerpaper.percent, 33.33) + + def test_update_result(self): + """ Test update_result() method of AnswerPaper""" + self.answerpaper.update_result() + self.assertEqual(self.answerpaper.result, "FAILED") def test_get_question_answer(self): """ Test get_question_answer() method of Answer Paper""" |