def _test_local_booru(self, host, port): # connection = http.client.HTTPConnection(host, port, timeout=10) # with open(os.path.join(HC.STATIC_DIR, 'local_booru_style.css'), 'rb') as f: css = f.read() connection.request('GET', '/style.css') response = connection.getresponse() data = response.read() self.assertEqual(data, css) # share_key = HydrusData.GenerateKey() hashes = [HydrusData.GenerateKey() for i in range(5)] client_files_default = os.path.join(TestController.DB_DIR, 'client_files') hash_encoded = hashes[0].hex() prefix = hash_encoded[:2] file_path = os.path.join(client_files_default, 'f' + prefix, hash_encoded + '.jpg') thumbnail_path = os.path.join(client_files_default, 't' + prefix, hash_encoded + '.thumbnail') with open(file_path, 'wb') as f: f.write(EXAMPLE_FILE) with open(thumbnail_path, 'wb') as f: f.write(EXAMPLE_THUMBNAIL) local_booru_manager = HG.client_controller.local_booru_manager # self._test_local_booru_requests(connection, share_key, hashes[0], 404) # info = {} info['name'] = 'name' info['text'] = 'text' info['timeout'] = 0 info['hashes'] = hashes file_info_manager = ClientMediaManagers.FileInfoManager( 1, hashes[0], 500, HC.IMAGE_JPEG, 640, 480) notes_manager = ClientMediaManagers.NotesManager({}) file_viewing_stats_manager = ClientMediaManagers.FileViewingStatsManager.STATICGenerateEmptyManager( ) media_results = [ ClientMediaResult.MediaResult( file_info_manager, ClientMediaManagers.TagsManager({}, {}), ClientMediaManagers.LocationsManager(dict(), dict(), set(), set()), ClientMediaManagers.RatingsManager({}), notes_manager, file_viewing_stats_manager) for hash in hashes ] HG.test_controller.SetRead('local_booru_share_keys', [share_key]) HG.test_controller.SetRead('local_booru_share', info) HG.test_controller.SetRead('media_results', media_results) local_booru_manager.RefreshShares() # self._test_local_booru_requests(connection, share_key, hashes[0], 404) # info['timeout'] = None HG.test_controller.SetRead('local_booru_share', info) local_booru_manager.RefreshShares() # self._test_local_booru_requests(connection, share_key, hashes[0], 200) # HG.test_controller.SetRead('local_booru_share_keys', []) local_booru_manager.RefreshShares() # self._test_local_booru_requests(connection, share_key, hashes[0], 404)
def test_SERIALISABLE_TYPE_DUPLICATE_ACTION_OPTIONS(self): def test(obj, dupe_obj): self.assertEqual(obj.ToTuple(), dupe_obj.ToTuple()) duplicate_action_options_delete_and_move = ClientDuplicates.DuplicateActionOptions( [(CC.DEFAULT_LOCAL_TAG_SERVICE_KEY, HC.CONTENT_MERGE_ACTION_MOVE, ClientTags.TagFilter())], [(TC.LOCAL_RATING_LIKE_SERVICE_KEY, HC.CONTENT_MERGE_ACTION_MOVE), (TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY, HC.CONTENT_MERGE_ACTION_MOVE)]) duplicate_action_options_copy = ClientDuplicates.DuplicateActionOptions( [(CC.DEFAULT_LOCAL_TAG_SERVICE_KEY, HC.CONTENT_MERGE_ACTION_COPY, ClientTags.TagFilter())], [(TC.LOCAL_RATING_LIKE_SERVICE_KEY, HC.CONTENT_MERGE_ACTION_COPY), (TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY, HC.CONTENT_MERGE_ACTION_COPY)]) duplicate_action_options_merge = ClientDuplicates.DuplicateActionOptions( [(CC.DEFAULT_LOCAL_TAG_SERVICE_KEY, HC.CONTENT_MERGE_ACTION_TWO_WAY_MERGE, ClientTags.TagFilter())], [(TC.LOCAL_RATING_LIKE_SERVICE_KEY, HC.CONTENT_MERGE_ACTION_TWO_WAY_MERGE), (TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY, HC.CONTENT_MERGE_ACTION_TWO_WAY_MERGE)]) inbox = True size = 40960 mime = HC.IMAGE_JPEG width = 640 height = 480 duration = None num_frames = None has_audio = False num_words = None local_locations_manager = ClientMediaManagers.LocationsManager( {CC.LOCAL_FILE_SERVICE_KEY, CC.COMBINED_LOCAL_FILE_SERVICE_KEY}, set(), set(), set(), inbox) trash_locations_manager = ClientMediaManagers.LocationsManager( {CC.TRASH_SERVICE_KEY, CC.COMBINED_LOCAL_FILE_SERVICE_KEY}, set(), set(), set(), inbox) deleted_locations_manager = ClientMediaManagers.LocationsManager( set(), {CC.COMBINED_LOCAL_FILE_SERVICE_KEY}, set(), set(), inbox) # duplicate to generate proper dicts one_tags_manager = ClientMediaManagers.TagsManager( { CC.DEFAULT_LOCAL_TAG_SERVICE_KEY: { HC.CONTENT_STATUS_CURRENT: {'one'} } }, { CC.DEFAULT_LOCAL_TAG_SERVICE_KEY: { HC.CONTENT_STATUS_CURRENT: {'one'} } }).Duplicate() two_tags_manager = ClientMediaManagers.TagsManager( { CC.DEFAULT_LOCAL_TAG_SERVICE_KEY: { HC.CONTENT_STATUS_CURRENT: {'two'} } }, { CC.DEFAULT_LOCAL_TAG_SERVICE_KEY: { HC.CONTENT_STATUS_CURRENT: {'two'} } }).Duplicate() substantial_tags_manager = ClientMediaManagers.TagsManager( { CC.DEFAULT_LOCAL_TAG_SERVICE_KEY: { HC.CONTENT_STATUS_CURRENT: {'test tag', 'series:namespaced test tag'} } }, { CC.DEFAULT_LOCAL_TAG_SERVICE_KEY: { HC.CONTENT_STATUS_CURRENT: {'test tag', 'series:namespaced test tag'} } }).Duplicate() empty_tags_manager = ClientMediaManagers.TagsManager({}, {}).Duplicate() one_ratings_manager = ClientMediaManagers.RatingsManager({ TC.LOCAL_RATING_LIKE_SERVICE_KEY: 1.0, TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY: 0.8 }) two_ratings_manager = ClientMediaManagers.RatingsManager({ TC.LOCAL_RATING_LIKE_SERVICE_KEY: 0.0, TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY: 0.6 }) substantial_ratings_manager = ClientMediaManagers.RatingsManager({ TC.LOCAL_RATING_LIKE_SERVICE_KEY: 1.0, TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY: 0.8 }) empty_ratings_manager = ClientMediaManagers.RatingsManager({}) notes_manager = ClientMediaManagers.NotesManager({}) file_viewing_stats_manager = ClientMediaManagers.FileViewingStatsManager.STATICGenerateEmptyManager( ) # local_hash_has_values = HydrusData.GenerateKey() file_info_manager = ClientMediaManagers.FileInfoManager( 1, local_hash_has_values, size, mime, width, height, duration, num_frames, has_audio, num_words) media_result = ClientMediaResult.MediaResult( file_info_manager, substantial_tags_manager, local_locations_manager, substantial_ratings_manager, notes_manager, file_viewing_stats_manager) local_media_has_values = ClientMedia.MediaSingleton(media_result) # other_local_hash_has_values = HydrusData.GenerateKey() file_info_manager = ClientMediaManagers.FileInfoManager( 2, other_local_hash_has_values, size, mime, width, height, duration, num_frames, has_audio, num_words) media_result = ClientMediaResult.MediaResult( file_info_manager, substantial_tags_manager, local_locations_manager, substantial_ratings_manager, notes_manager, file_viewing_stats_manager) other_local_media_has_values = ClientMedia.MediaSingleton(media_result) # local_hash_empty = HydrusData.GenerateKey() file_info_manager = ClientMediaManagers.FileInfoManager( 3, local_hash_empty, size, mime, width, height, duration, num_frames, has_audio, num_words) media_result = ClientMediaResult.MediaResult( file_info_manager, empty_tags_manager, local_locations_manager, empty_ratings_manager, notes_manager, file_viewing_stats_manager) local_media_empty = ClientMedia.MediaSingleton(media_result) # trashed_hash_empty = HydrusData.GenerateKey() file_info_manager = ClientMediaManagers.FileInfoManager( 4, trashed_hash_empty, size, mime, width, height, duration, num_frames, has_audio, num_words) media_result = ClientMediaResult.MediaResult( file_info_manager, empty_tags_manager, trash_locations_manager, empty_ratings_manager, notes_manager, file_viewing_stats_manager) trashed_media_empty = ClientMedia.MediaSingleton(media_result) # deleted_hash_empty = HydrusData.GenerateKey() file_info_manager = ClientMediaManagers.FileInfoManager( 5, deleted_hash_empty, size, mime, width, height, duration, num_frames, has_audio, num_words) media_result = ClientMediaResult.MediaResult( file_info_manager, empty_tags_manager, deleted_locations_manager, empty_ratings_manager, notes_manager, file_viewing_stats_manager) deleted_media_empty = ClientMedia.MediaSingleton(media_result) # one_hash = HydrusData.GenerateKey() file_info_manager = ClientMediaManagers.FileInfoManager( 6, one_hash, size, mime, width, height, duration, num_frames, has_audio, num_words) media_result = ClientMediaResult.MediaResult( file_info_manager, one_tags_manager, local_locations_manager, one_ratings_manager, notes_manager, file_viewing_stats_manager) one_media = ClientMedia.MediaSingleton(media_result) # two_hash = HydrusData.GenerateKey() file_info_manager = ClientMediaManagers.FileInfoManager( 7, two_hash, size, mime, width, height, duration, num_frames, has_audio, num_words) media_result = ClientMediaResult.MediaResult( file_info_manager, two_tags_manager, local_locations_manager, two_ratings_manager, notes_manager, file_viewing_stats_manager) two_media = ClientMedia.MediaSingleton(media_result) # self._dump_and_load_and_test(duplicate_action_options_delete_and_move, test) self._dump_and_load_and_test(duplicate_action_options_copy, test) self._dump_and_load_and_test(duplicate_action_options_merge, test) # def assertSCUEqual(one, two): self.assertEqual( TC.ConvertServiceKeysToContentUpdatesToComparable(one), TC.ConvertServiceKeysToContentUpdatesToComparable(two)) file_deletion_reason = 'test delete' # result = duplicate_action_options_delete_and_move.ProcessPairIntoContentUpdates( local_media_has_values, local_media_empty, delete_second=True, file_deletion_reason=file_deletion_reason) scu = {} scu[CC.LOCAL_FILE_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_FILES, HC.CONTENT_UPDATE_DELETE, {local_hash_empty}, reason=file_deletion_reason) ] assertSCUEqual(result, scu) # result = duplicate_action_options_delete_and_move.ProcessPairIntoContentUpdates( local_media_has_values, trashed_media_empty, delete_second=True, file_deletion_reason=file_deletion_reason) scu = {} scu[CC.TRASH_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_FILES, HC.CONTENT_UPDATE_DELETE, {trashed_hash_empty}, reason=file_deletion_reason) ] assertSCUEqual(result, scu) # result = duplicate_action_options_delete_and_move.ProcessPairIntoContentUpdates( local_media_has_values, deleted_media_empty, delete_second=True, file_deletion_reason=file_deletion_reason) self.assertEqual(result, {}) # result = duplicate_action_options_delete_and_move.ProcessPairIntoContentUpdates( local_media_has_values, other_local_media_has_values, delete_second=True, file_deletion_reason=file_deletion_reason) scu = {} scu[CC.DEFAULT_LOCAL_TAG_SERVICE_KEY] = [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_DELETE, ('test tag', {other_local_hash_has_values})), HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_DELETE, ('series:namespaced test tag', {other_local_hash_has_values})) ] scu[TC.LOCAL_RATING_LIKE_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, (None, {other_local_hash_has_values})) ] scu[TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, (None, {other_local_hash_has_values})) ] scu[CC.LOCAL_FILE_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_FILES, HC.CONTENT_UPDATE_DELETE, {other_local_hash_has_values}, reason=file_deletion_reason) ] assertSCUEqual(result, scu) # result = duplicate_action_options_delete_and_move.ProcessPairIntoContentUpdates( local_media_empty, other_local_media_has_values, delete_second=True, file_deletion_reason=file_deletion_reason) scu = {} scu[CC.DEFAULT_LOCAL_TAG_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('test tag', {local_hash_empty})), HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('series:namespaced test tag', {local_hash_empty})), HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_DELETE, ('test tag', {other_local_hash_has_values})), HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_DELETE, ('series:namespaced test tag', {other_local_hash_has_values})) ] scu[TC.LOCAL_RATING_LIKE_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, (1.0, {local_hash_empty})), HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, (None, {other_local_hash_has_values})) ] scu[TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, (0.8, {local_hash_empty})), HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, (None, {other_local_hash_has_values})) ] scu[CC.LOCAL_FILE_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_FILES, HC.CONTENT_UPDATE_DELETE, {other_local_hash_has_values}, reason=file_deletion_reason) ] assertSCUEqual(result, scu) # # result = duplicate_action_options_copy.ProcessPairIntoContentUpdates( local_media_has_values, local_media_empty, file_deletion_reason=file_deletion_reason) self.assertEqual(result, {}) # result = duplicate_action_options_copy.ProcessPairIntoContentUpdates( local_media_empty, other_local_media_has_values, file_deletion_reason=file_deletion_reason) scu = {} scu[CC.DEFAULT_LOCAL_TAG_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('test tag', {local_hash_empty})), HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('series:namespaced test tag', {local_hash_empty})) ] scu[TC.LOCAL_RATING_LIKE_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, (1.0, {local_hash_empty})) ] scu[TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, (0.8, {local_hash_empty})) ] assertSCUEqual(result, scu) # # result = duplicate_action_options_merge.ProcessPairIntoContentUpdates( local_media_has_values, local_media_empty, file_deletion_reason=file_deletion_reason) scu = {} scu[CC.DEFAULT_LOCAL_TAG_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('test tag', {local_hash_empty})), HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('series:namespaced test tag', {local_hash_empty})) ] scu[TC.LOCAL_RATING_LIKE_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, (1.0, {local_hash_empty})) ] scu[TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, (0.8, {local_hash_empty})) ] assertSCUEqual(result, scu) # result = duplicate_action_options_merge.ProcessPairIntoContentUpdates( local_media_empty, other_local_media_has_values, file_deletion_reason=file_deletion_reason) scu = {} scu[CC.DEFAULT_LOCAL_TAG_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('test tag', {local_hash_empty})), HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('series:namespaced test tag', {local_hash_empty})) ] scu[TC.LOCAL_RATING_LIKE_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, (1.0, {local_hash_empty})) ] scu[TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, (0.8, {local_hash_empty})) ] assertSCUEqual(result, scu) # result = duplicate_action_options_merge.ProcessPairIntoContentUpdates( one_media, two_media, file_deletion_reason=file_deletion_reason) scu = {} scu[CC.DEFAULT_LOCAL_TAG_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('one', {two_hash})), HydrusData.ContentUpdate(HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ('two', {one_hash})) ] scu[TC.LOCAL_RATING_LIKE_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, (1.0, {two_hash})) ] scu[TC.LOCAL_RATING_NUMERICAL_SERVICE_KEY] = [ HydrusData.ContentUpdate(HC.CONTENT_TYPE_RATINGS, HC.CONTENT_UPDATE_ADD, (0.8, {two_hash})) ] assertSCUEqual(result, scu)