def _GetJob(self, for_login=False): job = ClientNetworkingJobs.NetworkJobHydrus(MOCK_HYDRUS_SERVICE_KEY, 'GET', MOCK_HYDRUS_URL) job.SetForLogin(for_login) mock_controller = TestController.MockController() mock_service = ClientServices.GenerateService(MOCK_HYDRUS_SERVICE_KEY, HC.TAG_REPOSITORY, 'test tag repo') mock_services_manager = TestController.MockServicesManager( (mock_service, )) mock_controller.services_manager = mock_services_manager bandwidth_manager = ClientNetworkingBandwidth.NetworkBandwidthManager() session_manager = ClientNetworkingSessions.NetworkSessionManager() domain_manager = ClientNetworkingDomain.NetworkDomainManager() login_manager = ClientNetworkingLogin.NetworkLoginManager() engine = ClientNetworking.NetworkEngine(mock_controller, bandwidth_manager, session_manager, domain_manager, login_manager) job.engine = engine return job
def network_job_factory( *args, **kwargs ): network_job = ClientNetworkingJobs.NetworkJob( *args, **kwargs ) network_job.OverrideBandwidth() return network_job
def _GetExampleNetworkContexts(self, example_url: typing.Optional[str], subscription_name: str): subscription_key = self._GenerateNetworkJobSubscriptionKey( subscription_name) if example_url is None: return [ ClientNetworkingContexts.NetworkContext( CC.NETWORK_CONTEXT_SUBSCRIPTION, subscription_key), ClientNetworkingContexts.GLOBAL_NETWORK_CONTEXT ] try: # if the url is borked for some reason example_nj = ClientNetworkingJobs.NetworkJobSubscription( subscription_key, 'GET', example_url) example_network_contexts = example_nj.GetNetworkContexts() except: return [ ClientNetworkingContexts.NetworkContext( CC.NETWORK_CONTEXT_SUBSCRIPTION, subscription_key), ClientNetworkingContexts.GLOBAL_NETWORK_CONTEXT ] return example_network_contexts
def network_job_factory( *args, **kwargs ): network_job = ClientNetworkingJobs.NetworkJobSubscription( subscription_key, *args, **kwargs ) network_job.OverrideBandwidth( 30 ) return network_job
def test_engine_simple_job(self): mock_controller = TestController.MockController() bandwidth_manager = ClientNetworkingBandwidth.NetworkBandwidthManager() session_manager = ClientNetworkingSessions.NetworkSessionManager() domain_manager = ClientNetworkingDomain.NetworkDomainManager() login_manager = ClientNetworkingLogin.NetworkLoginManager() engine = ClientNetworking.NetworkEngine(mock_controller, bandwidth_manager, session_manager, domain_manager, login_manager) self.assertFalse(engine.IsRunning()) self.assertFalse(engine.IsShutdown()) mock_controller.CallToThread(engine.MainLoop) # with HTTMock(catch_all): with HTTMock(catch_wew_ok): job = ClientNetworkingJobs.NetworkJob('GET', MOCK_URL) engine.AddJob(job) time.sleep(0.25) self.assertTrue(job.IsDone()) self.assertFalse(job.HasError()) engine._new_work_to_do.set() time.sleep(0.25) self.assertEqual(len(engine._jobs_awaiting_validity), 0) self.assertEqual(len(engine._jobs_awaiting_bandwidth), 0) self.assertEqual(len(engine._jobs_awaiting_login), 0) self.assertEqual(len(engine._jobs_awaiting_slot), 0) self.assertEqual(len(engine._jobs_running), 0) # engine.Shutdown()
def _GetJob(self, for_login=False): job = ClientNetworkingJobs.NetworkJob('GET', MOCK_URL) job.SetForLogin(for_login) mock_controller = TestController.MockController() bandwidth_manager = ClientNetworkingBandwidth.NetworkBandwidthManager() session_manager = ClientNetworkingSessions.NetworkSessionManager() domain_manager = ClientNetworkingDomain.NetworkDomainManager() login_manager = ClientNetworkingLogin.NetworkLoginManager() engine = ClientNetworking.NetworkEngine(mock_controller, bandwidth_manager, session_manager, domain_manager, login_manager) job.engine = engine return job
def _GetExampleNetworkContexts( self, subscription_name ): file_seed = self._file_seed_cache.GetNextFileSeed( CC.STATUS_UNKNOWN ) subscription_key = self.GetNetworkJobSubscriptionKey( subscription_name ) if file_seed is None: return [ ClientNetworkingContexts.NetworkContext( CC.NETWORK_CONTEXT_SUBSCRIPTION, subscription_key ), ClientNetworkingContexts.GLOBAL_NETWORK_CONTEXT ] url = file_seed.file_seed_data try: # if the url is borked for some reason example_nj = ClientNetworkingJobs.NetworkJobSubscription( subscription_key, 'GET', url ) example_network_contexts = example_nj.GetNetworkContexts() except: return [ ClientNetworkingContexts.NetworkContext( CC.NETWORK_CONTEXT_SUBSCRIPTION, subscription_key ), ClientNetworkingContexts.GLOBAL_NETWORK_CONTEXT ] return example_network_contexts
def _NetworkJobFactory( self, *args, **kwargs ): network_job = ClientNetworkingJobs.NetworkJobDownloader( self._downloader_key, *args, **kwargs ) return network_job
def _NetworkJobFactory(self, *args, **kwargs): network_job = ClientNetworkingJobs.NetworkJobWatcherPage( self._watcher_key, *args, **kwargs) return network_job