Example #1
0
    def _GetJob(self, for_login=False):

        job = ClientNetworkingJobs.NetworkJobHydrus(MOCK_HYDRUS_SERVICE_KEY,
                                                    'GET', MOCK_HYDRUS_URL)

        job.SetForLogin(for_login)

        mock_controller = TestConstants.MockController()

        mock_service = ClientServices.GenerateService(MOCK_HYDRUS_SERVICE_KEY,
                                                      HC.TAG_REPOSITORY,
                                                      'test tag repo')

        mock_services_manager = TestConstants.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
Example #2
0
    def test_engine_shutdown_manual(self):

        mock_controller = TestConstants.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)

        time.sleep(0.1)

        self.assertTrue(engine.IsRunning())
        self.assertFalse(engine.IsShutdown())

        engine.Shutdown()

        time.sleep(0.1)

        self.assertFalse(engine.IsRunning())
        self.assertTrue(engine.IsShutdown())
Example #3
0
    def test_engine_simple_job(self):

        mock_controller = TestConstants.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.1)

                self.assertTrue(job.IsDone())
                self.assertFalse(job.HasError())

                engine._new_work_to_do.set()

                time.sleep(0.1)

                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()
Example #4
0
    def _PrepEngine(self):

        mock_controller = TestConstants.MockController()
        bandwidth_manager = ClientNetworkingBandwidth.NetworkBandwidthManager()
        session_manager = ClientNetworkingSessions.NetworkSessionManager()
        domain_manager = ClientNetworkingDomain.NetworkDomainManager()
        login_manager = ClientNetworkingLogin.NetworkLoginManager()

        ClientDefaults.SetDefaultDomainManagerData(domain_manager)

        engine = ClientNetworking.NetworkEngine(mock_controller,
                                                bandwidth_manager,
                                                session_manager,
                                                domain_manager, login_manager)

        mock_controller.CallToThread(engine.MainLoop)

        return (mock_controller, engine)
Example #5
0
    def _GetJob(self, for_login=False):

        job = ClientNetworkingJobs.NetworkJob('GET', MOCK_URL)

        job.SetForLogin(for_login)

        mock_controller = TestConstants.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
Example #6
0
 def InitModel( self ):
     
     self.pub( 'splash_set_title_text', u'booting db\u2026' )
     
     HydrusController.HydrusController.InitModel( self )
     
     self.pub( 'splash_set_status_text', u'initialising managers' )
     
     self.pub( 'splash_set_status_subtext', u'services' )
     
     self.services_manager = ClientCaches.ServicesManager( self )
     
     self.pub( 'splash_set_status_subtext', u'options' )
     
     self.options = self.Read( 'options' )
     self.new_options = self.Read( 'serialisable', HydrusSerialisable.SERIALISABLE_TYPE_CLIENT_OPTIONS )
     
     HC.options = self.options
     
     if self.new_options.GetBoolean( 'use_system_ffmpeg' ):
         
         if HydrusVideoHandling.FFMPEG_PATH.startswith( HC.BIN_DIR ):
             
             HydrusVideoHandling.FFMPEG_PATH = os.path.basename( HydrusVideoHandling.FFMPEG_PATH )
             
         
     
     self.pub( 'splash_set_status_subtext', u'client files' )
     
     self.InitClientFilesManager()
     
     #
     
     self.pub( 'splash_set_status_subtext', u'network' )
     
     bandwidth_manager = self.Read( 'serialisable', HydrusSerialisable.SERIALISABLE_TYPE_NETWORK_BANDWIDTH_MANAGER )
     
     if bandwidth_manager is None:
         
         bandwidth_manager = ClientNetworking.NetworkBandwidthManager()
         
         ClientDefaults.SetDefaultBandwidthManagerRules( bandwidth_manager )
         
         bandwidth_manager._dirty = True
         
         wx.MessageBox( 'Your bandwidth manager was missing on boot! I have recreated a new empty one with default rules. Please check that your hard drive and client are ok and let the hydrus dev know the details if there is a mystery.' )
         
     
     session_manager = self.Read( 'serialisable', HydrusSerialisable.SERIALISABLE_TYPE_NETWORK_SESSION_MANAGER )
     
     if session_manager is None:
         
         session_manager = ClientNetworking.NetworkSessionManager()
         
         session_manager._dirty = True
         
         wx.MessageBox( 'Your session manager was missing on boot! I have recreated a new empty one. Please check that your hard drive and client are ok and let the hydrus dev know the details if there is a mystery.' )
         
     
     domain_manager = self.Read( 'serialisable', HydrusSerialisable.SERIALISABLE_TYPE_NETWORK_DOMAIN_MANAGER )
     
     if domain_manager is None:
         
         domain_manager = ClientNetworkingDomain.NetworkDomainManager()
         
         ClientDefaults.SetDefaultDomainManagerData( domain_manager )
         
         domain_manager._dirty = True
         
         wx.MessageBox( 'Your domain manager was missing on boot! I have recreated a new empty one. Please check that your hard drive and client are ok and let the hydrus dev know the details if there is a mystery.' )
         
     
     domain_manager.Initialise()
     
     login_manager = ClientNetworkingLogin.NetworkLoginManager()
     
     self.network_engine = ClientNetworking.NetworkEngine( self, bandwidth_manager, session_manager, domain_manager, login_manager )
     
     self.CallToThreadLongRunning( self.network_engine.MainLoop )
     
     #
     
     self._shortcuts_manager = ClientCaches.ShortcutsManager( self )
     
     self.local_booru_manager = ClientCaches.LocalBooruCache( self )
     
     self.pub( 'splash_set_status_subtext', u'tag censorship' )
     
     self._managers[ 'tag_censorship' ] = ClientCaches.TagCensorshipManager( self )
     
     self.pub( 'splash_set_status_subtext', u'tag siblings' )
     
     self._managers[ 'tag_siblings' ] = ClientCaches.TagSiblingsManager( self )
     
     self.pub( 'splash_set_status_subtext', u'tag parents' )
     
     self._managers[ 'tag_parents' ] = ClientCaches.TagParentsManager( self )
     self._managers[ 'undo' ] = ClientCaches.UndoManager( self )
     
     def wx_code():
         
         self._caches[ 'images' ] = ClientCaches.RenderedImageCache( self )
         self._caches[ 'thumbnail' ] = ClientCaches.ThumbnailCache( self )
         
         CC.GlobalBMPs.STATICInitialise()
         
     
     self.pub( 'splash_set_status_subtext', u'image caches' )
     
     self.CallBlockingToWx( wx_code )
     
     self.sub( self, 'ToClipboard', 'clipboard' )
     self.sub( self, 'RestartBooru', 'restart_booru' )