Example #1
0
    def test_output(self, json, header):
        """
        Test json encoding.
        """
        data = {'test': 1234}
        json.dumps.return_value = repr(data)
        header.side_effect = ['h1', 'h2']

        # test
        controller = JSONController()
        encoded = controller._output(data)

        # validation
        json.dumps.assert_called_once_with(data, default=json_encoder)
        self.assertEqual(encoded, json.dumps.return_value)
        self.assertEqual(header.call_args_list, [
            (('Content-Type', 'application/json'), {}),
            (('Content-Length', len(encoded)), {}),
        ])