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')
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 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')
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')
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(), [])