Esempio n. 1
0
    def test_JsonRendererFactory(self, mock_trigger):
        mock_trigger.side_effect = lambda x, y: x
        request = mock.MagicMock()
        request.response.default_content_type = 'text/html'
        request.response.content_type = 'text/html'
        request.url = 'http://'
        view = mock.Mock()
        view._json_encoder = None

        factory = renderers.JsonRendererFactory({
            'name': 'json',
            'package': None,
            'registry': None
        })

        result = json.loads(
            factory(self._get_dummy_result(), {
                'request': request,
                'view': view,
                'context': 1
            }))
        self.assertDictContainsSubset(self._get_dummy_expected(), result)
        self.assertEqual('application/json', request.response.content_type)
        mock_trigger.assert_called_once_with(self._get_dummy_result(), {
            'request': request,
            'context': 1,
            'view': view
        })
Esempio n. 2
0
    def test_JsonRendererFactory_run_after_calls(self, mock_wrap):
        factory = renderers.JsonRendererFactory({
            'name': 'json',
            'package': None,
            'registry': None
        })
        request = mock.Mock(action='create')
        factory.run_after_calls(1, {'request': request})
        assert not mock_wrap.wrap_in_dict.called

        request = mock.Mock(action='show')
        factory.run_after_calls(1, {'request': request})
        mock_wrap.wrap_in_dict.assert_called_once_with(request)
        mock_wrap.wrap_in_dict().assert_called_once_with(result=1)
Esempio n. 3
0
    def test_JsonRendererFactory_trigger_events(self, mock_trigger):
        request = mock.MagicMock()
        request.response.default_content_type = 'text/html'
        request.response.content_type = 'text/html'
        request.url = 'http://'
        view = mock.Mock()
        view._json_encoder = None

        factory = renderers.JsonRendererFactory({
            'name': 'json',
            'package': None,
            'registry': None
        })

        result = factory._trigger_events(self._get_dummy_result(), {
            'request': request,
            'view': view,
            'context': 1
        })
        view.assert_called_once_with(1, request)
        mock_trigger.assert_called_once_with(view())
        assert result == mock_trigger().response