def test_services(self): def test_service(service, key, service_type, name, info): self.assertEqual(service.GetServiceKey(), key) self.assertEqual(service.GetServiceType(), service_type) self.assertEqual(service.GetName(), name) self.assertEqual(service.GetInfo(), info) repo_key = HydrusData.GenerateKey() repo_type = HC.TAG_REPOSITORY repo_name = 'test tag repo' repo_info = {'blah': 5} repo = ClientData.GenerateService(repo_key, repo_type, repo_name, repo_info) other_key = HydrusData.GenerateKey() other = ClientData.GenerateService(other_key, HC.LOCAL_BOORU, 'booru', {}) services = [] services.append(repo) services.append(other) HydrusGlobals.test_controller.SetRead('services', services) services_manager = ClientCaches.ServicesManager( HydrusGlobals.client_controller) # service = services_manager.GetService(repo_key) test_service(service, repo_key, repo_type, repo_name, repo_info) service = services_manager.GetService(other_key) # services = services_manager.GetServices((HC.TAG_REPOSITORY, )) self.assertEqual(len(services), 1) self.assertEqual(services[0].GetServiceKey(), repo_key) # services = [] services.append(repo) HydrusGlobals.test_controller.SetRead('services', services) services_manager.RefreshServices() self.assertRaises(Exception, services_manager.GetService, other_key)
def setUpClass( self ): services = [] self._file_service = ClientData.GenerateService( HydrusData.GenerateKey(), HC.FILE_REPOSITORY, 'file repo', {} ) self._tag_service = ClientData.GenerateService( HydrusData.GenerateKey(), HC.TAG_REPOSITORY, 'tag repo', {} ) self._admin_service = ClientData.GenerateService( HydrusData.GenerateKey(), HC.SERVER_ADMIN, 'server admin', {} ) services_manager = HydrusGlobals.test_controller.GetServicesManager() services_manager._keys_to_services[ self._file_service.GetServiceKey() ] = self._file_service services_manager._keys_to_services[ self._tag_service.GetServiceKey() ] = self._tag_service services_manager._keys_to_services[ self._admin_service.GetServiceKey() ] = self._admin_service HydrusPaths.MakeSureDirectoryExists( ServerFiles.GetExpectedUpdateDir( self._file_service.GetServiceKey() ) ) HydrusPaths.MakeSureDirectoryExists( ServerFiles.GetExpectedUpdateDir( self._tag_service.GetServiceKey() ) ) permissions = [ HC.GET_DATA, HC.POST_DATA, HC.POST_PETITIONS, HC.RESOLVE_PETITIONS, HC.MANAGE_USERS, HC.GENERAL_ADMIN, HC.EDIT_SERVICES ] account_key = HydrusData.GenerateKey() account_type = HydrusData.AccountType( 'account', permissions, ( None, None ) ) created = HydrusData.GetNow() - 100000 expires = None used_bytes = 0 used_requests = 0 self._account = HydrusData.Account( account_key, account_type, created, expires, used_bytes, used_requests ) self._access_key = HydrusData.GenerateKey() self._file_hash = HydrusData.GenerateKey() def TWISTEDSetup(): reactor.listenTCP( HC.DEFAULT_SERVER_ADMIN_PORT, ServerServer.HydrusServiceAdmin( self._admin_service.GetServiceKey(), HC.SERVER_ADMIN, 'hello' ) ) reactor.listenTCP( HC.DEFAULT_LOCAL_FILE_PORT, ClientLocalServer.HydrusServiceLocal( CC.LOCAL_FILE_SERVICE_KEY, HC.LOCAL_FILE, 'hello' ) ) reactor.listenTCP( HC.DEFAULT_LOCAL_BOORU_PORT, ClientLocalServer.HydrusServiceBooru( CC.LOCAL_BOORU_SERVICE_KEY, HC.LOCAL_BOORU, 'hello' ) ) reactor.listenTCP( HC.DEFAULT_SERVICE_PORT, ServerServer.HydrusServiceRepositoryFile( self._file_service.GetServiceKey(), HC.FILE_REPOSITORY, 'hello' ) ) reactor.listenTCP( HC.DEFAULT_SERVICE_PORT + 1, ServerServer.HydrusServiceRepositoryTag( self._tag_service.GetServiceKey(), HC.TAG_REPOSITORY, 'hello' ) ) reactor.callFromThread( TWISTEDSetup ) time.sleep( 1 )