Python mox.IgnoreArg() Examples

The following are 30 code examples of mox.IgnoreArg(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module mox , or try the search function .
Example #1
Source File: module_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_handle_script_request(self):
    self.auto_module._choose_instance(0.1).AndReturn(self.inst)
    self.inst.handle(self.environ,
                     self.start_response,
                     self.url_map,
                     self.match,
                     self.request_id,
                     instance.NORMAL_REQUEST).AndReturn(self.response)

    self.mox.ReplayAll()
    self.assertEqual(
        self.response,
        self.auto_module._handle_script_request(self.environ,
                                                self.start_response,
                                                self.url_map,
                                                self.match,
                                                self.request_id))
    self.mox.VerifyAll()
    self.assertEqual([(mox.IgnoreArg(), 1)],
                     list(self.auto_module._outstanding_request_history)) 
Example #2
Source File: certs_test.py    From macops with Apache License 2.0 6 votes vote down vote up
def testInstallCertInKeychainPrivateFailNoPassNoApp(self):
    """Test InstallCertInKeychain private key failure, no pass or app."""
    self.StubSetup()
    certs.tempfile.mkdtemp(prefix=mox.IgnoreArg()).AndReturn('tempdir')
    mock_file = self.mox.CreateMockAnything()
    open('tempdir/private.key', 'w').AndReturn(mock_file)
    mock_file.write('key').AndReturn(None)
    mock_file.close().AndReturn(None)
    certs.logging.info('Installing downloaded key into the %s keychain',
                       'k').AndReturn(None)
    command = [certs.CMD_SECURITY, 'import', 'tempdir/private.key', '-x',
               '-k', 'k', '-A']
    certs.logging.debug('Command: %s', command).AndReturn(None)
    certs.gmacpyutil.RunProcess(command,
                                sudo=False,
                                sudo_password=None).AndReturn(('out', 'err', 1))
    certs.logging.debug('Private key installation output: %s',
                        'out').AndReturn(None)
    certs.shutil.rmtree('tempdir').AndReturn(None)

    self.mox.ReplayAll()
    self.assertRaises(certs.KeychainError, certs.InstallCertInKeychain, 'cert',
                      'key', keychain='k')
    self.mox.VerifyAll() 
Example #3
Source File: server_test.py    From browserscope with Apache License 2.0 6 votes vote down vote up
def test_warmup(self):
    s = AutoScalingServerFacade(balanced_port=8080)
    self.mox.StubOutWithMock(s, '_handle_request')
    self.mox.StubOutWithMock(s._condition, 'notify')

    inst = self.mox.CreateMock(instance.Instance)

    environ = object()
    s.build_request_environ('GET', '/_ah/warmup', [], '', '0.1.0.3', 8080,
                            fake_login=True).AndReturn(environ)
    s._handle_request(environ,
                      mox.IgnoreArg(),
                      inst=inst,
                      request_type=instance.READY_REQUEST)
    s._condition.notify(1)

    self.mox.ReplayAll()
    s._warmup(inst)
    self.mox.VerifyAll() 
Example #4
Source File: server_test.py    From browserscope with Apache License 2.0 6 votes vote down vote up
def test_handle_cannot_accept_request(self):
    self.auto_server._choose_instance(0.1).AndReturn(self.inst)
    self.auto_server._choose_instance(0.1).AndReturn(self.inst)
    self.inst.handle(
        self.environ, self.start_response, self.url_map, self.match,
        self.request_id, instance.NORMAL_REQUEST).AndRaise(
            instance.CannotAcceptRequests)
    self.inst.handle(
        self.environ, self.start_response, self.url_map, self.match,
        self.request_id, instance.NORMAL_REQUEST).AndReturn(
            self.response)

    self.mox.ReplayAll()
    self.assertEqual(
        self.response,
        self.auto_server._handle_script_request(self.environ,
                                                self.start_response,
                                                self.url_map,
                                                self.match,
                                                self.request_id))
    self.mox.VerifyAll()
    self.assertEqual([(mox.IgnoreArg(), 1)],
                     list(self.auto_server._outstanding_request_history)) 
Example #5
Source File: server_test.py    From browserscope with Apache License 2.0 6 votes vote down vote up
def test_instance_start_success(self):
    s = ManualScalingServerFacade(balanced_port=8080)
    self.mox.StubOutWithMock(s, '_handle_request')
    self.mox.StubOutWithMock(s._condition, 'notify')

    wsgi_servr = self.mox.CreateMock(wsgi_server.WsgiServer)
    wsgi_servr.port = 12345
    inst = self.mox.CreateMock(instance.Instance)
    inst.instance_id = 0
    inst.start().AndReturn(True)

    environ = object()
    s.build_request_environ('GET', '/_ah/start', [], '', '0.1.0.3', 12345,
                            fake_login=True).AndReturn(environ)
    s._handle_request(environ,
                      mox.IgnoreArg(),
                      inst=inst,
                      request_type=instance.READY_REQUEST)
    s._condition.notify(1)

    self.mox.ReplayAll()
    s._start_instance(wsgi_servr, inst)
    self.mox.VerifyAll() 
Example #6
Source File: server_test.py    From browserscope with Apache License 2.0 6 votes vote down vote up
def test_instance_start_success(self):
    s = BasicScalingServerFacade(balanced_port=8080)
    self.mox.StubOutWithMock(s, '_handle_request')
    self.mox.StubOutWithMock(s._condition, 'notify')

    wsgi_servr = self.mox.CreateMock(wsgi_server.WsgiServer)
    wsgi_servr.port = 12345
    s._wsgi_servers[0] = wsgi_servr
    inst = self.mox.CreateMock(instance.Instance)
    inst.instance_id = 0
    s._instances[0] = inst
    inst.start().AndReturn(True)

    environ = object()
    s.build_request_environ('GET', '/_ah/start', [], '', '0.1.0.3', 12345,
                            fake_login=True).AndReturn(environ)
    s._handle_request(environ,
                      mox.IgnoreArg(),
                      inst=inst,
                      request_type=instance.READY_REQUEST)
    s._condition.notify(1)

    self.mox.ReplayAll()
    s._start_instance(0)
    self.mox.VerifyAll() 
Example #7
Source File: server_test.py    From browserscope with Apache License 2.0 6 votes vote down vote up
def test_send_interactive_command(self):
    def good_response(unused_environ, start_response, request_type):
      start_response('200 OK', [])
      return ['10\n']

    environ = object()
    self.servr.build_request_environ(
        'POST', '/', [], 'print 5+5', '192.0.2.0', 8000).AndReturn(environ)
    self.servr._handle_request(
        environ,
        mox.IgnoreArg(),
        request_type=instance.INTERACTIVE_REQUEST).WithSideEffects(
            good_response)

    self.mox.ReplayAll()
    self.assertEqual('10\n', self.servr.send_interactive_command('print 5+5'))
    self.mox.VerifyAll() 
Example #8
Source File: server_test.py    From browserscope with Apache License 2.0 6 votes vote down vote up
def test_handle_script_request(self):
    self.servr._instance_factory.new_instance(
        mox.IgnoreArg(),
        expect_ready_request=False).AndReturn(self.inst)
    self.inst.start()
    self.inst.handle(self.environ,
                     self.start_response,
                     self.url_map,
                     self.match,
                     self.request_id,
                     instance.INTERACTIVE_REQUEST).AndReturn(['10\n'])

    self.mox.ReplayAll()
    self.assertEqual(
        ['10\n'],
        self.servr._handle_script_request(self.environ,
                                          self.start_response,
                                          self.url_map,
                                          self.match,
                                          self.request_id))
    self.mox.VerifyAll() 
Example #9
Source File: server_test.py    From browserscope with Apache License 2.0 6 votes vote down vote up
def test_handle_script_request_unexpected_instance_exception(self):
    self.servr._instance_factory.new_instance(
        mox.IgnoreArg(),
        expect_ready_request=False).AndReturn(self.inst)
    self.inst.start()
    self.inst.handle(
        self.environ,
        self.start_response,
        self.url_map,
        self.match,
        self.request_id,
        instance.INTERACTIVE_REQUEST).AndRaise(httplib.BadStatusLine('line'))

    self.mox.ReplayAll()
    self.assertRaises(
        httplib.BadStatusLine,
        self.servr._handle_script_request,
        self.environ,
        self.start_response,
        self.url_map,
        self.match,
        self.request_id)
    self.mox.VerifyAll() 
Example #10
Source File: dispatcher_test.py    From browserscope with Apache License 2.0 6 votes vote down vote up
def test_add_async_request(self):
    dummy_environ = object()
    self.mox.StubOutWithMock(dispatcher._THREAD_POOL, 'submit')
    self.dispatcher._server_name_to_server['default'].build_request_environ(
        'PUT', '/foo?bar=baz', [('Header', 'Value'), ('Other', 'Values')],
        'body', '1.2.3.4', 1).AndReturn(
            dummy_environ)
    dispatcher._THREAD_POOL.submit(
        self.dispatcher._handle_request, dummy_environ, mox.IgnoreArg(),
        self.dispatcher._server_name_to_server['default'],
        None, catch_and_log_exceptions=True)
    self.mox.ReplayAll()
    self.dispatcher.add_async_request(
        'PUT', '/foo?bar=baz', [('Header', 'Value'), ('Other', 'Values')],
        'body', '1.2.3.4')
    self.mox.VerifyAll() 
Example #11
Source File: dispatcher_test.py    From browserscope with Apache License 2.0 6 votes vote down vote up
def test_add_request(self):
    dummy_environ = object()
    self.mox.StubOutWithMock(self.dispatcher, '_resolve_target')
    self.mox.StubOutWithMock(self.dispatcher, '_handle_request')
    self.dispatcher._resolve_target(None, '/foo').AndReturn(
        (self.dispatcher._server_name_to_server['default'], None))
    self.dispatcher._server_name_to_server['default'].build_request_environ(
        'PUT', '/foo?bar=baz', [('Header', 'Value'), ('Other', 'Values')],
        'body', '1.2.3.4', 1, fake_login=True).AndReturn(
            dummy_environ)
    self.dispatcher._handle_request(
        dummy_environ, mox.IgnoreArg(),
        self.dispatcher._server_name_to_server['default'],
        None).AndReturn(['Hello World'])
    self.mox.ReplayAll()
    response = self.dispatcher.add_request(
        'PUT', '/foo?bar=baz', [('Header', 'Value'), ('Other', 'Values')],
        'body', '1.2.3.4', fake_login=True)
    self.mox.VerifyAll()
    self.assertEqual('Hello World', response.content) 
Example #12
Source File: static_files_handler_test.py    From browserscope with Apache License 2.0 6 votes vote down vote up
def test_patterned_path(self):
    url_map = appinfo.URLMap(url=r'/(.*)/(.*)',
                             static_files=r'static/\1/subdir/\2')
    h = static_files_handler.StaticFilesHandler(root_path='/appdir',
                                                url_map=url_map)
    match = h.match('/hello/foo.jpg')
    self.assertTrue(match)
    self.assertFalse(h.match('/'))

    static_files_handler.StaticContentHandler._handle_path(
        os.path.join('/appdir', 'static/hello/subdir/foo.jpg'),
        {},
        mox.IgnoreArg()).AndReturn('<output>')
    self.mox.ReplayAll()
    self.assertEqual('<output>',
                     h.handle(match, {}, None))
    self.mox.VerifyAll() 
Example #13
Source File: static_files_handler_test.py    From browserscope with Apache License 2.0 6 votes vote down vote up
def test_simple_path(self):
    url_map = appinfo.URLMap(url='/foo',
                             static_dir='subdir')
    h = static_files_handler.StaticDirHandler(root_path='/appdir',
                                              url_map=url_map)
    match = h.match('/foo/bar.jpg')
    self.assertTrue(match)
    self.assertFalse(h.match('/baz'))

    static_files_handler.StaticContentHandler._handle_path(
        os.path.join('/appdir', 'subdir', 'bar.jpg'),
        {},
        mox.IgnoreArg()).AndReturn('<output>')
    self.mox.ReplayAll()
    self.assertEqual('<output>',
                     h.handle(match, {}, None))
    self.mox.VerifyAll() 
Example #14
Source File: aurora.py    From aurproxy with Apache License 2.0 6 votes vote down vote up
def getMockServerSet(smox):
  listeners = []
  def add_listener(listener):
    listeners.append(listener)

  zk = smox.CreateMock(KazooClient)
  zk.connected = True
  zk.handler = SequentialGeventHandler()
  zk.retry = KazooRetry()

  mock_stat = smox.CreateMock(ZnodeStat)
  mock_stat.mzxid = 1

  zk.exists(TEST_PATH).AndReturn(True)
  zk.add_listener(mox.IgnoreArg()).WithSideEffects(add_listener)
  zk.get(TEST_PATH, mox.IgnoreArg()).AndReturn((1, mock_stat))
  zk.add_listener(mox.IgnoreArg()).WithSideEffects(add_listener)

  return zk 
Example #15
Source File: module_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_warmup(self):
    s = AutoScalingModuleFacade(balanced_port=8080)
    self.mox.StubOutWithMock(s, '_handle_request')
    self.mox.StubOutWithMock(s._condition, 'notify')

    inst = self.mox.CreateMock(instance.Instance)

    environ = object()
    s.build_request_environ('GET', '/_ah/warmup', [], '', '0.1.0.3', 8080,
                            fake_login=True).AndReturn(environ)
    s._handle_request(environ,
                      mox.IgnoreArg(),
                      inst=inst,
                      request_type=instance.READY_REQUEST)
    s._condition.notify(1)

    self.mox.ReplayAll()
    s._warmup(inst)
    self.mox.VerifyAll() 
Example #16
Source File: static_files_handler_test.py    From browserscope with Apache License 2.0 6 votes vote down vote up
def test_simple_path(self):
    url_map = appinfo.URLMap(url='/',
                             static_files='index.html')
    h = static_files_handler.StaticFilesHandler(root_path='/appdir',
                                                url_map=url_map)
    match = h.match('/')
    self.assertTrue(match)
    self.assertFalse(h.match('/other'))

    static_files_handler.StaticContentHandler._handle_path(
        os.path.join('/appdir', 'index.html'),
        {},
        mox.IgnoreArg()).AndReturn('<output>')
    self.mox.ReplayAll()
    self.assertEqual('<output>',
                     h.handle(match, {}, None))
    self.mox.VerifyAll() 
Example #17
Source File: module_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_handle_cannot_accept_request(self):
    self.auto_module._choose_instance(0.1).AndReturn(self.inst)
    self.auto_module._choose_instance(0.1).AndReturn(self.inst)
    self.inst.handle(
        self.environ, self.start_response, self.url_map, self.match,
        self.request_id, instance.NORMAL_REQUEST).AndRaise(
            instance.CannotAcceptRequests)
    self.inst.handle(
        self.environ, self.start_response, self.url_map, self.match,
        self.request_id, instance.NORMAL_REQUEST).AndReturn(
            self.response)

    self.mox.ReplayAll()
    self.assertEqual(
        self.response,
        self.auto_module._handle_script_request(self.environ,
                                                self.start_response,
                                                self.url_map,
                                                self.match,
                                                self.request_id))
    self.mox.VerifyAll()
    self.assertEqual([(mox.IgnoreArg(), 1)],
                     list(self.auto_module._outstanding_request_history)) 
Example #18
Source File: module_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_instance_start_success(self):
    s = ManualScalingModuleFacade(balanced_port=8080)
    self.mox.StubOutWithMock(s, '_handle_request')
    self.mox.StubOutWithMock(s._condition, 'notify')

    wsgi_servr = self.mox.CreateMock(wsgi_server.WsgiServer)
    wsgi_servr.port = 12345
    inst = self.mox.CreateMock(instance.Instance)
    inst.instance_id = 0
    inst.start().AndReturn(True)

    environ = object()
    s.build_request_environ('GET', '/_ah/start', [], '', '0.1.0.3', 12345,
                            fake_login=True).AndReturn(environ)
    s._handle_request(environ,
                      mox.IgnoreArg(),
                      inst=inst,
                      request_type=instance.READY_REQUEST)
    s._condition.notify(1)

    self.mox.ReplayAll()
    s._start_instance(wsgi_servr, inst)
    self.mox.VerifyAll() 
Example #19
Source File: module_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_handle_timeout(self):
    self.time = 0.0

    def advance_time(*unused_args):
      self.time += 11

    self.mox.stubs.Set(time, 'time', lambda: self.time)
    self.mox.StubOutWithMock(self.manual_module, '_error_response')

    self.manual_module._choose_instance(10.0).WithSideEffects(advance_time)
    self.manual_module._error_response(
        self.environ, self.start_response, 503, mox.IgnoreArg()).AndReturn(
            self.response)
    self.mox.ReplayAll()
    self.assertEqual(
        self.response,
        self.manual_module._handle_script_request(self.environ,
                                                  self.start_response,
                                                  self.url_map,
                                                  self.match,
                                                  self.request_id))
    self.mox.VerifyAll() 
Example #20
Source File: module_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_handle_timeout(self):
    self.mox.StubOutWithMock(self.basic_module, '_error_response')

    self.basic_module._choose_instance(20).WithSideEffects(self.advance_time)
    self.basic_module._error_response(
        self.environ, self.start_response, 503, mox.IgnoreArg()).AndReturn(
            self.response)

    self.mox.ReplayAll()
    self.assertEqual(
        self.response,
        self.basic_module._handle_script_request(self.environ,
                                                 self.start_response,
                                                 self.url_map,
                                                 self.match,
                                                 self.request_id))
    self.mox.VerifyAll() 
Example #21
Source File: module_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_send_interactive_command(self):
    def good_response(unused_environ, start_response, request_type):
      start_response('200 OK', [])
      return ['10\n']

    environ = object()
    self.servr.build_request_environ(
        'POST', '/', [], 'print 5+5', '192.0.2.0', 8000).AndReturn(environ)
    self.servr._handle_request(
        environ,
        mox.IgnoreArg(),
        request_type=instance.INTERACTIVE_REQUEST).WithSideEffects(
            good_response)

    self.mox.ReplayAll()
    self.assertEqual('10\n', self.servr.send_interactive_command('print 5+5'))
    self.mox.VerifyAll() 
Example #22
Source File: module_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_send_interactive_command_handle_request_failure(self):
    def good_response(unused_environ, start_response, request_type):
      start_response('503 Service Unavailable', [])
      return ['Instance was restarted while executing command']

    environ = object()
    self.servr.build_request_environ(
        'POST', '/', [], 'print 5+5', '192.0.2.0', 8000).AndReturn(environ)
    self.servr._handle_request(
        environ,
        mox.IgnoreArg(),
        request_type=instance.INTERACTIVE_REQUEST).WithSideEffects(
            good_response)

    self.mox.ReplayAll()
    self.assertRaisesRegexp(module.InteractiveCommandError,
                            'Instance was restarted while executing command',
                            self.servr.send_interactive_command,
                            'print 5+5')
    self.mox.VerifyAll() 
Example #23
Source File: module_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_handle_script_request(self):
    self.servr._instance_factory.new_instance(
        mox.IgnoreArg(),
        expect_ready_request=False).AndReturn(self.inst)
    self.inst.start()
    self.inst.handle(self.environ,
                     self.start_response,
                     self.url_map,
                     self.match,
                     self.request_id,
                     instance.INTERACTIVE_REQUEST).AndReturn(['10\n'])

    self.mox.ReplayAll()
    self.assertEqual(
        ['10\n'],
        self.servr._handle_script_request(self.environ,
                                          self.start_response,
                                          self.url_map,
                                          self.match,
                                          self.request_id))
    self.mox.VerifyAll() 
Example #24
Source File: module_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_handle_script_request_unexpected_instance_exception(self):
    self.servr._instance_factory.new_instance(
        mox.IgnoreArg(),
        expect_ready_request=False).AndReturn(self.inst)
    self.inst.start()
    self.inst.handle(
        self.environ,
        self.start_response,
        self.url_map,
        self.match,
        self.request_id,
        instance.INTERACTIVE_REQUEST).AndRaise(httplib.BadStatusLine('line'))

    self.mox.ReplayAll()
    self.assertRaises(
        httplib.BadStatusLine,
        self.servr._handle_script_request,
        self.environ,
        self.start_response,
        self.url_map,
        self.match,
        self.request_id)
    self.mox.VerifyAll() 
Example #25
Source File: dispatcher_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_add_async_request(self):
    dummy_environ = object()
    self.mox.StubOutWithMock(dispatcher._THREAD_POOL, 'submit')
    self.dispatcher._module_name_to_module['default'].build_request_environ(
        'PUT', '/foo?bar=baz', [('Header', 'Value'), ('Other', 'Values')],
        'body', '1.2.3.4', 1).AndReturn(
            dummy_environ)
    dispatcher._THREAD_POOL.submit(
        self.dispatcher._handle_request, dummy_environ, mox.IgnoreArg(),
        self.dispatcher._module_name_to_module['default'],
        None, catch_and_log_exceptions=True)
    self.mox.ReplayAll()
    self.dispatcher.add_async_request(
        'PUT', '/foo?bar=baz', [('Header', 'Value'), ('Other', 'Values')],
        'body', '1.2.3.4')
    self.mox.VerifyAll() 
Example #26
Source File: dispatcher_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_add_async_request_specific_module(self):
    dummy_environ = object()
    self.mox.StubOutWithMock(dispatcher._THREAD_POOL, 'submit')
    self.dispatcher._module_name_to_module['other'].build_request_environ(
        'PUT', '/foo?bar=baz', [('Header', 'Value'), ('Other', 'Values')],
        'body', '1.2.3.4', 2).AndReturn(
            dummy_environ)
    dispatcher._THREAD_POOL.submit(
        self.dispatcher._handle_request, dummy_environ, mox.IgnoreArg(),
        self.dispatcher._module_name_to_module['other'],
        None, catch_and_log_exceptions=True)
    self.mox.ReplayAll()
    self.dispatcher.add_async_request(
        'PUT', '/foo?bar=baz', [('Header', 'Value'), ('Other', 'Values')],
        'body', '1.2.3.4', module_name='other')
    self.mox.VerifyAll() 
Example #27
Source File: dispatcher_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_add_async_request_soft_routing(self):
    """Tests add_async_request with soft routing."""
    dummy_environ = object()
    self.mox.StubOutWithMock(dispatcher._THREAD_POOL, 'submit')
    self.dispatcher._module_name_to_module['default'].build_request_environ(
        'PUT', '/foo?bar=baz', [('Header', 'Value'), ('Other', 'Values')],
        'body', '1.2.3.4', 1).AndReturn(
            dummy_environ)
    dispatcher._THREAD_POOL.submit(
        self.dispatcher._handle_request, dummy_environ, mox.IgnoreArg(),
        self.dispatcher._module_name_to_module['default'],
        None, catch_and_log_exceptions=True)
    self.mox.ReplayAll()
    self.dispatcher.add_async_request(
        'PUT', '/foo?bar=baz', [('Header', 'Value'), ('Other', 'Values')],
        'body', '1.2.3.4', module_name='nomodule')
    self.mox.VerifyAll() 
Example #28
Source File: dispatcher_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_add_request(self):
    dummy_environ = object()
    self.mox.StubOutWithMock(self.dispatcher, '_resolve_target')
    self.mox.StubOutWithMock(self.dispatcher, '_handle_request')
    self.dispatcher._resolve_target(None, '/foo').AndReturn(
        (self.dispatcher._module_name_to_module['default'], None))
    self.dispatcher._module_name_to_module['default'].build_request_environ(
        'PUT', '/foo?bar=baz', [('Header', 'Value'), ('Other', 'Values')],
        'body', '1.2.3.4', 1, fake_login=True).AndReturn(
            dummy_environ)
    self.dispatcher._handle_request(
        dummy_environ, mox.IgnoreArg(),
        self.dispatcher._module_name_to_module['default'],
        None).AndReturn(['Hello World'])
    self.mox.ReplayAll()
    response = self.dispatcher.add_request(
        'PUT', '/foo?bar=baz', [('Header', 'Value'), ('Other', 'Values')],
        'body', '1.2.3.4', fake_login=True)
    self.mox.VerifyAll()
    self.assertEqual('Hello World', response.content) 
Example #29
Source File: dispatcher_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_add_request_soft_routing(self):
    """Tests soft routing to the default module."""
    dummy_environ = object()
    self.mox.StubOutWithMock(self.dispatcher, '_handle_request')
    self.dispatcher._module_name_to_module['default'].build_request_environ(
        'PUT', '/foo?bar=baz', [('Header', 'Value'), ('Other', 'Values')],
        'body', '1.2.3.4', 1, fake_login=True).AndReturn(
            dummy_environ)
    self.dispatcher._handle_request(
        dummy_environ, mox.IgnoreArg(),
        self.dispatcher._module_name_to_module['default'],
        None).AndReturn(['Hello World'])
    self.mox.ReplayAll()
    response = self.dispatcher.add_request(
        'PUT', '/foo?bar=baz', [('Header', 'Value'), ('Other', 'Values')],
        'body', '1.2.3.4', fake_login=True, module_name='nomodule')
    self.mox.VerifyAll()
    self.assertEqual('Hello World', response.content) 
Example #30
Source File: application_configuration_test.py    From python-compat-runtime with Apache License 2.0 6 votes vote down vote up
def test_app_yaml_with_service(self):
    handlers = [appinfo.URLMap()]
    info = appinfo.AppInfoExternal(
        application='app',
        service='module1',
        version='1',
        runtime='python27',
        threadsafe=False,
        handlers=handlers,
        )
    appinfo_includes.ParseAndReturnIncludePaths(mox.IgnoreArg()).AndReturn(
        (info, []))
    os.path.getmtime('/appdir/app.yaml').AndReturn(10)

    self.mox.ReplayAll()
    config = application_configuration.ModuleConfiguration('/appdir/app.yaml')
    self.mox.VerifyAll()

    self.assertEqual('dev~app', config.application)
    self.assertEqual('app', config.application_external_name)
    self.assertEqual('module1', config.module_name)
    self.assertEqual('1', config.major_version)