Example #1
0
    def test_to_json_question_no_answer_no_help(self):
        question = Question("My test question")

        encoding = question.to_json()

        self.assertDictEqual(
            dict(question="My test question", answers=[], help=""), encoding)
Example #2
0
    def test_json_encoding_question_answer_help_without_ComplexEncoder(self):
        question = Question("What is this file for?")
        answer = Answer(True, "A test")
        question.add_answer(answer)
        question.add_help("There is no help for you")

        self.assertRaises(TypeError, json.dumps, question.to_json())
Example #3
0
    def test_to_json_question_answer_no_help(self):
        question = Question("Cookie question")
        answer = Mock()
        question.add_answer(answer)

        encoding = question.to_json()

        self.assertDictEqual(
            dict(question="Cookie question", answers=[answer], help=""), encoding)
Example #4
0
    def test_json_encoding_question_no_answer_help(self):
        question = Question("What is this file for?")
        question.add_help("There is no help for you")

        encoding = json.dumps(question.to_json())

        self.assertEqual(
            '{"question": "What is this file for?", "answers": [], "help": "There is no help for you"}',
            encoding
        )
Example #5
0
    def test_json_encoding_question_answer_help_with_ComplexEncoder(self):
        question = Question("What is this file for?")
        answer = Answer(True, "A test")
        question.add_answer(answer)
        question.add_help("There is no help for you")

        encoding = json.dumps(question.to_json(), cls=ComplexEncoder)

        self.assertEqual(
            '{"question": "What is this file for?", "answers": [{"isCorrect": true, "answer": "A test"}], "help": "There is no help for you"}',
            encoding
        )
Example #6
0
    def test_json_encoding_question_multiple_answers_help(self):
        question = Question("What is this file for?")
        a1 = Answer(True, "A test")
        a2 = Answer(False, "A book")
        a3 = Answer(False, "Nothing special")
        question.add_answer(a1)
        question.add_answer(a2)
        question.add_answer(a3)
        question.add_help("There is no help for you.")

        encoding = json.dumps(question.to_json(), cls=ComplexEncoder)

        self.assertEqual(
            '{"question": "What is this file for?", "answers": [{"isCorrect": true, "answer": "A test"}, {"isCorrect": false, "answer": "A book"}, {"isCorrect": false, "answer": "Nothing special"}], "help": "There is no help for you."}',
            encoding
        )