class TestXModuleHandler(TestCase): """ Tests that the xmodule_handler function correctly wraps handle_ajax """ def setUp(self): self.module = XModule(descriptor=Mock(), field_data=Mock(), runtime=Mock(), scope_ids=Mock()) self.module.handle_ajax = Mock(return_value='{}') self.request = webob.Request({}) def test_xmodule_handler_passed_data(self): self.module.xmodule_handler(self.request) self.module.handle_ajax.assert_called_with(None, self.request.POST) def test_xmodule_handler_dispatch(self): self.module.xmodule_handler(self.request, 'dispatch') self.module.handle_ajax.assert_called_with('dispatch', self.request.POST) def test_xmodule_handler_return_value(self): response = self.module.xmodule_handler(self.request) self.assertIsInstance(response, webob.Response) self.assertEqual(response.body, '{}')
class TestXModuleHandler(TestCase): """ Tests that the xmodule_handler function correctly wraps handle_ajax """ def setUp(self): self.module = XModule(descriptor=Mock(), field_data=Mock(), runtime=Mock(), scope_ids=Mock()) self.module.handle_ajax = Mock(return_value='{}') self.request = webob.Request({}) def test_xmodule_handler_passed_data(self): self.module.xmodule_handler(self.request) self.module.handle_ajax.assert_called_with(None, self.request.POST) def test_xmodule_handler_dispatch(self): self.module.xmodule_handler(self.request, 'dispatch') self.module.handle_ajax.assert_called_with('dispatch', self.request.POST) def test_xmodule_handler_return_value(self): response = self.module.xmodule_handler(self.request) self.assertIsInstance(response, webob.Response) self.assertEqual(response.body, '{}')
class TestXModuleHandler(TestCase): """ Tests that the xmodule_handler function correctly wraps handle_ajax """ def setUp(self): super(TestXModuleHandler, self).setUp() self.module = XModule(descriptor=Mock(), field_data=Mock(), runtime=Mock(), scope_ids=Mock()) self.module.handle_ajax = Mock(return_value='{}') self.request = webob.Request({}) def test_xmodule_handler_passed_data(self): self.module.xmodule_handler(self.request) self.module.handle_ajax.assert_called_with( None, MultiDict(self.request.POST)) def test_xmodule_handler_dispatch(self): self.module.xmodule_handler(self.request, 'dispatch') self.module.handle_ajax.assert_called_with( 'dispatch', MultiDict(self.request.POST)) def test_xmodule_handler_return_value(self): response = self.module.xmodule_handler(self.request) self.assertIsInstance(response, webob.Response) self.assertEqual(response.body.decode('utf-8'), '{}') @ddt.data( u'{"test_key": "test_value"}', '{"test_key": "test_value"}', ) def test_xmodule_handler_with_data(self, response_data): """ Tests that xmodule_handler function correctly wraps handle_ajax when handle_ajax response is either str or unicode. """ self.module.handle_ajax = Mock(return_value=response_data) response = self.module.xmodule_handler(self.request) self.assertIsInstance(response, webob.Response) self.assertEqual(response.body.decode('utf-8'), '{"test_key": "test_value"}')
class TestXModuleHandler(TestCase): """ Tests that the xmodule_handler function correctly wraps handle_ajax """ shard = 1 def setUp(self): super(TestXModuleHandler, self).setUp() self.module = XModule(descriptor=Mock(), field_data=Mock(), runtime=Mock(), scope_ids=Mock()) self.module.handle_ajax = Mock(return_value='{}') self.request = webob.Request({}) def test_xmodule_handler_passed_data(self): self.module.xmodule_handler(self.request) self.module.handle_ajax.assert_called_with(None, self.request.POST) def test_xmodule_handler_dispatch(self): self.module.xmodule_handler(self.request, 'dispatch') self.module.handle_ajax.assert_called_with('dispatch', self.request.POST) def test_xmodule_handler_return_value(self): response = self.module.xmodule_handler(self.request) self.assertIsInstance(response, webob.Response) self.assertEqual(response.body, '{}') @ddt.data( u'{"test_key": "test_value"}', '{"test_key": "test_value"}', ) def test_xmodule_handler_with_data(self, response_data): """ Tests that xmodule_handler function correctly wraps handle_ajax when handle_ajax response is either str or unicode. """ self.module.handle_ajax = Mock(return_value=response_data) response = self.module.xmodule_handler(self.request) self.assertIsInstance(response, webob.Response) self.assertEqual(response.body, '{"test_key": "test_value"}')