def test_filter(self): some_tags = {'bodysuit', 'character:samus aran', 'series:metroid'} example_hash = HydrusData.GenerateKey() example_service_key = HydrusData.GenerateKey() # tag_blacklist = ClientTags.TagFilter() tag_blacklist.SetRule('series:', CC.FILTER_BLACKLIST) service_keys_to_service_tag_import_options = { example_service_key: ClientImportOptions.ServiceTagImportOptions(get_tags=True) } tag_import_options = ClientImportOptions.TagImportOptions( tag_blacklist=tag_blacklist, service_keys_to_service_tag_import_options= service_keys_to_service_tag_import_options) result = tag_import_options.GetServiceKeysToContentUpdates( CC.STATUS_SUCCESSFUL_AND_NEW, True, example_hash, some_tags) self.assertIn(example_service_key, result) self.assertEqual(len(result), 1) content_updates = result[example_service_key] filtered_tags = {'bodysuit', 'character:samus aran'} self.assertTrue(len(content_updates), len(filtered_tags))
def test_services(self): some_tags = {'bodysuit', 'character:samus aran', 'series:metroid'} example_hash = HydrusData.GenerateKey() example_service_key_1 = HydrusData.GenerateKey() example_service_key_2 = HydrusData.GenerateKey() # service_keys_to_service_tag_import_options = {} service_keys_to_service_tag_import_options[ example_service_key_1] = ClientImportOptions.ServiceTagImportOptions( get_tags=True) service_keys_to_service_tag_import_options[ example_service_key_2] = ClientImportOptions.ServiceTagImportOptions( get_tags=False) tag_import_options = ClientImportOptions.TagImportOptions( service_keys_to_service_tag_import_options= service_keys_to_service_tag_import_options) result = tag_import_options.GetServiceKeysToContentUpdates( CC.STATUS_SUCCESSFUL_AND_NEW, True, example_hash, some_tags) self.assertIn(example_service_key_1, result) self.assertNotIn(example_service_key_2, result) self.assertTrue(len(result), 2) content_updates_1 = result[example_service_key_1] self.assertEqual(len(content_updates_1), 3)
def setUpClass( cls ): cls._access_key = HydrusData.GenerateKey() services = [] cls._serverside_file_service = HydrusNetwork.GenerateService( HydrusData.GenerateKey(), HC.FILE_REPOSITORY, 'file repo', HC.DEFAULT_SERVICE_PORT + 1 ) cls._serverside_tag_service = HydrusNetwork.GenerateService( HydrusData.GenerateKey(), HC.TAG_REPOSITORY, 'tag repo', HC.DEFAULT_SERVICE_PORT ) cls._serverside_admin_service = HydrusNetwork.GenerateService( HydrusData.GenerateKey(), HC.SERVER_ADMIN, 'server admin', HC.DEFAULT_SERVER_ADMIN_PORT ) cls._clientside_file_service = ClientServices.GenerateService( HydrusData.GenerateKey(), HC.FILE_REPOSITORY, 'file repo' ) cls._clientside_tag_service = ClientServices.GenerateService( HydrusData.GenerateKey(), HC.TAG_REPOSITORY, 'tag repo' ) cls._clientside_admin_service = ClientServices.GenerateService( HydrusData.GenerateKey(), HC.SERVER_ADMIN, 'server admin' ) cls._clientside_file_service.SetCredentials( HydrusNetwork.Credentials( '127.0.0.1', HC.DEFAULT_SERVICE_PORT + 1, cls._access_key ) ) cls._clientside_tag_service.SetCredentials( HydrusNetwork.Credentials( '127.0.0.1', HC.DEFAULT_SERVICE_PORT, cls._access_key ) ) cls._clientside_admin_service.SetCredentials( HydrusNetwork.Credentials( '127.0.0.1', HC.DEFAULT_SERVER_ADMIN_PORT, cls._access_key ) ) cls._local_booru = ClientServices.GenerateService( HydrusData.GenerateKey(), HC.LOCAL_BOORU, 'local booru' ) services_manager = HG.test_controller.services_manager services_manager._keys_to_services[ cls._clientside_file_service.GetServiceKey() ] = cls._clientside_file_service services_manager._keys_to_services[ cls._clientside_tag_service.GetServiceKey() ] = cls._clientside_tag_service services_manager._keys_to_services[ cls._clientside_admin_service.GetServiceKey() ] = cls._clientside_admin_service 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 = HydrusNetwork.AccountType.GenerateAdminAccountType( HC.SERVER_ADMIN ) created = HydrusData.GetNow() - 100000 expires = None cls._account = HydrusNetwork.Account( account_key, account_type, created, expires ) cls._file_hash = HydrusData.GenerateKey() def TWISTEDSetup(): cls._ssl_cert_path = os.path.join( TestConstants.DB_DIR, 'server.crt' ) cls._ssl_key_path = os.path.join( TestConstants.DB_DIR, 'server.key' ) # if db test ran, this is still hanging around and read-only, so don't bother to fail overwriting if not os.path.exists( cls._ssl_cert_path ): HydrusEncryption.GenerateOpenSSLCertAndKeyFile( cls._ssl_cert_path, cls._ssl_key_path ) context_factory = twisted.internet.ssl.DefaultOpenSSLContextFactory( cls._ssl_key_path, cls._ssl_cert_path ) reactor.listenSSL( HC.DEFAULT_SERVER_ADMIN_PORT, ServerServer.HydrusServiceAdmin( cls._serverside_admin_service ), context_factory ) reactor.listenSSL( HC.DEFAULT_SERVICE_PORT + 1, ServerServer.HydrusServiceRepositoryFile( cls._serverside_file_service ), context_factory ) reactor.listenSSL( HC.DEFAULT_SERVICE_PORT, ServerServer.HydrusServiceRepositoryTag( cls._serverside_tag_service ), context_factory ) reactor.listenTCP( HC.DEFAULT_LOCAL_BOORU_PORT, ClientLocalServer.HydrusServiceBooru( cls._local_booru ) ) reactor.callFromThread( TWISTEDSetup ) time.sleep( 1 )
def test_SERIALISABLE_TYPE_APPLICATION_COMMAND(self): def test(obj, dupe_obj): self.assertEqual(obj.GetCommandType(), dupe_obj.GetCommandType()) self.assertEqual(obj.GetData(), dupe_obj.GetData()) acs = [] acs.append( (ClientData.ApplicationCommand(CC.APPLICATION_COMMAND_TYPE_SIMPLE, 'archive_file'), 'archive_file')) acs.append((ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_CONTENT, (HydrusData.GenerateKey(), HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_FLIP, 'test')), 'flip on/off mappings "test" for unknown service!')) acs.append((ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_CONTENT, (CC.LOCAL_TAG_SERVICE_KEY, HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_FLIP, 'test')), 'flip on/off mappings "test" for local tags')) acs.append((ClientData.ApplicationCommand( CC.APPLICATION_COMMAND_TYPE_CONTENT, (HydrusData.GenerateKey(), HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_SET, 0.4)), 'set ratings "0.4" for unknown service!')) for (ac, s) in acs: self._dump_and_load_and_test(ac, test) self.assertEqual(ac.ToString(), s)
def test_dict_to_content_updates( self ): hash = HydrusData.GenerateKey() hashes = { hash } local_key = CC.LOCAL_TAG_SERVICE_KEY remote_key = HydrusData.GenerateKey() service_keys_to_tags = { local_key : { 'a' } } content_updates = { local_key : [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ( 'a', hashes ) ) ] } self.assertEqual( ClientData.ConvertServiceKeysToTagsToServiceKeysToContentUpdates( { hash }, service_keys_to_tags ), content_updates ) service_keys_to_tags = { remote_key : { 'c' } } content_updates = { remote_key : [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, ( 'c', hashes ) ) ] } self.assertEqual( ClientData.ConvertServiceKeysToTagsToServiceKeysToContentUpdates( { hash }, service_keys_to_tags ), content_updates ) service_keys_to_tags = { local_key : [ 'a', 'character:b' ], remote_key : [ 'c', 'series:d' ] } content_updates = {} content_updates[ local_key ] = [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ( 'a', hashes ) ), HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ( 'character:b', hashes ) ) ] content_updates[ remote_key ] = [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, ( 'c', hashes ) ), HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, ( 'series:d', hashes ) ) ] self.assertEqual( HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, 'c' ), HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, 'c' ) ) self.assertEqual( ClientData.ConvertServiceKeysToTagsToServiceKeysToContentUpdates( { hash }, service_keys_to_tags ), content_updates )
def test_basics(self): some_tags = {'bodysuit', 'character:samus aran', 'series:metroid'} example_hash = HydrusData.GenerateKey() example_service_key = HydrusData.GenerateKey() # default_service_tag_import_options = ClientImportOptions.ServiceTagImportOptions( ) self.assertEqual(default_service_tag_import_options._get_tags, False) self.assertEqual(default_service_tag_import_options._additional_tags, []) self.assertEqual(default_service_tag_import_options._to_new_files, True) self.assertEqual( default_service_tag_import_options._to_already_in_inbox, True) self.assertEqual( default_service_tag_import_options._to_already_in_archive, True) self.assertEqual( default_service_tag_import_options._only_add_existing_tags, False) self.assertEqual( default_service_tag_import_options.GetTags( example_service_key, CC.STATUS_SUCCESSFUL_AND_NEW, True, example_hash, some_tags), set())
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 test_get_tags_filtering(self): some_tags = {'bodysuit', 'character:samus aran', 'series:metroid'} example_hash = HydrusData.GenerateKey() example_service_key = HydrusData.GenerateKey() # service_tag_import_options = ClientImportOptions.ServiceTagImportOptions( get_tags=True) self.assertEqual( service_tag_import_options.GetTags(example_service_key, CC.STATUS_SUCCESSFUL_AND_NEW, True, example_hash, some_tags), some_tags) # only_namespaced = ClientTags.TagFilter() only_namespaced.SetRule('', CC.FILTER_BLACKLIST) service_tag_import_options = ClientImportOptions.ServiceTagImportOptions( get_tags=True, get_tags_filter=only_namespaced) self.assertEqual( service_tag_import_options.GetTags(example_service_key, CC.STATUS_SUCCESSFUL_AND_NEW, True, example_hash, some_tags), {'character:samus aran', 'series:metroid'}) # only_samus = ClientTags.TagFilter() only_samus.SetRule('', CC.FILTER_BLACKLIST) only_samus.SetRule(':', CC.FILTER_BLACKLIST) only_samus.SetRule('character:samus aran', CC.FILTER_WHITELIST) service_tag_import_options = ClientImportOptions.ServiceTagImportOptions( get_tags=True, get_tags_filter=only_samus) self.assertEqual( service_tag_import_options.GetTags(example_service_key, CC.STATUS_SUCCESSFUL_AND_NEW, True, example_hash, some_tags), {'character:samus aran'})
def _UpdateSerialisableInfo(self, version, old_serialisable_info): if version == 1: (url_type, preferred_scheme, netloc, allow_subdomains, keep_subdomains, serialisable_path_components, serialisable_parameters, example_url) = old_serialisable_info url_match_key = HydrusData.GenerateKey() serialisable_url_match_key = url_match_key.encode('hex') api_lookup_converter = ClientParsing.StringConverter( example_string=example_url) serialisable_api_lookup_converter = api_lookup_converter.GetSerialisableTuple( ) new_serialisable_info = (serialisable_url_match_key, url_type, preferred_scheme, netloc, allow_subdomains, keep_subdomains, serialisable_path_components, serialisable_parameters, serialisable_api_lookup_converter, example_url) return (2, new_serialisable_info)
def __init__(self): HydrusSerialisable.SerialisableBase.__init__(self) self._gallery_seed_log = ClientImportGallerySeeds.GallerySeedLog() self._file_seed_cache = ClientImportFileSeeds.FileSeedCache() self._file_import_options = HG.client_controller.new_options.GetDefaultFileImportOptions( 'loud') self._tag_import_options = ClientImportOptions.TagImportOptions( is_default=True) self._paused = False self._downloader_key = HydrusData.GenerateKey() self._lock = threading.Lock() self._files_network_job = None self._gallery_network_job = None self._files_repeating_job = None self._gallery_repeating_job = None HG.client_controller.sub(self, 'NotifyFileSeedsUpdated', 'file_seed_cache_file_seeds_updated') HG.client_controller.sub(self, 'NotifyGallerySeedsUpdated', 'gallery_seed_log_gallery_seeds_updated')
def test_additional(self): some_tags = {'bodysuit', 'character:samus aran', 'series:metroid'} example_hash = HydrusData.GenerateKey() example_service_key = HydrusData.GenerateKey() # service_tag_import_options = ClientImportOptions.ServiceTagImportOptions( get_tags=True, additional_tags=['wew']) self.assertEqual( service_tag_import_options.GetTags(example_service_key, CC.STATUS_SUCCESSFUL_AND_NEW, True, example_hash, some_tags), some_tags.union(['wew']))
def AddSession(self, service_key, access_key): with self._lock: account_key = HG.controller.Read('account_key_from_access_key', service_key, access_key) account_keys_to_accounts = self._service_keys_to_account_keys_to_accounts[ service_key] if account_key not in account_keys_to_accounts: account = HG.controller.Read('account', service_key, account_key) account_keys_to_accounts[account_key] = account session_key = HydrusData.GenerateKey() now = HydrusData.GetNow() expires = now + HYDRUS_SESSION_LIFETIME HG.controller.Write('session', session_key, service_key, account_key, expires) self._service_keys_to_session_keys_to_sessions[service_key][ session_key] = (account_key, expires) return (session_key, expires)
def __init__( self, pausable = False, cancellable = False, only_when_idle = False, only_start_if_unbusy = False, stop_time = None ): self._key = HydrusData.GenerateKey() self._pausable = pausable self._cancellable = cancellable self._only_when_idle = only_when_idle self._only_start_if_unbusy = only_start_if_unbusy self._stop_time = stop_time self._deleted = threading.Event() self._deletion_time = None self._begun = threading.Event() self._done = threading.Event() self._cancelled = threading.Event() self._paused = threading.Event() self._yield_pause_period = 10 self._next_yield_pause = HydrusData.GetNow() + self._yield_pause_period self._bigger_pause_period = 100 self._next_bigger_pause = HydrusData.GetNow() + self._bigger_pause_period self._longer_pause_period = 1000 self._next_longer_pause = HydrusData.GetNow() + self._longer_pause_period self._variable_lock = threading.Lock() self._variables = dict()
def __init__(self): HydrusSerialisable.SerialisableBase.__init__(self) file_import_options = HG.client_controller.new_options.GetDefaultFileImportOptions( 'loud') self._pending_jobs = [] self._gallery_seed_log = ClientImportGallerySeeds.GallerySeedLog() self._file_seed_cache = ClientImportFileSeeds.FileSeedCache() self._file_import_options = file_import_options self._formula_name = 'all files linked by images in page' self._queue_paused = False self._files_paused = False self._downloader_key = HydrusData.GenerateKey() self._parser_status = '' self._current_action = '' self._lock = threading.Lock() self._files_network_job = None self._page_network_job = None self._files_repeating_job = None self._queue_repeating_job = None HG.client_controller.sub(self, 'NotifyFileSeedsUpdated', 'file_seed_cache_file_seeds_updated')
def test_SERIALISABLE_TYPE_SHORTCUTS( self ): def test( obj, dupe_obj ): for ( ( modifier, key ), action ) in obj.IterateKeyboardShortcuts(): self.assertEqual( dupe_obj.GetKeyboardAction( modifier, key ), action ) for ( ( modifier, mouse_button ), action ) in obj.IterateMouseShortcuts(): self.assertEqual( dupe_obj.GetMouseAction( modifier, mouse_button ), action ) action_1 = ( HydrusData.GenerateKey(), u'test unicode tag\u2026' ) action_2 = ( HydrusData.GenerateKey(), 0.5 ) action_3 = ( None, 'archive' ) shortcuts = ClientData.Shortcuts( 'test' ) shortcuts.SetKeyboardAction( wx.ACCEL_NORMAL, wx.WXK_NUMPAD1, action_1 ) shortcuts.SetKeyboardAction( wx.ACCEL_SHIFT, wx.WXK_END, action_2 ) shortcuts.SetKeyboardAction( wx.ACCEL_CTRL, ord( 'R' ), action_3 ) shortcuts.SetMouseAction( wx.ACCEL_NORMAL, wx.MOUSE_BTN_LEFT, action_1 ) shortcuts.SetMouseAction( wx.ACCEL_SHIFT, wx.MOUSE_BTN_MIDDLE, action_2 ) shortcuts.SetMouseAction( wx.ACCEL_CTRL, wx.MOUSE_BTN_RIGHT, action_3 ) shortcuts.SetMouseAction( wx.ACCEL_ALT, wx.MOUSE_WHEEL_VERTICAL, action_3 ) k_a = [ item for item in shortcuts.IterateKeyboardShortcuts() ] self.assertEqual( len( k_a ), 3 ) for ( ( modifier, key ), action ) in k_a: self.assertEqual( shortcuts.GetKeyboardAction( modifier, key ), action ) m_a = [ item for item in shortcuts.IterateMouseShortcuts() ] self.assertEqual( len( m_a ), 4 ) for ( ( modifier, mouse_button ), action ) in m_a: self.assertEqual( shortcuts.GetMouseAction( modifier, mouse_button ), action )
def AcquirePageKey(self): with self._page_key_lock: page_key = HydrusData.GenerateKey() self._alive_page_keys.add(page_key) return page_key
def test_existing(self): some_tags = {'bodysuit', 'character:samus aran', 'series:metroid'} existing_tags = {'character:samus aran', 'series:metroid'} example_hash = HydrusData.GenerateKey() example_service_key = HydrusData.GenerateKey() # HG.test_controller.SetRead('filter_existing_tags', existing_tags) service_tag_import_options = ClientImportOptions.ServiceTagImportOptions( get_tags=True, only_add_existing_tags=True) self.assertEqual( service_tag_import_options.GetTags(example_service_key, CC.STATUS_SUCCESSFUL_AND_NEW, True, example_hash, some_tags), existing_tags) # some_tags = { 'explicit', 'bodysuit', 'character:samus aran', 'series:metroid' } existing_tags = {'bodysuit'} only_unnamespaced = ClientTags.TagFilter() only_unnamespaced.SetRule(':', CC.FILTER_BLACKLIST) HG.test_controller.SetRead('filter_existing_tags', existing_tags) service_tag_import_options = ClientImportOptions.ServiceTagImportOptions( get_tags=True, only_add_existing_tags=True, only_add_existing_tags_filter=only_unnamespaced) self.assertEqual( service_tag_import_options.GetTags(example_service_key, CC.STATUS_SUCCESSFUL_AND_NEW, True, example_hash, some_tags), {'bodysuit', 'character:samus aran', 'series:metroid'})
def __init__(self): HydrusSerialisable.SerialisableBase.__init__(self) self._page_key = 'initialising page key' self._publish_to_page = False self._url = '' self._gallery_seed_log = ClientImportGallerySeeds.GallerySeedLog() self._file_seed_cache = ClientImportFileSeeds.FileSeedCache() self._urls_to_filenames = {} self._urls_to_md5_base64 = {} self._checker_options = HG.client_controller.new_options.GetDefaultWatcherCheckerOptions( ) self._file_import_options = HG.client_controller.new_options.GetDefaultFileImportOptions( 'loud') self._tag_import_options = ClientImportOptions.TagImportOptions( is_default=True) self._last_check_time = 0 self._checking_status = ClientImporting.CHECKER_STATUS_OK self._subject = 'unknown subject' self._next_check_time = None self._download_control_file_set = None self._download_control_file_clear = None self._download_control_checker_set = None self._download_control_checker_clear = None self._check_now = False self._files_paused = False self._checking_paused = False self._no_work_until = 0 self._no_work_until_reason = '' self._creation_time = HydrusData.GetNow() self._file_velocity_status = '' self._current_action = '' self._watcher_status = '' self._watcher_key = HydrusData.GenerateKey() self._lock = threading.Lock() self._last_pubbed_page_name = '' self._files_repeating_job = None self._checker_repeating_job = None HG.client_controller.sub(self, 'NotifyFileSeedsUpdated', 'file_seed_cache_file_seeds_updated')
def __init__(self, parent, controller, management_controller, initial_media_results): wx.SplitterWindow.__init__(self, parent) self._page_key = HydrusData.GenerateKey() self._controller = controller self._management_controller = management_controller self._management_controller.SetKey('page', self._page_key) self._pretty_status = '' self.SetMinimumPaneSize(120) self.SetSashGravity(0.0) self.Bind(wx.EVT_SPLITTER_DCLICK, self.EventUnsplit) self._search_preview_split = wx.SplitterWindow(self, style=wx.SP_NOBORDER) self._search_preview_split.SetMinimumPaneSize(180) self._search_preview_split.SetSashGravity(1.0) self._search_preview_split.Bind(wx.EVT_SPLITTER_DCLICK, self.EventPreviewUnsplit) self._management_panel = ClientGUIManagement.CreateManagementPanel( self._search_preview_split, self, self._controller, self._management_controller) file_service_key = self._management_controller.GetKey('file_service') self._preview_panel = ClientGUICanvas.CanvasPanel( self._search_preview_split, self._page_key) self._media_panel = ClientGUIMedia.MediaPanelThumbnails( self, self._page_key, file_service_key, initial_media_results) self._search_preview_split.SplitHorizontally(self._management_panel, self._preview_panel, HC.options['vpos']) self.SplitVertically(self._search_preview_split, self._media_panel, HC.options['hpos']) if HC.options['hide_preview']: wx.CallAfter(self._search_preview_split.Unsplit, self._preview_panel) self._controller.sub(self, 'SetPrettyStatus', 'new_page_status') self._controller.sub(self, 'SwapMediaPanel', 'swap_media_panel')
def test_namespace_filtering(self): some_tags = {'bodysuit', 'character:samus aran', 'series:metroid'} example_hash = HydrusData.GenerateKey() example_service_key = HydrusData.GenerateKey() # service_tag_import_options = ClientImportOptions.ServiceTagImportOptions( get_all=True) self.assertEqual( service_tag_import_options.GetTags(example_service_key, CC.STATUS_SUCCESSFUL_AND_NEW, True, example_hash, some_tags), some_tags) # service_tag_import_options = ClientImportOptions.ServiceTagImportOptions( namespaces=['', 'character']) self.assertEqual( service_tag_import_options.GetTags(example_service_key, CC.STATUS_SUCCESSFUL_AND_NEW, True, example_hash, some_tags), {'bodysuit', 'character:samus aran'}) # service_tag_import_options = ClientImportOptions.ServiceTagImportOptions( namespaces=[]) self.assertEqual( service_tag_import_options.GetTags(example_service_key, CC.STATUS_SUCCESSFUL_AND_NEW, True, example_hash, some_tags), set())
def test_basics(self): def test(obj, dupe_obj): self.assertEqual(len(obj.items()), len(dupe_obj.items())) for (key, value) in obj.items(): self.assertEqual(value, dupe_obj[key]) # d = HydrusSerialisable.SerialisableDictionary() d[1] = 2 d[3] = 'test1' d['test2'] = 4 d['test3'] = 5 d[6] = HydrusSerialisable.SerialisableDictionary( {i: 'test' + str(i) for i in range(20)}) d[ClientSearch.Predicate(HC.PREDICATE_TYPE_TAG, 'test pred 1')] = 56 d[ClientSearch.Predicate( HC.PREDICATE_TYPE_TAG, 'test pred 2')] = HydrusSerialisable.SerialisableList([ ClientSearch.Predicate(HC.PREDICATE_TYPE_TAG, 'test' + str(i)) for i in range(10) ]) self.assertEqual(len(d.keys()), 7) for (key, value) in d.items(): self.assertEqual(d[key], value) self._dump_and_load_and_test(d, test) # db = HydrusSerialisable.SerialisableBytesDictionary() db[HydrusData.GenerateKey()] = HydrusData.GenerateKey() db[HydrusData.GenerateKey()] = [ HydrusData.GenerateKey() for i in range(10) ] db[1] = HydrusData.GenerateKey() db[2] = [HydrusData.GenerateKey() for i in range(10)] self.assertEqual(len(db.keys()), 4) for (key, value) in db.items(): self.assertEqual(db[key], value) self._dump_and_load_and_test(db, test)
def ConvertGalleryIdentifierToGUGKeyAndName(gallery_identifier): gug_name = ConvertGalleryIdentifierToGUGName(gallery_identifier) import ClientDefaults gugs = ClientDefaults.GetDefaultGUGs() for gug in gugs: if gug.GetName() == gug_name: return gug.GetGUGKeyAndName() return (HydrusData.GenerateKey(), gug_name)
def test_basics(self): some_tags = {'bodysuit', 'character:samus aran', 'series:metroid'} example_hash = HydrusData.GenerateKey() # default_tag_import_options = ClientImportOptions.TagImportOptions() self.assertEqual( default_tag_import_options. ShouldFetchTagsEvenIfURLKnownAndFileAlreadyInDB(), False) self.assertEqual( default_tag_import_options. ShouldFetchTagsEvenIfHashKnownAndFileAlreadyInDB(), False) blacklist = default_tag_import_options.GetTagBlacklist() self.assertEqual(blacklist.Filter(some_tags), some_tags) self.assertEqual( default_tag_import_options.GetServiceKeysToContentUpdates( CC.STATUS_SUCCESSFUL_AND_NEW, True, example_hash, some_tags), {}) # tag_import_options = ClientImportOptions.TagImportOptions( fetch_tags_even_if_url_recognised_and_file_already_in_db=True) self.assertEqual( tag_import_options.ShouldFetchTagsEvenIfURLKnownAndFileAlreadyInDB( ), True) self.assertEqual( tag_import_options. ShouldFetchTagsEvenIfHashKnownAndFileAlreadyInDB(), False) # tag_import_options = ClientImportOptions.TagImportOptions( fetch_tags_even_if_hash_recognised_and_file_already_in_db=True) self.assertEqual( tag_import_options.ShouldFetchTagsEvenIfURLKnownAndFileAlreadyInDB( ), False) self.assertEqual( tag_import_options. ShouldFetchTagsEvenIfHashKnownAndFileAlreadyInDB(), True)
def __init__( self ): HydrusSerialisable.SerialisableBase.__init__( self ) self._gallery_seeds = HydrusSerialisable.SerialisableList() self._gallery_seeds_to_indices = {} self._gallery_seed_log_key = HydrusData.GenerateKey() self._status_cache = None self._status_cache_generation_time = 0 self._status_dirty = True self._lock = threading.Lock()
def _test_server_admin(self, service, host, port): info = service.GetInfo() info['host'] = host info['port'] = port # init access_key = HydrusData.GenerateKey() HydrusGlobals.test_controller.SetRead('init', access_key) response = service.Request(HC.GET, 'init') self.assertEqual(response['access_key'], access_key) # info['access_key'] = self._access_key # backup response = service.Request(HC.POST, 'backup') # services services_info = {'message': 'hello'} HydrusGlobals.test_controller.SetRead('services_info', services_info) response = service.Request(HC.GET, 'services_info') self.assertEqual(response['services_info'], services_info) edit_log = 'blah' registration_keys = service.Request(HC.POST, 'services', {'edit_log': edit_log}) written = HydrusGlobals.test_controller.GetWrite('services') [(args, kwargs)] = written (written_service_key, written_edit_log) = args self.assertEqual(edit_log, written_edit_log)
def AddSession( self, service_key, access_key, name ): session_key = HydrusData.GenerateKey() account_key = HydrusGlobals.controller.Read( 'account_key_from_access_key', service_key, access_key ) account = HydrusGlobals.controller.Read( 'account', service_key, account_key ) now = HydrusData.GetNow() expires = now + HYDRUS_SESSION_LIFETIME with self._lock: self._service_keys_to_sessions[ service_key ][ session_key ] = ( account, name, expires ) HydrusGlobals.controller.Write( 'messaging_session', service_key, session_key, account_key, name, expires ) return session_key
def _test_server_admin( self, service ): # init access_key = HydrusData.GenerateKey() HG.test_controller.SetRead( 'access_key', access_key ) response = service.Request( HC.GET, 'access_key', { 'registration_key' : 'init' } ) self.assertEqual( response[ 'access_key' ], access_key ) # ## backup response = service.Request( HC.POST, 'backup' )
def __init__(self, gug_key_and_name=None): if gug_key_and_name is None: gug_key_and_name = (HydrusData.GenerateKey(), 'unknown source') HydrusSerialisable.SerialisableBase.__init__(self) self._lock = threading.Lock() self._page_key = 'initialising page key' self._gug_key_and_name = gug_key_and_name self._highlighted_gallery_import_key = None new_options = HG.client_controller.new_options self._file_limit = HC.options['gallery_file_limit'] self._start_file_queues_paused = False self._start_gallery_queues_paused = False self._file_import_options = HG.client_controller.new_options.GetDefaultFileImportOptions( 'loud') self._tag_import_options = ClientImportOptions.TagImportOptions( is_default=True) self._gallery_imports = HydrusSerialisable.SerialisableList() self._gallery_import_keys_to_gallery_imports = {} self._status_dirty = True self._status_cache = None self._status_cache_generation_time = 0 self._last_time_imports_changed = HydrusData.GetNowPrecise() self._last_pubbed_value_range = (0, 0) self._next_pub_value_check_time = 0 self._importers_repeating_job = None
def _test_server_admin(self, service): # init access_key = HydrusData.GenerateKey() HG.test_controller.SetRead('access_key', access_key) response = service.Request(HC.GET, 'access_key', 'init') self.assertEqual(response['access_key'], access_key) # # backup response = service.Request(HC.POST, 'backup') # services services_info = {'message': 'hello'} HG.test_controller.SetRead('services_info', services_info) response = service.Request(HC.GET, 'services_info') self.assertEqual(response['services_info'], services_info) edit_log = 'blah' registration_keys = service.Request(HC.POST, 'services', {'edit_log': edit_log}) written = HG.test_controller.GetWrite('services') [(args, kwargs)] = written (written_service_key, written_edit_log) = args self.assertEqual(edit_log, written_edit_log)
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 )