def write_question(form):
    question = Question()
    question.load_from_dict(form)
    if int(form['saved_id']) != -1:
        return question.update_db(QUESTIONS_FILENAME, int(form['saved_id']))
    else:
        return question.write_to_db(QUESTIONS_FILENAME)
Beispiel #2
0
    def test_edit_saved_question(self):
        question = Question()

        data = {
            'questionText': 'Example text',
            'multi': 'false',
            'options': ['yes', 'no'],
            'text': 'false',
            'mandatory': 'false'
        }

        question.load_from_dict(data)

        write_id = question.write_to_db(DATABASE_FILENAME)

        question = None

        question = Question()

        data = {
            'questionNum': write_id,
            'questionText': 'Example other text',
            'multi': 'true',
            'options': ['maybe', 'not'],
            'text': 'false',
            'mandatory': 'true'
        }

        question.load_from_dict(data)
        question.update_db(DATABASE_FILENAME, write_id)

        question = None

        question = Question()

        question.load_from_db(DATABASE_FILENAME, write_id)

        self.assertNotEqual(question.get_question_text(), 'Example text')
        self.assertEqual(question.get_question_text(), 'Example other text')
        self.assertNotEqual(question.get_type(), 'single')
        self.assertEqual(question.get_type(), 'multi')
        self.assertNotEqual(question.get_options(), ['yes', 'no'])
        self.assertEqual(question.get_options(), ['maybe', 'not'])
        self.assertNotEqual(question.get_mandatory(), False)
        self.assertEqual(question.get_mandatory(), True)
def remove_question(id):
    question = Question()
    question.load_from_db(QUESTIONS_FILENAME, id)
    question.turn_invisible()
    question.update_db(QUESTIONS_FILENAME, id)