Python mox.Mox() Examples
The following are 30
code examples of mox.Mox().
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: server_test.py From browserscope with Apache License 2.0 | 6 votes |
def setUp(self): api_server.test_setup_stubs() self.mox = mox.Mox() self.instance_factory = instance.InstanceFactory(object(), 10) self.instance_factory.FILE_CHANGE_INSTANCE_RESTART_POLICY = instance.ALWAYS self.servr = AutoScalingServerFacade(instance_factory=self.instance_factory) self.inst1 = self.mox.CreateMock(instance.Instance) self.inst2 = self.mox.CreateMock(instance.Instance) self.inst3 = self.mox.CreateMock(instance.Instance) self.inst1.total_requests = 2 self.inst2.total_requests = 0 self.inst3.total_requests = 4 self.servr._instances.add(self.inst1) self.servr._instances.add(self.inst2) self.servr._instances.add(self.inst3)
Example #2
Source File: server_test.py From browserscope with Apache License 2.0 | 6 votes |
def setUp(self): api_server.test_setup_stubs() self.mox = mox.Mox() self.inst = self.mox.CreateMock(instance.Instance) self.inst.instance_id = 0 self.environ = {} self.start_response = object() self.response = [object()] self.url_map = object() self.match = object() self.request_id = object() self.manual_server = ManualScalingServerFacade( instance_factory=instance.InstanceFactory(object(), 10)) self.mox.StubOutWithMock(self.manual_server, '_choose_instance') self.mox.StubOutWithMock(self.manual_server, '_add_instance') self.mox.StubOutWithMock(self.manual_server._condition, 'notify') self.mox.stubs.Set(time, 'time', lambda: 0.0)
Example #3
Source File: server_test.py From browserscope with Apache License 2.0 | 6 votes |
def setUp(self): api_server.test_setup_stubs() self.mox = mox.Mox() self.inst = self.mox.CreateMock(instance.Instance) self.environ = {} self.start_response = object() self.response = [object()] self.url_map = object() self.match = object() self.request_id = object() self.auto_server = AutoScalingServerFacade( instance_factory=instance.InstanceFactory(object(), 10)) self.mox.StubOutWithMock(self.auto_server, '_choose_instance') self.mox.StubOutWithMock(self.auto_server, '_add_instance') self.mox.stubs.Set(time, 'time', lambda: 0.0)
Example #4
Source File: http_test.py From honeything with GNU General Public License v3.0 | 6 votes |
def testEventQueue(self): cpe_machine = self.getCpe() m = mox.Mox() m.StubOutWithMock(sys, 'exit') sys.exit(1) sys.exit(1) sys.exit(1) sys.exit(1) m.ReplayAll() for i in range(64): cpe_machine.event_queue.append(i) cpe_machine.event_queue.append(100) cpe_machine.event_queue.appendleft(200) cpe_machine.event_queue.extend([300]) cpe_machine.event_queue.extendleft([400]) cpe_machine.event_queue.clear() cpe_machine.event_queue.append(10) cpe_machine.event_queue.clear() m.VerifyAll()
Example #5
Source File: periodic_statistics_test.py From honeything with GNU General Public License v3.0 | 6 votes |
def testCollectSample(self): obj_name = 'InternetGatewayDevice.LANDevice.1.WLANConfiguration.1.' obj_param = 'TotalBytesSent' sampled_param = periodic_statistics.PeriodicStatistics.SampleSet.Parameter() sampled_param.Enable = True sampled_param.Reference = obj_name + obj_param sample_set = periodic_statistics.PeriodicStatistics.SampleSet() m = mox.Mox() mock_root = m.CreateMock(tr.core.Exporter) mock_root.GetExport(mox.IsA(str)).AndReturn(1000) m.ReplayAll() sample_set.SetCpeAndRoot(cpe=object(), root=mock_root) sample_set.SetParameter('1', sampled_param) sample_set.CollectSample() m.VerifyAll() # Check that the sampled_param updated it's values. self.assertEqual('1000', sampled_param.Values)
Example #6
Source File: server_test.py From browserscope with Apache License 2.0 | 6 votes |
def setUp(self): api_server.test_setup_stubs() self.mox = mox.Mox() self.inst = self.mox.CreateMock(instance.Instance) self.inst.instance_id = 0 self.environ = {} self.start_response = object() self.response = [object()] self.url_map = object() self.match = object() self.request_id = object() self.basic_server = BasicScalingServerFacade( instance_factory=instance.InstanceFactory(object(), 10)) self.mox.StubOutWithMock(self.basic_server, '_choose_instance') self.mox.StubOutWithMock(self.basic_server, '_start_any_instance') self.mox.StubOutWithMock(self.basic_server, '_start_instance') self.mox.StubOutWithMock(self.basic_server._condition, 'wait') self.mox.StubOutWithMock(self.basic_server._condition, 'notify') self.time = 10 self.mox.stubs.Set(time, 'time', lambda: self.time)
Example #7
Source File: application_configuration_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): self.mox = mox.Mox() self.mox.StubOutWithMock(os.path, 'getmtime') self.mox.StubOutWithMock( application_configuration.DispatchConfiguration, '_parse_configuration')
Example #8
Source File: instance_test.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def setUp(self): self.mox = mox.Mox() self.proxy = self.mox.CreateMock(instance.RuntimeProxy) self.environ = object() self.start_response = object() self.url_map = object() self.match = object() self.request_id = object() self.response = [object()] self.request_data = self.mox.CreateMock(wsgi_request_info.WSGIRequestInfo)
Example #9
Source File: application_configuration_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): self.mox = mox.Mox() self.mox.StubOutWithMock( application_configuration.ServerConfiguration, '_parse_configuration') self.mox.StubOutWithMock(os.path, 'getmtime')
Example #10
Source File: static_files_handler_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): self.mox = mox.Mox() self.mox.StubOutWithMock(os.path, 'getmtime') self.mox.StubOutWithMock(static_files_handler.StaticContentHandler, '_read_file')
Example #11
Source File: junos_test.py From ldpush with Apache License 2.0 | 5 votes |
def setUp(self): self._mox = mox.Mox() self.device = junos.JunosDevice(host='pr01.dub01')
Example #12
Source File: container_sandbox_test.py From appstart with Apache License 2.0 | 5 votes |
def setUp(self): super(TestBase, self).setUp() test_directory = tempfile.mkdtemp() app_yaml = 'vm: true' self.conf_file = open(os.path.join(test_directory, 'app.yaml'), 'w') self.conf_file.write(app_yaml) self.conf_file.close() self.mocker = mox.Mox()
Example #13
Source File: periodic_statistics_test.py From honeything with GNU General Public License v3.0 | 5 votes |
def setUp(self): self.ps = periodic_statistics.PeriodicStatistics() self.m = mox.Mox() self.mock_root = self.m.CreateMock(tr.core.Exporter) self.mock_cpe = self.m.CreateMock(tr.http.CPEStateMachine) self.ps.SetCpe(self.mock_cpe) self.ps.SetRoot(self.mock_root)
Example #14
Source File: http_test.py From honeything with GNU General Public License v3.0 | 5 votes |
def testNewPingSession(self): cpe_machine = self.getCpe() cpe_machine.previous_ping_time = 0 # Create mocks of ioloop, and stubout the time function. m = mox.Mox() ioloop_mock = m.CreateMock(tornado.ioloop.IOLoop) m.StubOutWithMock(cpe_machine, "_NewSession") StubOutMonotime(m) # First call to _NewSession should get the time and trigger a new session GetMonotime()().AndReturn(1000) cpe_machine._NewSession(mox.IsA(str)) # Second call to _NewSession should queue a session GetMonotime()().AndReturn(1001) ioloop_mock.add_timeout(mox.IsA(datetime.timedelta), mox.IgnoreArg()).AndReturn(1) # Third call should get the time and then not do anything # since a session is queued. GetMonotime()().AndReturn(1001) # And the call to _NewTimeoutSession should call through to # NewPingSession, and start a new session GetMonotime()().AndReturn(1000 + cpe_machine.rate_limit_seconds) ioloop_mock.add_timeout(mox.IsA(datetime.timedelta), mox.IgnoreArg()).AndReturn(2) cpe_machine.ioloop = ioloop_mock m.ReplayAll() # Real test starts here. cpe_machine._NewPingSession() cpe_machine._NewPingSession() cpe_machine._NewPingSession() cpe_machine._NewTimeoutPingSession() # Verify everything was called correctly. m.VerifyAll()
Example #15
Source File: http_test.py From honeything with GNU General Public License v3.0 | 5 votes |
def testNewPeriodicSession(self): """Tests that _NewSession is called if the event queue is empty.""" cpe_machine = self.getCpe() # Create mocks of ioloop, and stubout the time function. m = mox.Mox() m.StubOutWithMock(cpe_machine, '_NewSession') cpe_machine._NewSession('2 PERIODIC') m.ReplayAll() cpe_machine.NewPeriodicSession() m.VerifyAll()
Example #16
Source File: file_util_test.py From google-apputils with Apache License 2.0 | 5 votes |
def setUp(self): self.mox = mox.Mox() self.sample_contents = 'Contents of the file' self.file_path = '/path/to/some/file' self.fd = 'a file descriptor'
Example #17
Source File: timer_test.py From macops with Apache License 2.0 | 5 votes |
def setUp(self): self.mox = mox.Mox() self.mox.StubOutWithMock(timer.gmacpyutil, 'SetPlistKey') self.mox.StubOutWithMock(timer.gmacpyutil, 'GetPlistKey') self.timeplist = '/tmp/blah/myapp.plist' self.interval = datetime.timedelta(hours=23) self.tf = timer.TimeFile(self.timeplist)
Example #18
Source File: static_files_handler_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): self.mox = mox.Mox() self.mox.StubOutWithMock(static_files_handler.StaticContentHandler, '_handle_path')
Example #19
Source File: application_configuration_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): self.mox = mox.Mox() self.mox.StubOutWithMock( application_configuration.BackendsConfiguration, '_parse_configuration') self.mox.StubOutWithMock(application_configuration, 'BackendConfiguration')
Example #20
Source File: application_configuration_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): self.mox = mox.Mox() self.mox.StubOutWithMock( application_configuration.ServerConfiguration, '_parse_configuration') self.mox.StubOutWithMock(os.path, 'getmtime')
Example #21
Source File: dispatcher_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): self.mox = mox.Mox() api_server.test_setup_stubs() self.dispatch_config = DispatchConfigurationStub() app_config = ApplicationConfigurationStub(SERVER_CONFIGURATIONS) self.dispatcher = dispatcher.Dispatcher( app_config, 'localhost', 1, 'gmail.com', 1, 'php_executable_path', 'enable_php_remote_debugging', python_config=None, cloud_sql_config=None, server_to_max_instances={}, use_mtime_file_watcher=False, automatic_restart=True, allow_skipped_files=False) self.server1 = AutoScalingServerFacade(app_config.servers[0], balanced_port=1, host='localhost') self.server2 = ManualScalingServerFacade(app_config.servers[0], balanced_port=2, host='localhost') self.mox.StubOutWithMock(self.dispatcher, '_create_server') self.dispatcher._create_server(app_config.servers[0], 1).AndReturn( (self.server1, 2)) self.dispatcher._create_server(app_config.servers[1], 2).AndReturn( (self.server2, 3)) self.mox.ReplayAll() self.dispatcher.start(12345, object()) app_config.dispatch = self.dispatch_config self.mox.VerifyAll() self.mox.StubOutWithMock(server.Server, 'build_request_environ')
Example #22
Source File: server_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): api_server.test_setup_stubs() self.mox = mox.Mox() self.instance_factory = instance.InstanceFactory(object(), 10) self.servr = BasicScalingServerFacade( instance_factory=self.instance_factory) self.mox.StubOutWithMock(self.instance_factory, 'files_changed') self.mox.StubOutWithMock(self.instance_factory, 'configuration_changed') self.mox.StubOutWithMock(self.servr, 'restart') self.mox.StubOutWithMock(self.servr, '_create_url_handlers') self.mox.StubOutWithMock(self.servr._server_configuration, 'check_for_updates') self.mox.StubOutWithMock(self.servr._watcher, 'has_changes')
Example #23
Source File: server_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): api_server.test_setup_stubs() self.mox = mox.Mox() self.factory = self.mox.CreateMock(instance.InstanceFactory) self.factory.max_concurrent_requests = 10 self.mox.StubOutWithMock(server._THREAD_POOL, 'submit') self.server = BasicScalingServerFacade(instance_factory=self.factory, host='localhost') self.wsgi_server = self.server._wsgi_servers[0] self.wsgi_server.start()
Example #24
Source File: server_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): api_server.test_setup_stubs() self.mox = mox.Mox() self.servr = BasicScalingServerFacade( instance_factory=instance.InstanceFactory(object(), 10)) self.mox.stubs.Set(time, 'time', lambda: self.time) self.mox.StubOutWithMock(self.servr._condition, 'wait') self.mox.StubOutWithMock(self.servr, '_start_any_instance') self.time = 0
Example #25
Source File: server_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): api_server.test_setup_stubs() self.mox = mox.Mox() self.mox.StubOutWithMock(server.Server, 'build_request_environ')
Example #26
Source File: server_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): self.mox = mox.Mox() api_server.test_setup_stubs() self.factory = self.mox.CreateMock(instance.InstanceFactory) self.server = ManualScalingServerFacade( instance_factory=self.factory) self._instance = self.mox.CreateMock(instance.Instance) self._wsgi_server = wsgi_server.WsgiServer(('localhost', 0), None) self.server._instances = [self._instance] self.server._wsgi_servers = [self._wsgi_server] self.mox.StubOutWithMock(server._THREAD_POOL, 'submit') self.mox.StubOutWithMock(self.server, '_shutdown_instance') self._wsgi_server.start()
Example #27
Source File: server_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): self.mox = mox.Mox() api_server.test_setup_stubs() self.server = ManualScalingServerFacade( instance_factory=instance.InstanceFactory(object(), 10)) self._instance = self.mox.CreateMock(instance.Instance) self._wsgi_server = self.mox.CreateMock(wsgi_server.WsgiServer) self._wsgi_server.port = 8080 self.server._instances = [self._instance] self.server._wsgi_servers = [self._wsgi_server] self.mox.StubOutWithMock(server._THREAD_POOL, 'submit') self.mox.StubOutWithMock(self.server, '_add_instance') self.mox.StubOutWithMock(self.server, '_shutdown_instance')
Example #28
Source File: server_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): self.mox = mox.Mox() api_server.test_setup_stubs() self.servr = ManualScalingServerFacade( instance_factory=instance.InstanceFactory(object(), 10)) self.mox.StubOutWithMock(self.servr._condition, 'wait') self.time = 0 self.mox.stubs.Set(time, 'time', lambda: self.time)
Example #29
Source File: server_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): api_server.test_setup_stubs() self.mox = mox.Mox() self.factory = self.mox.CreateMock(instance.InstanceFactory) self.factory.max_concurrent_requests = 10
Example #30
Source File: server_test.py From browserscope with Apache License 2.0 | 5 votes |
def setUp(self): api_server.test_setup_stubs() self.mox = mox.Mox() self.servr = AutoScalingServerFacade( instance_factory=instance.InstanceFactory(object(), 10))