def test_downloads(self): result = self._read('downloads') self.assertEqual(result, set()) # hash = '\xadm5\x99\xa6\xc4\x89\xa5u\xeb\x19\xc0&\xfa\xce\x97\xa9\xcdey\xe7G(\xb0\xce\x94\xa6\x01\xd22\xf3\xc3' service_keys_to_content_updates = {} service_keys_to_content_updates[HC.LOCAL_FILE_SERVICE_KEY] = ( HC.ContentUpdate(HC.CONTENT_DATA_TYPE_FILES, HC.CONTENT_UPDATE_PENDING, (hash, )), ) self._write('content_updates', service_keys_to_content_updates) # result = self._read('downloads') self.assertEqual(result, {hash}) # hash = '\xadm5\x99\xa6\xc4\x89\xa5u\xeb\x19\xc0&\xfa\xce\x97\xa9\xcdey\xe7G(\xb0\xce\x94\xa6\x01\xd22\xf3\xc3' service_keys_to_content_updates = {} service_keys_to_content_updates[HC.LOCAL_FILE_SERVICE_KEY] = ( HC.ContentUpdate(HC.CONTENT_DATA_TYPE_FILES, HC.CONTENT_UPDATE_RESCIND_PENDING, (hash, )), ) self._write('content_updates', service_keys_to_content_updates) # result = self._read('downloads') self.assertEqual(result, set())
def test_md5_status(self): self._clear_db() hash = '\xadm5\x99\xa6\xc4\x89\xa5u\xeb\x19\xc0&\xfa\xce\x97\xa9\xcdey\xe7G(\xb0\xce\x94\xa6\x01\xd22\xf3\xc3' md5 = 'fdadb2cae78f2dfeb629449cd005f2a2'.decode('hex') path = HC.STATIC_DIR + os.path.sep + 'hydrus.png' # result = self._read('md5_status', md5) self.assertEqual(result, ('new', None)) # self._write('import_file', path) # result = self._read('md5_status', md5) self.assertEqual(result, ('redundant', hash)) # content_update = HC.ContentUpdate(HC.CONTENT_DATA_TYPE_FILES, HC.CONTENT_UPDATE_DELETE, (hash, )) service_keys_to_content_updates = { HC.LOCAL_FILE_SERVICE_KEY: (content_update, ) } self._write('content_updates', service_keys_to_content_updates) # HC.options['exclude_deleted_files'] = True result = self._read('md5_status', md5) self.assertEqual(result, ('deleted', None)) HC.options['exclude_deleted_files'] = False result = self._read('md5_status', md5) self.assertEqual(result, ('new', None))
def test_undo(self): hash_1 = os.urandom(32) hash_2 = os.urandom(32) hash_3 = os.urandom(32) command_1 = { HC.LOCAL_FILE_SERVICE_KEY: [ HC.ContentUpdate(HC.CONTENT_DATA_TYPE_FILES, HC.CONTENT_UPDATE_ARCHIVE, {hash_1}) ] } command_2 = { HC.LOCAL_FILE_SERVICE_KEY: [ HC.ContentUpdate(HC.CONTENT_DATA_TYPE_FILES, HC.CONTENT_UPDATE_INBOX, {hash_2}) ] } command_3 = { HC.LOCAL_FILE_SERVICE_KEY: [ HC.ContentUpdate(HC.CONTENT_DATA_TYPE_FILES, HC.CONTENT_UPDATE_ARCHIVE, {hash_1, hash_3}) ] } command_1_inverted = { HC.LOCAL_FILE_SERVICE_KEY: [ HC.ContentUpdate(HC.CONTENT_DATA_TYPE_FILES, HC.CONTENT_UPDATE_INBOX, {hash_1}) ] } command_2_inverted = { HC.LOCAL_FILE_SERVICE_KEY: [ HC.ContentUpdate(HC.CONTENT_DATA_TYPE_FILES, HC.CONTENT_UPDATE_ARCHIVE, {hash_2}) ] } undo_manager = CC.UndoManager() # undo_manager.AddCommand('content_updates', command_1) self.assertEqual((u'undo local files->archive 1 files', None), undo_manager.GetUndoRedoStrings()) undo_manager.AddCommand('content_updates', command_2) self.assertEqual((u'undo local files->inbox 1 files', None), undo_manager.GetUndoRedoStrings()) undo_manager.Undo() self.assertEqual((u'undo local files->archive 1 files', u'redo local files->inbox 1 files'), undo_manager.GetUndoRedoStrings()) self.assertEqual(HC.app.GetWrite('content_updates'), [((command_2_inverted, ), {})]) undo_manager.Redo() self.assertEqual(HC.app.GetWrite('content_updates'), [((command_2, ), {})]) self.assertEqual((u'undo local files->inbox 1 files', None), undo_manager.GetUndoRedoStrings()) undo_manager.Undo() self.assertEqual(HC.app.GetWrite('content_updates'), [((command_2_inverted, ), {})]) undo_manager.Undo() self.assertEqual(HC.app.GetWrite('content_updates'), [((command_1_inverted, ), {})]) self.assertEqual((None, u'redo local files->archive 1 files'), undo_manager.GetUndoRedoStrings()) undo_manager.AddCommand('content_updates', command_3) self.assertEqual((u'undo local files->archive 2 files', None), undo_manager.GetUndoRedoStrings())
def test_autocomplete(self): self._clear_db() result = self._read('autocomplete_tags', half_complete_tag='c') self.assertEqual(result.GetMatches('c'), []) result = self._read('autocomplete_tags', half_complete_tag='series:') self.assertEqual(result.GetMatches('series:'), []) # hash = '\xadm5\x99\xa6\xc4\x89\xa5u\xeb\x19\xc0&\xfa\xce\x97\xa9\xcdey\xe7G(\xb0\xce\x94\xa6\x01\xd22\xf3\xc3' path = HC.STATIC_DIR + os.path.sep + 'hydrus.png' self._write('import_file', path) # service_keys_to_content_updates = {} content_updates = [] content_updates.append( HC.ContentUpdate(HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('car', (hash, )))) content_updates.append( HC.ContentUpdate(HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('series:cars', (hash, )))) content_updates.append( HC.ContentUpdate(HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('maker:ford', (hash, )))) service_keys_to_content_updates[ HC.LOCAL_TAG_SERVICE_KEY] = content_updates self._write('content_updates', service_keys_to_content_updates) # cars result = self._read('autocomplete_tags', half_complete_tag='c') preds = set() preds.add( HC.Predicate(HC.PREDICATE_TYPE_TAG, 'car', counts={HC.CURRENT: 1})) preds.add( HC.Predicate(HC.PREDICATE_TYPE_TAG, 'series:cars', counts={HC.CURRENT: 1})) read_preds = result.GetMatches('c') # count isn't tested in predicate.__eq__, I think for p in read_preds: self.assertEqual(p.GetCount(HC.CURRENT), 1) self.assertEqual(set(read_preds), preds) # result = self._read('autocomplete_tags', half_complete_tag='ser') read_preds = result.GetMatches('ser') self.assertEqual(read_preds, []) # result = self._read('autocomplete_tags', half_complete_tag='series:c') pred = HC.Predicate(HC.PREDICATE_TYPE_TAG, 'series:cars', counts={HC.CURRENT: 1}) (read_pred, ) = result.GetMatches('series:c') self.assertEqual(read_pred.GetCount(HC.CURRENT), 1) self.assertEqual(pred, read_pred) # result = self._read('autocomplete_tags', tag='car') pred = HC.Predicate(HC.PREDICATE_TYPE_TAG, 'car', counts={HC.CURRENT: 1}) (read_pred, ) = result.GetMatches('car') self.assertEqual(read_pred.GetCount(HC.CURRENT), 1) self.assertEqual(pred, read_pred) # result = self._read('autocomplete_tags', tag='c') read_preds = result.GetMatches('c') self.assertEqual(read_preds, [])
def test_file_query_ids(self): self._clear_db() def run_namespace_predicate_tests(tests): for (inclusive, namespace, result) in tests: predicates = [ HC.Predicate(HC.PREDICATE_TYPE_NAMESPACE, namespace, inclusive=inclusive) ] search_context = CC.FileSearchContext( file_service_key=HC.LOCAL_FILE_SERVICE_KEY, predicates=predicates) file_query_ids = self._read('file_query_ids', search_context) self.assertEqual(len(file_query_ids), result) def run_system_predicate_tests(tests): for (predicate_type, info, result) in tests: predicates = [ HC.Predicate(HC.PREDICATE_TYPE_SYSTEM, (predicate_type, info)) ] search_context = CC.FileSearchContext( file_service_key=HC.LOCAL_FILE_SERVICE_KEY, predicates=predicates) file_query_ids = self._read('file_query_ids', search_context) self.assertEqual(len(file_query_ids), result) def run_tag_predicate_tests(tests): for (inclusive, tag, result) in tests: predicates = [ HC.Predicate(HC.PREDICATE_TYPE_TAG, tag, inclusive=inclusive) ] search_context = CC.FileSearchContext( file_service_key=HC.LOCAL_FILE_SERVICE_KEY, predicates=predicates) file_query_ids = self._read('file_query_ids', search_context) self.assertEqual(len(file_query_ids), result) tests = [] tests.append((HC.SYSTEM_PREDICATE_TYPE_ARCHIVE, None, 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_EVERYTHING, None, 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_INBOX, None, 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_LOCAL, None, 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NOT_LOCAL, None, 0)) run_system_predicate_tests(tests) # hash = '\xadm5\x99\xa6\xc4\x89\xa5u\xeb\x19\xc0&\xfa\xce\x97\xa9\xcdey\xe7G(\xb0\xce\x94\xa6\x01\xd22\xf3\xc3' path = HC.STATIC_DIR + os.path.sep + 'hydrus.png' self._write('import_file', path) time.sleep(1) # tests = [] tests.append((HC.SYSTEM_PREDICATE_TYPE_AGE, ( '<', 1, 1, 1, 1, ), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_AGE, ( '<', 0, 0, 0, 0, ), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_AGE, ( u'\u2248', 1, 1, 1, 1, ), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_AGE, ( u'\u2248', 0, 0, 0, 0, ), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_AGE, ( '>', 1, 1, 1, 1, ), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_AGE, ( '>', 0, 0, 0, 0, ), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_ARCHIVE, None, 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_DURATION, ( '<', 100, ), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_DURATION, ( '<', 0, ), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_DURATION, ( u'\u2248', 100, ), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_DURATION, ( u'\u2248', 0, ), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_DURATION, ( '=', 100, ), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_DURATION, ( '=', 0, ), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_DURATION, ( '>', 100, ), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_DURATION, ( '>', 0, ), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_EVERYTHING, None, 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_FILE_SERVICE, (False, HC.CURRENT, HC.LOCAL_FILE_SERVICE_KEY), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_FILE_SERVICE, (False, HC.PENDING, HC.LOCAL_FILE_SERVICE_KEY), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_FILE_SERVICE, (True, HC.CURRENT, HC.LOCAL_FILE_SERVICE_KEY), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_FILE_SERVICE, (True, HC.PENDING, HC.LOCAL_FILE_SERVICE_KEY), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_HASH, hash, 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_HASH, ('0123456789abcdef' * 4).decode('hex'), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_HEIGHT, ('<', 201), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_HEIGHT, ('<', 200), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_HEIGHT, ('<', 0), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_HEIGHT, (u'\u2248', 200), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_HEIGHT, (u'\u2248', 60), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_HEIGHT, (u'\u2248', 0), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_HEIGHT, ('=', 200), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_HEIGHT, ('=', 0), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_HEIGHT, ('>', 200), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_HEIGHT, ('>', 199), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_INBOX, None, 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_LOCAL, None, 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_MIME, HC.IMAGES, 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_MIME, HC.IMAGE_PNG, 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_MIME, HC.IMAGE_JPEG, 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_MIME, HC.VIDEO, 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NOT_LOCAL, None, 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_TAGS, ('<', 1), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_TAGS, ('<', 0), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_TAGS, ('=', 0), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_TAGS, ('=', 1), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_TAGS, ('>', 0), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_TAGS, ('>', 1), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_WORDS, ('<', 1), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_WORDS, ('<', 0), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_WORDS, (u'\u2248', 0), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_WORDS, (u'\u2248', 1), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_WORDS, ('=', 0), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_WORDS, ('=', 1), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_WORDS, ('>', 0), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_WORDS, ('>', 1), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_RATIO, ('=', 1, 1), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_RATIO, ('=', 4, 3), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_RATIO, (u'\u2248', 1, 1), 1)) tests.append( (HC.SYSTEM_PREDICATE_TYPE_RATIO, (u'\u2248', 200, 201), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_RATIO, (u'\u2248', 4, 1), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_SIMILAR_TO, (hash, 5), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_SIMILAR_TO, (('0123456789abcdef' * 4).decode('hex'), 5), 0)) tests.append( (HC.SYSTEM_PREDICATE_TYPE_SIZE, ('<', 0, HC.ConvertUnitToInteger('B')), 0)) tests.append( (HC.SYSTEM_PREDICATE_TYPE_SIZE, ('<', 5270, HC.ConvertUnitToInteger('B')), 0)) tests.append( (HC.SYSTEM_PREDICATE_TYPE_SIZE, ('<', 5271, HC.ConvertUnitToInteger('B')), 1)) tests.append( (HC.SYSTEM_PREDICATE_TYPE_SIZE, ('=', 5270, HC.ConvertUnitToInteger('B')), 1)) tests.append( (HC.SYSTEM_PREDICATE_TYPE_SIZE, ('=', 0, HC.ConvertUnitToInteger('B')), 0)) tests.append( (HC.SYSTEM_PREDICATE_TYPE_SIZE, (u'\u2248', 5270, HC.ConvertUnitToInteger('B')), 1)) tests.append( (HC.SYSTEM_PREDICATE_TYPE_SIZE, (u'\u2248', 0, HC.ConvertUnitToInteger('B')), 0)) tests.append( (HC.SYSTEM_PREDICATE_TYPE_SIZE, ('>', 5270, HC.ConvertUnitToInteger('B')), 0)) tests.append( (HC.SYSTEM_PREDICATE_TYPE_SIZE, ('>', 5269, HC.ConvertUnitToInteger('B')), 1)) tests.append( (HC.SYSTEM_PREDICATE_TYPE_SIZE, ('>', 0, HC.ConvertUnitToInteger('B')), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_SIZE, ('>', 0, HC.ConvertUnitToInteger('KB')), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_SIZE, ('>', 0, HC.ConvertUnitToInteger('MB')), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_SIZE, ('>', 0, HC.ConvertUnitToInteger('GB')), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_WIDTH, ('<', 201), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_WIDTH, ('<', 200), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_WIDTH, ('<', 0), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_WIDTH, (u'\u2248', 200), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_WIDTH, (u'\u2248', 60), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_WIDTH, (u'\u2248', 0), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_WIDTH, ('=', 200), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_WIDTH, ('=', 0), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_WIDTH, ('>', 200), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_WIDTH, ('>', 199), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_LIMIT, 100, 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_LIMIT, 1, 1)) # limit is not applied in file_query_ids! we do it later! tests.append((HC.SYSTEM_PREDICATE_TYPE_LIMIT, 0, 1)) run_system_predicate_tests(tests) # service_keys_to_content_updates = {} service_keys_to_content_updates[HC.LOCAL_FILE_SERVICE_KEY] = ( HC.ContentUpdate(HC.CONTENT_DATA_TYPE_FILES, HC.CONTENT_UPDATE_ARCHIVE, (hash, )), ) service_keys_to_content_updates[HC.LOCAL_TAG_SERVICE_KEY] = ( HC.ContentUpdate(HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('car', (hash, ))), ) self._write('content_updates', service_keys_to_content_updates) # tests = [] tests.append((HC.SYSTEM_PREDICATE_TYPE_ARCHIVE, None, 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_INBOX, None, 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_TAGS, ('<', 2), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_TAGS, ('<', 1), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_TAGS, ('<', 0), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_TAGS, ('=', 0), 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_TAGS, ('=', 1), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_TAGS, ('>', 0), 1)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NUM_TAGS, ('>', 1), 0)) run_system_predicate_tests(tests) # tests = [] tests.append((True, 'car', 1)) tests.append((False, 'car', 0)) tests.append((True, 'bus', 0)) tests.append((False, 'bus', 1)) run_tag_predicate_tests(tests) # tests = [] tests.append((True, 'series', 0)) tests.append((False, 'series', 1)) run_namespace_predicate_tests(tests) # service_keys_to_content_updates = {} content_updates = [] content_updates.append( HC.ContentUpdate(HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('series:cars', (hash, )))) content_updates.append( HC.ContentUpdate(HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('maker:ford', (hash, )))) service_keys_to_content_updates[ HC.LOCAL_TAG_SERVICE_KEY] = content_updates self._write('content_updates', service_keys_to_content_updates) # tests = [] tests.append((True, 'maker:ford', 1)) tests.append((True, 'ford', 1)) tests.append((False, 'maker:ford', 0)) tests.append((False, 'ford', 0)) run_tag_predicate_tests(tests) # tests = [] tests.append((True, 'series', 1)) tests.append((False, 'series', 0)) run_namespace_predicate_tests(tests) # content_update = HC.ContentUpdate(HC.CONTENT_DATA_TYPE_FILES, HC.CONTENT_UPDATE_DELETE, (hash, )) service_keys_to_content_updates = { HC.LOCAL_FILE_SERVICE_KEY: (content_update, ) } self._write('content_updates', service_keys_to_content_updates) # tests = [] tests.append((HC.SYSTEM_PREDICATE_TYPE_ARCHIVE, None, 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_EVERYTHING, None, 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_INBOX, None, 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_LOCAL, None, 0)) tests.append((HC.SYSTEM_PREDICATE_TYPE_NOT_LOCAL, None, 0)) run_system_predicate_tests(tests)
def test_dict_to_content_updates(self): hash = os.urandom(32) hashes = set([hash]) local_key = HC.LOCAL_TAG_SERVICE_KEY remote_key = os.urandom(32) service_keys_to_tags = {local_key: {'a'}} content_updates = { local_key: [ HC.ContentUpdate(HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('a', hashes)) ] } self.assertEqual( HydrusDownloading. ConvertServiceKeysToTagsToServiceKeysToContentUpdates( hash, service_keys_to_tags), content_updates) service_keys_to_tags = {remote_key: {'c'}} content_updates = { remote_key: [ HC.ContentUpdate(HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PENDING, ('c', hashes)) ] } self.assertEqual( HydrusDownloading. 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] = [ HC.ContentUpdate(HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('a', hashes)), HC.ContentUpdate(HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('character:b', hashes)) ] content_updates[remote_key] = [ HC.ContentUpdate(HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PENDING, ('c', hashes)), HC.ContentUpdate(HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PENDING, ('series:d', hashes)) ] self.assertEqual( HC.ContentUpdate(HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PENDING, 'c'), HC.ContentUpdate(HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PENDING, 'c')) self.assertEqual( HydrusDownloading. ConvertServiceKeysToTagsToServiceKeysToContentUpdates( hash, service_keys_to_tags), content_updates)
def test_process_content_update( self ): hashes = { os.urandom( 32 ) for i in range( 6 ) } # self.assertEqual( self._other_tags_manager.GetCurrent( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetDeleted( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetPending( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetPetitioned( self._content_update_service_key ), set() ) self.assertNotIn( 'hello', self._other_tags_manager.GetCurrent() ) self.assertNotIn( 'hello', self._other_tags_manager.GetPending() ) # content_update = HC.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_DELETE, ( 'hello', hashes ) ) self._other_tags_manager.ProcessContentUpdate( self._content_update_service_key, content_update ) self.assertEqual( self._other_tags_manager.GetCurrent( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetDeleted( self._content_update_service_key ), { 'hello' } ) self.assertEqual( self._other_tags_manager.GetPending( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetPetitioned( self._content_update_service_key ), set() ) self.assertNotIn( 'hello', self._other_tags_manager.GetCurrent() ) self.assertNotIn( 'hello', self._other_tags_manager.GetPending() ) # content_update = HC.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PENDING, ( 'hello', hashes ) ) self._other_tags_manager.ProcessContentUpdate( self._content_update_service_key, content_update ) self.assertEqual( self._other_tags_manager.GetCurrent( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetDeleted( self._content_update_service_key ), { 'hello' } ) self.assertEqual( self._other_tags_manager.GetPending( self._content_update_service_key ), { 'hello' } ) self.assertEqual( self._other_tags_manager.GetPetitioned( self._content_update_service_key ), set() ) self.assertNotIn( 'hello', self._other_tags_manager.GetCurrent() ) self.assertIn( 'hello', self._other_tags_manager.GetPending() ) # content_update = HC.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_RESCIND_PENDING, ( 'hello', hashes ) ) self._other_tags_manager.ProcessContentUpdate( self._content_update_service_key, content_update ) self.assertEqual( self._other_tags_manager.GetCurrent( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetDeleted( self._content_update_service_key ), { 'hello' } ) self.assertEqual( self._other_tags_manager.GetPending( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetPetitioned( self._content_update_service_key ), set() ) self.assertNotIn( 'hello', self._other_tags_manager.GetCurrent() ) self.assertNotIn( 'hello', self._other_tags_manager.GetPending() ) # content_update = HC.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PENDING, ( 'hello', hashes ) ) self._other_tags_manager.ProcessContentUpdate( self._content_update_service_key, content_update ) self.assertEqual( self._other_tags_manager.GetCurrent( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetDeleted( self._content_update_service_key ), { 'hello' } ) self.assertEqual( self._other_tags_manager.GetPending( self._content_update_service_key ), { 'hello' } ) self.assertEqual( self._other_tags_manager.GetPetitioned( self._content_update_service_key ), set() ) self.assertNotIn( 'hello', self._other_tags_manager.GetCurrent() ) self.assertIn( 'hello', self._other_tags_manager.GetPending() ) # content_update = HC.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ( 'hello', hashes ) ) self._other_tags_manager.ProcessContentUpdate( self._content_update_service_key, content_update ) self.assertEqual( self._other_tags_manager.GetCurrent( self._content_update_service_key ), { 'hello' } ) self.assertEqual( self._other_tags_manager.GetDeleted( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetPending( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetPetitioned( self._content_update_service_key ), set() ) self.assertIn( 'hello', self._other_tags_manager.GetCurrent() ) self.assertNotIn( 'hello', self._other_tags_manager.GetPending() ) # content_update = HC.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PETITION, ( 'hello', hashes, 'reason' ) ) self._other_tags_manager.ProcessContentUpdate( self._content_update_service_key, content_update ) self.assertEqual( self._other_tags_manager.GetCurrent( self._content_update_service_key ), { 'hello' } ) self.assertEqual( self._other_tags_manager.GetDeleted( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetPending( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetPetitioned( self._content_update_service_key ), { 'hello' } ) self.assertIn( 'hello', self._other_tags_manager.GetCurrent() ) self.assertNotIn( 'hello', self._other_tags_manager.GetPending() ) # content_update = HC.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_RESCIND_PETITION, ( 'hello', hashes ) ) self._other_tags_manager.ProcessContentUpdate( self._content_update_service_key, content_update ) self.assertEqual( self._other_tags_manager.GetCurrent( self._content_update_service_key ), { 'hello' } ) self.assertEqual( self._other_tags_manager.GetDeleted( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetPending( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetPetitioned( self._content_update_service_key ), set() ) self.assertIn( 'hello', self._other_tags_manager.GetCurrent() ) self.assertNotIn( 'hello', self._other_tags_manager.GetPending() ) # content_update = HC.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PETITION, ( 'hello', hashes, 'reason' ) ) self._other_tags_manager.ProcessContentUpdate( self._content_update_service_key, content_update ) self.assertEqual( self._other_tags_manager.GetCurrent( self._content_update_service_key ), { 'hello' } ) self.assertEqual( self._other_tags_manager.GetDeleted( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetPending( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetPetitioned( self._content_update_service_key ), { 'hello' } ) self.assertIn( 'hello', self._other_tags_manager.GetCurrent() ) self.assertNotIn( 'hello', self._other_tags_manager.GetPending() ) # content_update = HC.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_DELETE, ( 'hello', hashes ) ) self._other_tags_manager.ProcessContentUpdate( self._content_update_service_key, content_update ) self.assertEqual( self._other_tags_manager.GetCurrent( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetDeleted( self._content_update_service_key ), { 'hello' } ) self.assertEqual( self._other_tags_manager.GetPending( self._content_update_service_key ), set() ) self.assertEqual( self._other_tags_manager.GetPetitioned( self._content_update_service_key ), set() ) self.assertNotIn( 'hello', self._other_tags_manager.GetCurrent() ) self.assertNotIn( 'hello', self._other_tags_manager.GetPending() )