def load_questions_xml(filename):
    """Load questions from the given XML file."""
    q_bank = parse(filename).getElementsByTagName("question")

    for question in q_bank:

        summary_node = question.getElementsByTagName("summary")[0]
        summary = (summary_node.childNodes[0].data).strip()

        desc_node = question.getElementsByTagName("description")[0]
        description = (desc_node.childNodes[0].data).strip()

        type_node = question.getElementsByTagName("type")[0]
        type = (type_node.childNodes[0].data).strip()

        points_node = question.getElementsByTagName("points")[0]
        points = float((points_node.childNodes[0].data).strip()) \
                 if points_node else 1.0

        test_node = question.getElementsByTagName("test")[0]
        test = decode_html((test_node.childNodes[0].data).strip())

        opt_node = question.getElementsByTagName("options")[0]
        opt = decode_html((opt_node.childNodes[0].data).strip())

        new_question = Question(summary=summary,
                                description=description,
                                points=points,
                                options=opt,
                                type=type,
                                test=test)
        new_question.save()
def load_questions_xml(filename):
    """Load questions from the given XML file."""
    q_bank = parse(filename).getElementsByTagName("entry")

    for questions in q_bank:

        question_node = questions.getElementsByTagName("question")[0]
        question = (question_node.childNodes[0].data).strip()

        desc_node = questions.getElementsByTagName("description")[0]
        description = (desc_node.childNodes[0].data).strip()

        points_node = questions.getElementsByTagName("points")[0]
        points = float((points_node.childNodes[0].data).strip()) \
                 if points_node else 1.0

	neg_points_node = questions.getElementsByTagName("neg_points")[0]
        neg_points = float((neg_points_node.childNodes[0].data).strip())\
                 if neg_points_node else 0.25

        right_response_node = questions.getElementsByTagName("right_response")[0]
        right_response = decode_html((right_response_node.childNodes[0].data).strip())

        opt_node = questions.getElementsByTagName("options")[0]
        opt = decode_html((opt_node.childNodes[0].data).strip())

        new_question = Question(question=question,
                                description=description,
                                points=points,
				neg_points=neg_points,
                                options=opt,
                                right_response=right_response)
        new_question.save()
Exemple #3
0
class QuestionTestCases(unittest.TestCase):
    def setUp(self):
        # Single question details
        self.question = Question(summary='Demo question', language='Python',
                                 type='Code', active=True,
                                 description='Write a function', points=1.0,
                                 test='Test Cases', snippet='def myfunc()')
        self.question.save()
        self.question.tags.add('python', 'function')

    def test_question(self):
        """ Test question """
        self.assertEqual(self.question.summary, 'Demo question')
        self.assertEqual(self.question.language, 'Python')
        self.assertEqual(self.question.type, 'Code')
        self.assertFalse(self.question.options)
        self.assertEqual(self.question.description, 'Write a function')
        self.assertEqual(self.question.points, 1.0)
        self.assertTrue(self.question.active)
        self.assertEqual(self.question.test, 'Test Cases')
        self.assertEqual(self.question.snippet, 'def myfunc()')
        tag_list = []
        for tag in self.question.tags.all():
                    tag_list.append(tag.name)
        self.assertEqual(tag_list, ['python', 'function'])
Exemple #4
0
 def setUp(self):
     # Single question details
     self.question = Question(summary='Demo question', language='Python',
                              type='Code', active=True,
                              description='Write a function', points=1.0,
                              test='Test Cases', snippet='def myfunc()')
     self.question.save()
     self.question.tags.add('python', 'function')
Exemple #5
0
    def save(self):
        summary = self.cleaned_data["summary"]
        description = self.cleaned_data["description"]
        points = self.cleaned_data['points']
        test = self.cleaned_data["test"]
        options = self.cleaned_data['options']
        language = self.cleaned_data['language']
        type = self.cleaned_data["type"]
        active = self.cleaned_data["active"]
        snippet = self.cleaned_data["snippet"]

        new_question = Question()
        new_question.summary = summary
        new_question.description = description
        new_question.points = points
        new_question.test = test
        new_question.options = options
        new_question.language = language
        new_question.type = type
        new_question.active = active
        new_question.snippet = snippet
        new_question.save()