def test_post_when_console_disabled_fails(self): self.mox.StubOutWithMock(console.ConsoleRequestHandler, 'enable_console') request = webapp2.Request.blank('', POST={'code': 'print 5+5', 'module_name': 'default'}) response = webapp2.Response() handler = console.ConsoleRequestHandler(request, response) handler.enable_console = False admin_request_handler.AdminRequestHandler(handler).post() self.mox.ReplayAll() handler.post() self.mox.VerifyAll() self.assertEqual(404, response.status_int) self.assertIn('The interactive console is currently disabled.', response.body)
def test_post_exception(self): console.ConsoleRequestHandler._modulename_to_shell_module = { 'default': self.interactive_command_module} request = webapp2.Request.blank('', POST={'code': 'print 5+5', 'module_name': 'default'}) response = webapp2.Response() handler = console.ConsoleRequestHandler(request, response) handler.dispatcher = self.dispatcher self.interactive_command_module.send_interactive_command( 'print 5+5').AndRaise(module.InteractiveCommandError('restart')) self.mox.ReplayAll() handler.post() self.mox.VerifyAll() self.assertEqual(200, response.status_int) self.assertEqual('restart', response.body)
def test_post_new_module(self): request = webapp2.Request.blank('', POST={'code': 'print 5+5', 'module_name': 'default'}) response = webapp2.Response() handler = console.ConsoleRequestHandler(request, response) handler.dispatcher = self.dispatcher handler.dispatcher.get_module_by_name('default').AndReturn(self.module) self.module.create_interactive_command_module().AndReturn( self.interactive_command_module) self.interactive_command_module.send_interactive_command( 'print 5+5').AndReturn('10\n') self.mox.ReplayAll() handler.post() self.mox.VerifyAll() self.assertEqual(200, response.status_int) self.assertEqual('10\n', response.body)
def test_post_cached_server(self): console.ConsoleRequestHandler._servername_to_shell_server = { 'default': self.interactive_command_server} request = webapp2.Request.blank('', POST={'code': 'print 5+5', 'server_name': 'default'}) response = webapp2.Response() handler = console.ConsoleRequestHandler(request, response) handler.dispatcher = self.dispatcher self.interactive_command_server.send_interactive_command( 'print 5+5').AndReturn('10\n') self.mox.ReplayAll() handler.post() self.mox.VerifyAll() self.assertEqual(200, response.status_int) self.assertEqual('10\n', response.body)
def test_post_cached_module(self): self.mox.StubOutWithMock(console.ConsoleRequestHandler, 'enable_console') console.ConsoleRequestHandler._modulename_to_shell_module = { 'default': self.interactive_command_module} request = webapp2.Request.blank('', POST={'code': 'print 5+5', 'module_name': 'default'}) response = webapp2.Response() handler = console.ConsoleRequestHandler(request, response) handler.enable_console = True admin_request_handler.AdminRequestHandler(handler).post() handler.dispatcher = self.dispatcher self.interactive_command_module.send_interactive_command( 'print 5+5').AndReturn('10\n') self.mox.ReplayAll() handler.post() self.mox.VerifyAll() self.assertEqual(200, response.status_int) self.assertEqual('10\n', response.body)