示例#1
0
    def test_create_question(self):

        question = Question()

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

        question.load_from_dict(data)

        write_id = question.write_to_db(DATABASE_FILENAME)

        question = None

        question = Question()
        question.load_from_db(DATABASE_FILENAME, write_id)

        self.assertEqual(question.get_id(), write_id)
        self.assertEqual(question.get_question_text(), 'Example text')
        self.assertEqual(question.get_type(), 'single')
        self.assertEqual(question.get_mandatory(), True)
        self.assertEqual(question.get_options()[0], 'yes')
示例#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)
示例#3
0
    def test_edit_question_type(self):
        question = Question()

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

        question.load_from_dict(data)

        self.assertEqual(question.get_type(), 'single')
        question.toggle_multi()
        self.assertEqual(question.get_type(), 'multi')
        question.toggle_multi()
        self.assertEqual(question.get_type(), 'single')
示例#4
0
    def test_values_read_from_dictionary(self):

        question = Question()

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

        question.load_from_dict(data)

        self.assertEqual(question.get_id(), 20)
        self.assertEqual(question.get_question_text(), 'Example text')
        self.assertEqual(question.get_type(), 'single')
        self.assertEqual(question.get_mandatory(), True)
        self.assertEqual(question.get_options()[0], 'yes')
示例#5
0
    def test_create_text_question_no_options(self):
        question = Question()

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

        question.load_from_dict(data)

        write_id = question.write_to_db(DATABASE_FILENAME)

        question = None

        question = Question()
        question.load_from_db(DATABASE_FILENAME, write_id)

        self.assertEqual(question.get_type(), 'text')
        self.assertEqual(question.get_options(), [])