2013-07-17 20:56:13 +00:00
import collections
import HydrusConstants as HC
import HydrusTags
import os
import TestConstants
import unittest
2015-03-25 22:04:19 +00:00
import HydrusData
2015-08-05 18:42:35 +00:00
import ClientCaches
2015-06-03 21:05:13 +00:00
import ClientConstants as CC
2015-08-05 18:42:35 +00:00
import ClientData
import ClientMedia
2015-03-25 22:04:19 +00:00
import ClientSearch
2017-05-10 21:33:58 +00:00
import HydrusGlobals as HG
2013-07-17 20:56:13 +00:00
class TestMergeTagsManagers ( unittest . TestCase ) :
def test_merge ( self ) :
2015-07-01 22:02:07 +00:00
first = HydrusData . GenerateKey ( )
second = HydrusData . GenerateKey ( )
third = HydrusData . GenerateKey ( )
2013-07-17 20:56:13 +00:00
#
2015-03-25 22:04:19 +00:00
service_keys_to_statuses_to_tags = collections . defaultdict ( HydrusData . default_dict_set )
2013-07-17 20:56:13 +00:00
2017-03-02 02:14:56 +00:00
service_keys_to_statuses_to_tags [ first ] [ HC . CONTENT_STATUS_CURRENT ] = { ' current_1 ' , ' series:blame! ' }
2013-07-17 20:56:13 +00:00
2017-03-02 02:14:56 +00:00
service_keys_to_statuses_to_tags [ second ] [ HC . CONTENT_STATUS_CURRENT ] = { ' current_duplicate_1 ' , ' character:cibo ' }
service_keys_to_statuses_to_tags [ second ] [ HC . CONTENT_STATUS_DELETED ] = { ' current_1 ' }
service_keys_to_statuses_to_tags [ second ] [ HC . CONTENT_STATUS_PENDING ] = { ' pending_1 ' , ' creator:tsutomu nihei ' }
service_keys_to_statuses_to_tags [ second ] [ HC . CONTENT_STATUS_PETITIONED ] = { ' petitioned_1 ' }
2013-07-17 20:56:13 +00:00
2017-03-02 02:14:56 +00:00
service_keys_to_statuses_to_tags [ third ] [ HC . CONTENT_STATUS_CURRENT ] = { ' current_duplicate ' , ' current_duplicate_1 ' }
service_keys_to_statuses_to_tags [ third ] [ HC . CONTENT_STATUS_PENDING ] = { ' volume:3 ' }
2013-07-17 20:56:13 +00:00
2015-08-05 18:42:35 +00:00
tags_manager_1 = ClientMedia . TagsManager ( service_keys_to_statuses_to_tags )
2013-07-17 20:56:13 +00:00
#
2015-03-25 22:04:19 +00:00
service_keys_to_statuses_to_tags = collections . defaultdict ( HydrusData . default_dict_set )
2013-07-17 20:56:13 +00:00
2017-03-02 02:14:56 +00:00
service_keys_to_statuses_to_tags [ first ] [ HC . CONTENT_STATUS_CURRENT ] = { ' current_2 ' , ' series:blame! ' , ' chapter:1 ' }
service_keys_to_statuses_to_tags [ first ] [ HC . CONTENT_STATUS_DELETED ] = { ' deleted_2 ' }
2013-07-17 20:56:13 +00:00
2017-03-02 02:14:56 +00:00
service_keys_to_statuses_to_tags [ second ] [ HC . CONTENT_STATUS_CURRENT ] = { ' current_duplicate ' }
service_keys_to_statuses_to_tags [ second ] [ HC . CONTENT_STATUS_PENDING ] = { ' architecture ' , ' chapter:2 ' }
2013-07-17 20:56:13 +00:00
2017-03-02 02:14:56 +00:00
service_keys_to_statuses_to_tags [ third ] [ HC . CONTENT_STATUS_CURRENT ] = { ' current_duplicate ' }
2013-07-17 20:56:13 +00:00
2015-08-05 18:42:35 +00:00
tags_manager_2 = ClientMedia . TagsManager ( service_keys_to_statuses_to_tags )
2013-07-17 20:56:13 +00:00
#
2015-03-25 22:04:19 +00:00
service_keys_to_statuses_to_tags = collections . defaultdict ( HydrusData . default_dict_set )
2013-07-17 20:56:13 +00:00
2017-03-02 02:14:56 +00:00
service_keys_to_statuses_to_tags [ second ] [ HC . CONTENT_STATUS_CURRENT ] = { ' page:4 ' , ' page:5 ' }
service_keys_to_statuses_to_tags [ second ] [ HC . CONTENT_STATUS_PENDING ] = { ' title:double page spread ' }
2013-07-17 20:56:13 +00:00
2015-08-05 18:42:35 +00:00
tags_manager_3 = ClientMedia . TagsManager ( service_keys_to_statuses_to_tags )
2013-07-17 20:56:13 +00:00
#
tags_managers = ( tags_manager_1 , tags_manager_2 , tags_manager_3 )
2015-08-05 18:42:35 +00:00
tags_manager = ClientMedia . MergeTagsManagers ( tags_managers )
2013-07-17 20:56:13 +00:00
#
2015-01-21 22:49:58 +00:00
result = { ' creator ' : { ' tsutomu nihei ' } , ' series ' : { ' blame! ' } , ' title ' : { ' double page spread ' } , ' volume ' : { ' 3 ' } , ' chapter ' : { ' 1 ' , ' 2 ' } , ' page ' : { ' 4 ' , ' 5 ' } }
2013-07-31 21:26:38 +00:00
self . assertEqual ( tags_manager . GetCombinedNamespaces ( ( ' creator ' , ' series ' , ' title ' , ' volume ' , ' chapter ' , ' page ' ) ) , result )
2013-07-17 20:56:13 +00:00
self . assertEqual ( tags_manager . GetNamespaceSlice ( ( ' character ' , ) ) , frozenset ( { ' character:cibo ' } ) )
class TestTagsManager ( unittest . TestCase ) :
@classmethod
2017-04-05 21:16:40 +00:00
def setUpClass ( cls ) :
2013-07-17 20:56:13 +00:00
2017-04-05 21:16:40 +00:00
cls . _first_key = HydrusData . GenerateKey ( )
cls . _second_key = HydrusData . GenerateKey ( )
cls . _third_key = HydrusData . GenerateKey ( )
2013-07-17 20:56:13 +00:00
2015-03-25 22:04:19 +00:00
service_keys_to_statuses_to_tags = collections . defaultdict ( HydrusData . default_dict_set )
2013-07-17 20:56:13 +00:00
2017-04-05 21:16:40 +00:00
service_keys_to_statuses_to_tags [ cls . _first_key ] [ HC . CONTENT_STATUS_CURRENT ] = { ' current ' , u ' \u2835 ' , ' creator:tsutomu nihei ' , ' series:blame! ' , ' title:test title ' , ' volume:3 ' , ' chapter:2 ' , ' page:1 ' }
service_keys_to_statuses_to_tags [ cls . _first_key ] [ HC . CONTENT_STATUS_DELETED ] = { ' deleted ' }
2013-07-17 20:56:13 +00:00
2017-04-05 21:16:40 +00:00
service_keys_to_statuses_to_tags [ cls . _second_key ] [ HC . CONTENT_STATUS_CURRENT ] = { ' deleted ' , u ' \u2835 ' }
service_keys_to_statuses_to_tags [ cls . _second_key ] [ HC . CONTENT_STATUS_DELETED ] = { ' current ' }
service_keys_to_statuses_to_tags [ cls . _second_key ] [ HC . CONTENT_STATUS_PENDING ] = { ' pending ' }
service_keys_to_statuses_to_tags [ cls . _second_key ] [ HC . CONTENT_STATUS_PETITIONED ] = { ' petitioned ' }
2013-07-17 20:56:13 +00:00
2017-04-05 21:16:40 +00:00
service_keys_to_statuses_to_tags [ cls . _third_key ] [ HC . CONTENT_STATUS_CURRENT ] = { ' petitioned ' }
service_keys_to_statuses_to_tags [ cls . _third_key ] [ HC . CONTENT_STATUS_DELETED ] = { ' pending ' }
2013-07-17 20:56:13 +00:00
2017-04-05 21:16:40 +00:00
cls . _tags_manager = ClientMedia . TagsManager ( service_keys_to_statuses_to_tags )
2013-07-17 20:56:13 +00:00
2017-04-05 21:16:40 +00:00
cls . _service_keys_to_statuses_to_tags = service_keys_to_statuses_to_tags
2013-07-17 20:56:13 +00:00
#
2017-04-05 21:16:40 +00:00
cls . _pending_service_key = HydrusData . GenerateKey ( )
cls . _content_update_service_key = HydrusData . GenerateKey ( )
cls . _reset_service_key = HydrusData . GenerateKey ( )
2013-07-17 20:56:13 +00:00
2015-03-25 22:04:19 +00:00
other_service_keys_to_statuses_to_tags = collections . defaultdict ( HydrusData . default_dict_set )
2013-07-17 20:56:13 +00:00
2017-04-05 21:16:40 +00:00
other_service_keys_to_statuses_to_tags [ cls . _pending_service_key ] [ HC . CONTENT_STATUS_PENDING ] = { ' pending ' }
other_service_keys_to_statuses_to_tags [ cls . _pending_service_key ] [ HC . CONTENT_STATUS_PETITIONED ] = { ' petitioned ' }
2013-07-17 20:56:13 +00:00
2017-04-05 21:16:40 +00:00
other_service_keys_to_statuses_to_tags [ cls . _reset_service_key ] [ HC . CONTENT_STATUS_CURRENT ] = { ' reset_current ' }
other_service_keys_to_statuses_to_tags [ cls . _reset_service_key ] [ HC . CONTENT_STATUS_DELETED ] = { ' reset_deleted ' }
other_service_keys_to_statuses_to_tags [ cls . _reset_service_key ] [ HC . CONTENT_STATUS_PENDING ] = { ' reset_pending ' }
other_service_keys_to_statuses_to_tags [ cls . _reset_service_key ] [ HC . CONTENT_STATUS_PETITIONED ] = { ' reset_petitioned ' }
2013-07-17 20:56:13 +00:00
2017-04-05 21:16:40 +00:00
cls . _other_tags_manager = ClientMedia . TagsManager ( other_service_keys_to_statuses_to_tags )
2013-07-17 20:56:13 +00:00
2017-04-05 21:16:40 +00:00
cls . _other_service_keys_to_statuses_to_tags = other_service_keys_to_statuses_to_tags
2013-07-17 20:56:13 +00:00
def test_get_cstvcp ( self ) :
2015-01-21 22:49:58 +00:00
result = { ' creator ' : { ' tsutomu nihei ' } , ' series ' : { ' blame! ' } , ' title ' : { ' test title ' } , ' volume ' : { ' 3 ' } , ' chapter ' : { ' 2 ' } , ' page ' : { ' 1 ' } }
2013-07-31 21:26:38 +00:00
self . assertEqual ( self . _tags_manager . GetCombinedNamespaces ( ( ' creator ' , ' series ' , ' title ' , ' volume ' , ' chapter ' , ' page ' ) ) , result )
2013-07-17 20:56:13 +00:00
def test_delete_pending ( self ) :
2014-08-27 22:15:22 +00:00
self . assertEqual ( self . _other_tags_manager . GetPending ( self . _pending_service_key ) , { ' pending ' } )
self . assertEqual ( self . _other_tags_manager . GetPetitioned ( self . _pending_service_key ) , { ' petitioned ' } )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . _other_tags_manager . DeletePending ( self . _pending_service_key )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . assertEqual ( self . _other_tags_manager . GetPending ( self . _pending_service_key ) , set ( ) )
self . assertEqual ( self . _other_tags_manager . GetPetitioned ( self . _pending_service_key ) , set ( ) )
2013-07-17 20:56:13 +00:00
def test_get_current ( self ) :
2014-08-27 22:15:22 +00:00
self . assertEqual ( self . _tags_manager . GetCurrent ( self . _first_key ) , { ' current ' , u ' \u2835 ' , ' creator:tsutomu nihei ' , ' series:blame! ' , ' title:test title ' , ' volume:3 ' , ' chapter:2 ' , ' page:1 ' } )
self . assertEqual ( self . _tags_manager . GetCurrent ( self . _second_key ) , { ' deleted ' , u ' \u2835 ' } )
2015-01-21 22:49:58 +00:00
self . assertEqual ( self . _tags_manager . GetCurrent ( self . _third_key ) , { ' petitioned ' } )
2013-07-17 20:56:13 +00:00
2015-01-21 22:49:58 +00:00
self . assertEqual ( self . _tags_manager . GetCurrent ( ) , { ' current ' , ' deleted ' , u ' \u2835 ' , ' creator:tsutomu nihei ' , ' series:blame! ' , ' title:test title ' , ' volume:3 ' , ' chapter:2 ' , ' page:1 ' , ' petitioned ' } )
2013-07-17 20:56:13 +00:00
def test_get_deleted ( self ) :
2014-08-27 22:15:22 +00:00
self . assertEqual ( self . _tags_manager . GetDeleted ( self . _first_key ) , { ' deleted ' } )
self . assertEqual ( self . _tags_manager . GetDeleted ( self . _second_key ) , { ' current ' } )
self . assertEqual ( self . _tags_manager . GetDeleted ( self . _third_key ) , { ' pending ' } )
2013-07-17 20:56:13 +00:00
2015-11-11 21:20:41 +00:00
self . assertEqual ( self . _tags_manager . GetDeleted ( ) , { ' deleted ' , ' current ' , ' pending ' } )
2013-07-17 20:56:13 +00:00
def test_get_namespace_slice ( self ) :
self . assertEqual ( self . _tags_manager . GetNamespaceSlice ( ( ' creator ' , ' series ' ) ) , frozenset ( { ' creator:tsutomu nihei ' , ' series:blame! ' } ) )
self . assertEqual ( self . _tags_manager . GetNamespaceSlice ( ( ) ) , frozenset ( ) )
def test_get_num_tags ( self ) :
2014-08-27 22:15:22 +00:00
self . assertEqual ( self . _tags_manager . GetNumTags ( self . _first_key , include_current_tags = False , include_pending_tags = False ) , 0 )
self . assertEqual ( self . _tags_manager . GetNumTags ( self . _first_key , include_current_tags = True , include_pending_tags = False ) , 8 )
self . assertEqual ( self . _tags_manager . GetNumTags ( self . _first_key , include_current_tags = False , include_pending_tags = True ) , 0 )
self . assertEqual ( self . _tags_manager . GetNumTags ( self . _first_key , include_current_tags = True , include_pending_tags = True ) , 8 )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . assertEqual ( self . _tags_manager . GetNumTags ( self . _second_key , include_current_tags = False , include_pending_tags = False ) , 0 )
self . assertEqual ( self . _tags_manager . GetNumTags ( self . _second_key , include_current_tags = True , include_pending_tags = False ) , 2 )
self . assertEqual ( self . _tags_manager . GetNumTags ( self . _second_key , include_current_tags = False , include_pending_tags = True ) , 1 )
self . assertEqual ( self . _tags_manager . GetNumTags ( self . _second_key , include_current_tags = True , include_pending_tags = True ) , 3 )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . assertEqual ( self . _tags_manager . GetNumTags ( self . _third_key , include_current_tags = False , include_pending_tags = False ) , 0 )
2015-01-21 22:49:58 +00:00
self . assertEqual ( self . _tags_manager . GetNumTags ( self . _third_key , include_current_tags = True , include_pending_tags = False ) , 1 )
2014-08-27 22:15:22 +00:00
self . assertEqual ( self . _tags_manager . GetNumTags ( self . _third_key , include_current_tags = False , include_pending_tags = True ) , 0 )
2015-01-21 22:49:58 +00:00
self . assertEqual ( self . _tags_manager . GetNumTags ( self . _third_key , include_current_tags = True , include_pending_tags = True ) , 1 )
2013-07-17 20:56:13 +00:00
2015-06-03 21:05:13 +00:00
self . assertEqual ( self . _tags_manager . GetNumTags ( CC . COMBINED_TAG_SERVICE_KEY , include_current_tags = False , include_pending_tags = False ) , 0 )
self . assertEqual ( self . _tags_manager . GetNumTags ( CC . COMBINED_TAG_SERVICE_KEY , include_current_tags = True , include_pending_tags = False ) , 10 )
self . assertEqual ( self . _tags_manager . GetNumTags ( CC . COMBINED_TAG_SERVICE_KEY , include_current_tags = False , include_pending_tags = True ) , 1 )
self . assertEqual ( self . _tags_manager . GetNumTags ( CC . COMBINED_TAG_SERVICE_KEY , include_current_tags = True , include_pending_tags = True ) , 11 )
2013-07-17 20:56:13 +00:00
def test_get_pending ( self ) :
2014-08-27 22:15:22 +00:00
self . assertEqual ( self . _tags_manager . GetPending ( self . _first_key ) , set ( ) )
self . assertEqual ( self . _tags_manager . GetPending ( self . _second_key ) , { ' pending ' } )
self . assertEqual ( self . _tags_manager . GetPending ( self . _third_key ) , set ( ) )
2013-07-17 20:56:13 +00:00
self . assertEqual ( self . _tags_manager . GetPending ( ) , { ' pending ' } )
def test_get_petitioned ( self ) :
2014-08-27 22:15:22 +00:00
self . assertEqual ( self . _tags_manager . GetPetitioned ( self . _first_key ) , set ( ) )
self . assertEqual ( self . _tags_manager . GetPetitioned ( self . _second_key ) , { ' petitioned ' } )
self . assertEqual ( self . _tags_manager . GetPetitioned ( self . _third_key ) , set ( ) )
2013-07-17 20:56:13 +00:00
2015-11-11 21:20:41 +00:00
self . assertEqual ( self . _tags_manager . GetPetitioned ( ) , { ' petitioned ' } )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
def test_get_service_keys_to_statuses_to_tags ( self ) :
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
s = self . _tags_manager . GetServiceKeysToStatusesToTags ( )
2013-10-09 18:13:42 +00:00
2014-08-27 22:15:22 +00:00
self . assertEqual ( s [ self . _first_key ] , self . _service_keys_to_statuses_to_tags [ self . _first_key ] )
self . assertEqual ( s [ self . _second_key ] , self . _service_keys_to_statuses_to_tags [ self . _second_key ] )
self . assertEqual ( s [ self . _third_key ] , self . _service_keys_to_statuses_to_tags [ self . _third_key ] )
2013-07-17 20:56:13 +00:00
def test_get_statuses_to_tags ( self ) :
2014-08-27 22:15:22 +00:00
self . assertEqual ( self . _tags_manager . GetStatusesToTags ( self . _first_key ) , self . _service_keys_to_statuses_to_tags [ self . _first_key ] )
self . assertEqual ( self . _tags_manager . GetStatusesToTags ( self . _second_key ) , self . _service_keys_to_statuses_to_tags [ self . _second_key ] )
self . assertEqual ( self . _tags_manager . GetStatusesToTags ( self . _third_key ) , self . _service_keys_to_statuses_to_tags [ self . _third_key ] )
2013-07-17 20:56:13 +00:00
def test_has_tag ( self ) :
self . assertTrue ( self . _tags_manager . HasTag ( u ' \u2835 ' ) )
self . assertFalse ( self . _tags_manager . HasTag ( ' not_exist ' ) )
def test_process_content_update ( self ) :
2015-07-01 22:02:07 +00:00
hashes = { HydrusData . GenerateKey ( ) for i in range ( 6 ) }
2013-07-17 20:56:13 +00:00
#
2014-08-27 22:15:22 +00:00
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 ( ) )
2013-07-17 20:56:13 +00:00
self . assertNotIn ( ' hello ' , self . _other_tags_manager . GetCurrent ( ) )
self . assertNotIn ( ' hello ' , self . _other_tags_manager . GetPending ( ) )
#
2015-10-14 21:02:25 +00:00
content_update = HydrusData . ContentUpdate ( HC . CONTENT_TYPE_MAPPINGS , HC . CONTENT_UPDATE_DELETE , ( ' hello ' , hashes ) )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . _other_tags_manager . ProcessContentUpdate ( self . _content_update_service_key , content_update )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
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 ( ) )
2013-07-17 20:56:13 +00:00
self . assertNotIn ( ' hello ' , self . _other_tags_manager . GetCurrent ( ) )
self . assertNotIn ( ' hello ' , self . _other_tags_manager . GetPending ( ) )
#
2015-10-14 21:02:25 +00:00
content_update = HydrusData . ContentUpdate ( HC . CONTENT_TYPE_MAPPINGS , HC . CONTENT_UPDATE_PEND , ( ' hello ' , hashes ) )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . _other_tags_manager . ProcessContentUpdate ( self . _content_update_service_key , content_update )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
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 ( ) )
2013-07-17 20:56:13 +00:00
self . assertNotIn ( ' hello ' , self . _other_tags_manager . GetCurrent ( ) )
self . assertIn ( ' hello ' , self . _other_tags_manager . GetPending ( ) )
#
2015-10-14 21:02:25 +00:00
content_update = HydrusData . ContentUpdate ( HC . CONTENT_TYPE_MAPPINGS , HC . CONTENT_UPDATE_RESCIND_PEND , ( ' hello ' , hashes ) )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . _other_tags_manager . ProcessContentUpdate ( self . _content_update_service_key , content_update )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
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 ( ) )
2013-07-17 20:56:13 +00:00
self . assertNotIn ( ' hello ' , self . _other_tags_manager . GetCurrent ( ) )
self . assertNotIn ( ' hello ' , self . _other_tags_manager . GetPending ( ) )
#
2015-10-14 21:02:25 +00:00
content_update = HydrusData . ContentUpdate ( HC . CONTENT_TYPE_MAPPINGS , HC . CONTENT_UPDATE_PEND , ( ' hello ' , hashes ) )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . _other_tags_manager . ProcessContentUpdate ( self . _content_update_service_key , content_update )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
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 ( ) )
2013-07-17 20:56:13 +00:00
self . assertNotIn ( ' hello ' , self . _other_tags_manager . GetCurrent ( ) )
self . assertIn ( ' hello ' , self . _other_tags_manager . GetPending ( ) )
#
2015-10-14 21:02:25 +00:00
content_update = HydrusData . ContentUpdate ( HC . CONTENT_TYPE_MAPPINGS , HC . CONTENT_UPDATE_ADD , ( ' hello ' , hashes ) )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . _other_tags_manager . ProcessContentUpdate ( self . _content_update_service_key , content_update )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
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 ( ) )
2013-07-17 20:56:13 +00:00
self . assertIn ( ' hello ' , self . _other_tags_manager . GetCurrent ( ) )
self . assertNotIn ( ' hello ' , self . _other_tags_manager . GetPending ( ) )
#
2015-10-14 21:02:25 +00:00
content_update = HydrusData . ContentUpdate ( HC . CONTENT_TYPE_MAPPINGS , HC . CONTENT_UPDATE_PETITION , ( ' hello ' , hashes , ' reason ' ) )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . _other_tags_manager . ProcessContentUpdate ( self . _content_update_service_key , content_update )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
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 ' } )
2013-07-17 20:56:13 +00:00
self . assertIn ( ' hello ' , self . _other_tags_manager . GetCurrent ( ) )
self . assertNotIn ( ' hello ' , self . _other_tags_manager . GetPending ( ) )
#
2015-10-14 21:02:25 +00:00
content_update = HydrusData . ContentUpdate ( HC . CONTENT_TYPE_MAPPINGS , HC . CONTENT_UPDATE_RESCIND_PETITION , ( ' hello ' , hashes ) )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . _other_tags_manager . ProcessContentUpdate ( self . _content_update_service_key , content_update )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
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 ( ) )
2013-07-17 20:56:13 +00:00
self . assertIn ( ' hello ' , self . _other_tags_manager . GetCurrent ( ) )
self . assertNotIn ( ' hello ' , self . _other_tags_manager . GetPending ( ) )
#
2015-10-14 21:02:25 +00:00
content_update = HydrusData . ContentUpdate ( HC . CONTENT_TYPE_MAPPINGS , HC . CONTENT_UPDATE_PETITION , ( ' hello ' , hashes , ' reason ' ) )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . _other_tags_manager . ProcessContentUpdate ( self . _content_update_service_key , content_update )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
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 ' } )
2013-07-17 20:56:13 +00:00
self . assertIn ( ' hello ' , self . _other_tags_manager . GetCurrent ( ) )
self . assertNotIn ( ' hello ' , self . _other_tags_manager . GetPending ( ) )
#
2015-10-14 21:02:25 +00:00
content_update = HydrusData . ContentUpdate ( HC . CONTENT_TYPE_MAPPINGS , HC . CONTENT_UPDATE_DELETE , ( ' hello ' , hashes ) )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . _other_tags_manager . ProcessContentUpdate ( self . _content_update_service_key , content_update )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
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 ( ) )
2013-07-17 20:56:13 +00:00
self . assertNotIn ( ' hello ' , self . _other_tags_manager . GetCurrent ( ) )
self . assertNotIn ( ' hello ' , self . _other_tags_manager . GetPending ( ) )
def test_reset_service ( self ) :
2014-08-27 22:15:22 +00:00
self . assertEqual ( self . _other_tags_manager . GetCurrent ( self . _reset_service_key ) , { ' reset_current ' } )
self . assertEqual ( self . _other_tags_manager . GetDeleted ( self . _reset_service_key ) , { ' reset_deleted ' } )
self . assertEqual ( self . _other_tags_manager . GetPending ( self . _reset_service_key ) , { ' reset_pending ' } )
self . assertEqual ( self . _other_tags_manager . GetPetitioned ( self . _reset_service_key ) , { ' reset_petitioned ' } )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . _other_tags_manager . ResetService ( self . _reset_service_key )
2013-07-17 20:56:13 +00:00
2014-08-27 22:15:22 +00:00
self . assertEqual ( self . _other_tags_manager . GetCurrent ( self . _reset_service_key ) , set ( ) )
self . assertEqual ( self . _other_tags_manager . GetDeleted ( self . _reset_service_key ) , set ( ) )
self . assertEqual ( self . _other_tags_manager . GetPending ( self . _reset_service_key ) , set ( ) )
self . assertEqual ( self . _other_tags_manager . GetPetitioned ( self . _reset_service_key ) , set ( ) )
2013-07-17 20:56:13 +00:00
2015-01-14 22:27:55 +00:00
class TestTagObjects ( unittest . TestCase ) :
def test_predicates ( self ) :
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' tag ' )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' tag ' )
2016-06-22 20:59:24 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' tag ' , min_current_count = 1 , min_pending_count = 2 )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( with_count = False ) , u ' tag ' )
self . assertEqual ( p . GetUnicode ( with_count = True ) , u ' tag (1) (+2) ' )
2016-06-22 20:59:24 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' tag ' , False )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' -tag ' )
2016-06-22 20:59:24 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' tag ' , False , 1 , 2 )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( with_count = False ) , u ' -tag ' )
self . assertEqual ( p . GetUnicode ( with_count = True ) , u ' -tag (1) (+2) ' )
#
2018-01-31 22:58:15 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_AGE , ( ' < ' , ' delta ' , ( 1 , 2 , 3 , 4 ) ) )
2015-01-14 22:27:55 +00:00
2018-02-07 23:40:33 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:time imported: since 1 year 2 months 3 days 4 hours ago ' )
2015-01-14 22:27:55 +00:00
2018-01-31 22:58:15 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_AGE , ( u ' \u2248 ' , ' delta ' , ( 1 , 2 , 3 , 4 ) ) )
2015-01-14 22:27:55 +00:00
2018-02-07 23:40:33 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:time imported: around 1 year 2 months 3 days 4 hours ago ' )
2015-01-14 22:27:55 +00:00
2018-01-31 22:58:15 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_AGE , ( ' > ' , ' delta ' , ( 1 , 2 , 3 , 4 ) ) )
2015-01-14 22:27:55 +00:00
2018-02-07 23:40:33 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:time imported: before 1 year 2 months 3 days 4 hours ago ' )
2015-01-14 22:27:55 +00:00
2016-06-22 20:59:24 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_ARCHIVE , min_current_count = 1000 )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:archive (1,000) ' )
2015-12-30 23:44:09 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_DURATION , ( ' < ' , 200 ) )
2015-01-14 22:27:55 +00:00
2015-12-30 23:44:09 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:duration < 200 milliseconds ' )
2015-01-14 22:27:55 +00:00
2016-06-22 20:59:24 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_EVERYTHING , min_current_count = 2000 )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:everything (2,000) ' )
2017-03-02 02:14:56 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_FILE_SERVICE , ( True , HC . CONTENT_STATUS_CURRENT , CC . LOCAL_FILE_SERVICE_KEY ) )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:is currently in local files ' )
2017-03-02 02:14:56 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_FILE_SERVICE , ( False , HC . CONTENT_STATUS_PENDING , CC . LOCAL_FILE_SERVICE_KEY ) )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:is not pending to local files ' )
2015-12-30 23:44:09 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_HASH , ( ' abcd ' . decode ( ' hex ' ) , ' sha256 ' ) )
2015-01-14 22:27:55 +00:00
2015-12-30 23:44:09 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:sha256 hash is abcd ' )
2015-01-14 22:27:55 +00:00
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_HEIGHT , ( ' < ' , 2000 ) )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:height < 2,000 ' )
2016-06-22 20:59:24 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_INBOX , min_current_count = 1000 )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:inbox (1,000) ' )
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_LIMIT , 2000 )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:limit is 2,000 ' )
2016-06-22 20:59:24 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_LOCAL , min_current_count = 100 )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:local (100) ' )
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_MIME , set ( HC . IMAGES ) . intersection ( HC . SEARCHABLE_MIMES ) )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:mime is image ' )
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_MIME , ( HC . VIDEO_WEBM , ) )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:mime is video/webm ' )
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_MIME , ( HC . VIDEO_WEBM , HC . IMAGE_GIF ) )
2015-09-09 22:04:39 +00:00
2015-09-16 18:11:00 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:mime is video/webm, image/gif ' )
2015-09-09 22:04:39 +00:00
2016-06-22 20:59:24 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_NOT_LOCAL , min_current_count = 100 )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:not local (100) ' )
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_NUM_TAGS , ( ' < ' , 2 ) )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:number of tags < 2 ' )
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_NUM_WORDS , ( ' < ' , 5000 ) )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:number of words < 5,000 ' )
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_RATING , ( ' > ' , 0.2 , CC . LOCAL_FILE_SERVICE_KEY ) )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:rating for local files > 0.2 ' )
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_RATIO , ( ' = ' , 16 , 9 ) )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:ratio = 16:9 ' )
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_SIMILAR_TO , ( ' abcd ' . decode ( ' hex ' ) , 5 ) )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:similar to abcd using max hamming of 5 ' )
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_SIZE , ( ' > ' , 5 , 1048576 ) )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:size > 5MB ' )
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_UNTAGGED , HC . IMAGES )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:untagged ' )
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_SYSTEM_WIDTH , ( ' = ' , 1920 ) )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' system:width = 1,920 ' )
#
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_NAMESPACE , ' series ' )
2015-01-14 22:27:55 +00:00
2015-07-15 20:28:26 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' series:*anything* ' )
2015-01-14 22:27:55 +00:00
2016-06-22 20:59:24 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' series ' , False )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' -series ' )
#
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_WILDCARD , ' a*i:o* ' )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' a*i:o* ' )
2016-06-22 20:59:24 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' a*i:o* ' , False )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' -a*i:o* ' )
#
2015-12-09 23:16:41 +00:00
p = ClientSearch . Predicate ( HC . PREDICATE_TYPE_PARENT , ' series:game of thrones ' )
2015-01-14 22:27:55 +00:00
self . assertEqual ( p . GetUnicode ( ) , u ' series:game of thrones ' )
2013-07-17 20:56:13 +00:00
class TestTagParents ( unittest . TestCase ) :
@classmethod
2017-04-05 21:16:40 +00:00
def setUpClass ( cls ) :
2013-07-17 20:56:13 +00:00
2017-04-05 21:16:40 +00:00
cls . _first_key = HydrusData . GenerateKey ( )
cls . _second_key = HydrusData . GenerateKey ( )
cls . _third_key = HydrusData . GenerateKey ( )
2013-07-17 20:56:13 +00:00
2015-03-25 22:04:19 +00:00
first_dict = HydrusData . default_dict_set ( )
2013-07-17 20:56:13 +00:00
2017-03-02 02:14:56 +00:00
first_dict [ HC . CONTENT_STATUS_CURRENT ] = { ( ' current_a ' , ' current_b ' ) , ( ' child ' , ' mother ' ) , ( ' child ' , ' father ' ) , ( ' sister ' , ' mother ' ) , ( ' sister ' , ' father ' ) , ( ' brother ' , ' mother ' ) , ( ' brother ' , ' father ' ) , ( ' mother ' , ' grandmother ' ) , ( ' mother ' , ' grandfather ' ) , ( ' aunt ' , ' grandmother ' ) , ( ' aunt ' , ' grandfather ' ) , ( ' cousin ' , ' aunt ' ) , ( ' cousin ' , ' uncle ' ) , ( ' closed_loop ' , ' closed_loop ' ) , ( ' loop_a ' , ' loop_b ' ) , ( ' loop_b ' , ' loop_c ' ) }
first_dict [ HC . CONTENT_STATUS_DELETED ] = { ( ' deleted_a ' , ' deleted_b ' ) }
2013-07-17 20:56:13 +00:00
2015-03-25 22:04:19 +00:00
second_dict = HydrusData . default_dict_set ( )
2013-07-17 20:56:13 +00:00
2017-03-02 02:14:56 +00:00
second_dict [ HC . CONTENT_STATUS_CURRENT ] = { ( ' loop_c ' , ' loop_a ' ) }
second_dict [ HC . CONTENT_STATUS_DELETED ] = { ( ' current_a ' , ' current_b ' ) }
second_dict [ HC . CONTENT_STATUS_PENDING ] = { ( ' pending_a ' , ' pending_b ' ) }
second_dict [ HC . CONTENT_STATUS_PETITIONED ] = { ( ' petitioned_a ' , ' petitioned_b ' ) }
2013-07-17 20:56:13 +00:00
2015-03-25 22:04:19 +00:00
third_dict = HydrusData . default_dict_set ( )
2013-07-17 20:56:13 +00:00
2017-03-02 02:14:56 +00:00
third_dict [ HC . CONTENT_STATUS_CURRENT ] = { ( ' petitioned_a ' , ' petitioned_b ' ) }
third_dict [ HC . CONTENT_STATUS_DELETED ] = { ( ' pending_a ' , ' pending_b ' ) }
2013-07-17 20:56:13 +00:00
2015-03-25 22:04:19 +00:00
tag_parents = collections . defaultdict ( HydrusData . default_dict_set )
2014-08-27 22:15:22 +00:00
2017-04-05 21:16:40 +00:00
tag_parents [ cls . _first_key ] = first_dict
tag_parents [ cls . _second_key ] = second_dict
tag_parents [ cls . _third_key ] = third_dict
2013-07-17 20:56:13 +00:00
2017-05-10 21:33:58 +00:00
HG . test_controller . SetRead ( ' tag_parents ' , tag_parents )
2013-07-17 20:56:13 +00:00
2017-05-10 21:33:58 +00:00
cls . _tag_parents_manager = ClientCaches . TagParentsManager ( HG . client_controller )
2013-07-17 20:56:13 +00:00
def test_expand_predicates ( self ) :
predicates = [ ]
2016-06-22 20:59:24 +00:00
predicates . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' grandmother ' , min_current_count = 10 ) )
predicates . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' grandfather ' , min_current_count = 15 ) )
predicates . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' not_exist ' , min_current_count = 20 ) )
2013-07-17 20:56:13 +00:00
2015-06-03 21:05:13 +00:00
self . assertEqual ( self . _tag_parents_manager . ExpandPredicates ( CC . COMBINED_TAG_SERVICE_KEY , predicates ) , predicates )
2013-07-17 20:56:13 +00:00
predicates = [ ]
2016-06-22 20:59:24 +00:00
predicates . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' child ' , min_current_count = 10 ) )
2013-07-17 20:56:13 +00:00
results = [ ]
2016-06-22 20:59:24 +00:00
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' child ' , min_current_count = 10 ) )
2015-12-09 23:16:41 +00:00
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_PARENT , ' mother ' ) )
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_PARENT , ' father ' ) )
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_PARENT , ' grandmother ' ) )
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_PARENT , ' grandfather ' ) )
2013-07-17 20:56:13 +00:00
2015-06-03 21:05:13 +00:00
self . assertEqual ( set ( self . _tag_parents_manager . ExpandPredicates ( CC . COMBINED_TAG_SERVICE_KEY , predicates ) ) , set ( results ) )
2013-07-17 20:56:13 +00:00
predicates = [ ]
2015-12-09 23:16:41 +00:00
predicates . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_NAMESPACE , ' series ' ) )
2016-06-22 20:59:24 +00:00
predicates . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' child ' , min_current_count = 10 ) )
predicates . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' cousin ' , min_current_count = 5 ) )
2013-07-17 20:56:13 +00:00
results = [ ]
2015-12-09 23:16:41 +00:00
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_NAMESPACE , ' series ' ) )
2016-06-22 20:59:24 +00:00
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' child ' , min_current_count = 10 ) )
2015-12-09 23:16:41 +00:00
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_PARENT , ' mother ' ) )
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_PARENT , ' father ' ) )
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_PARENT , ' grandmother ' ) )
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_PARENT , ' grandfather ' ) )
2016-06-22 20:59:24 +00:00
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' cousin ' , min_current_count = 5 ) )
2015-12-09 23:16:41 +00:00
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_PARENT , ' aunt ' ) )
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_PARENT , ' uncle ' ) )
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_PARENT , ' grandmother ' ) )
results . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_PARENT , ' grandfather ' ) )
2013-07-17 20:56:13 +00:00
2015-06-03 21:05:13 +00:00
self . assertEqual ( set ( self . _tag_parents_manager . ExpandPredicates ( CC . COMBINED_TAG_SERVICE_KEY , predicates ) ) , set ( results ) )
2013-07-17 20:56:13 +00:00
def test_expand_tags ( self ) :
tags = { ' grandmother ' , ' grandfather ' }
2015-06-03 21:05:13 +00:00
self . assertEqual ( self . _tag_parents_manager . ExpandTags ( CC . COMBINED_TAG_SERVICE_KEY , tags ) , tags )
2013-07-17 20:56:13 +00:00
tags = { ' child ' , ' cousin ' }
results = { ' child ' , ' mother ' , ' father ' , ' grandmother ' , ' grandfather ' , ' cousin ' , ' aunt ' , ' uncle ' , ' grandmother ' , ' grandfather ' }
2015-06-03 21:05:13 +00:00
self . assertEqual ( self . _tag_parents_manager . ExpandTags ( CC . COMBINED_TAG_SERVICE_KEY , tags ) , results )
2013-07-17 20:56:13 +00:00
def test_grandparents ( self ) :
2015-06-03 21:05:13 +00:00
self . assertEqual ( set ( self . _tag_parents_manager . GetParents ( CC . COMBINED_TAG_SERVICE_KEY , ' child ' ) ) , { ' mother ' , ' father ' , ' grandmother ' , ' grandfather ' } )
self . assertEqual ( set ( self . _tag_parents_manager . GetParents ( CC . COMBINED_TAG_SERVICE_KEY , ' mother ' ) ) , { ' grandmother ' , ' grandfather ' } )
self . assertEqual ( set ( self . _tag_parents_manager . GetParents ( CC . COMBINED_TAG_SERVICE_KEY , ' grandmother ' ) ) , set ( ) )
2013-07-17 20:56:13 +00:00
def test_current_overwrite ( self ) :
2015-06-03 21:05:13 +00:00
self . assertEqual ( self . _tag_parents_manager . GetParents ( CC . COMBINED_TAG_SERVICE_KEY , ' current_a ' ) , [ ' current_b ' ] )
self . assertEqual ( self . _tag_parents_manager . GetParents ( CC . COMBINED_TAG_SERVICE_KEY , ' current_b ' ) , [ ] )
2013-07-17 20:56:13 +00:00
2015-06-03 21:05:13 +00:00
self . assertEqual ( self . _tag_parents_manager . ExpandTags ( CC . COMBINED_TAG_SERVICE_KEY , [ ' current_a ' ] ) , { ' current_a ' , ' current_b ' } )
self . assertEqual ( self . _tag_parents_manager . ExpandTags ( CC . COMBINED_TAG_SERVICE_KEY , [ ' current_b ' ] ) , { ' current_b ' } )
2013-07-17 20:56:13 +00:00
2014-09-24 21:50:07 +00:00
def test_deleted ( self ) :
2013-07-17 20:56:13 +00:00
2015-06-03 21:05:13 +00:00
self . assertEqual ( self . _tag_parents_manager . GetParents ( CC . COMBINED_TAG_SERVICE_KEY , ' deleted_a ' ) , [ ] )
self . assertEqual ( self . _tag_parents_manager . GetParents ( CC . COMBINED_TAG_SERVICE_KEY , ' deleted_b ' ) , [ ] )
2013-07-17 20:56:13 +00:00
2015-06-03 21:05:13 +00:00
self . assertEqual ( self . _tag_parents_manager . ExpandTags ( CC . COMBINED_TAG_SERVICE_KEY , [ ' deleted_a ' ] ) , { ' deleted_a ' } )
self . assertEqual ( self . _tag_parents_manager . ExpandTags ( CC . COMBINED_TAG_SERVICE_KEY , [ ' deleted_b ' ] ) , { ' deleted_b ' } )
2013-07-17 20:56:13 +00:00
def test_no_loop ( self ) :
2015-06-03 21:05:13 +00:00
self . assertEqual ( self . _tag_parents_manager . GetParents ( CC . COMBINED_TAG_SERVICE_KEY , ' closed_loop ' ) , [ ] )
2013-07-17 20:56:13 +00:00
2015-06-03 21:05:13 +00:00
self . assertEqual ( self . _tag_parents_manager . ExpandTags ( CC . COMBINED_TAG_SERVICE_KEY , [ ' closed_loop ' ] ) , { ' closed_loop ' } )
2013-07-17 20:56:13 +00:00
def test_not_exist ( self ) :
2015-06-03 21:05:13 +00:00
self . assertEqual ( self . _tag_parents_manager . GetParents ( CC . COMBINED_TAG_SERVICE_KEY , ' not_exist ' ) , [ ] )
2013-07-17 20:56:13 +00:00
2015-06-03 21:05:13 +00:00
self . assertEqual ( self . _tag_parents_manager . ExpandTags ( CC . COMBINED_TAG_SERVICE_KEY , [ ' not_exist ' ] ) , { ' not_exist ' } )
2013-07-17 20:56:13 +00:00
def test_pending_overwrite ( self ) :
2015-06-03 21:05:13 +00:00
self . assertEqual ( self . _tag_parents_manager . GetParents ( CC . COMBINED_TAG_SERVICE_KEY , ' pending_a ' ) , [ ' pending_b ' ] )
self . assertEqual ( self . _tag_parents_manager . GetParents ( CC . COMBINED_TAG_SERVICE_KEY , ' pending_b ' ) , [ ] )
2013-07-17 20:56:13 +00:00
2015-06-03 21:05:13 +00:00
self . assertEqual ( self . _tag_parents_manager . ExpandTags ( CC . COMBINED_TAG_SERVICE_KEY , [ ' pending_a ' ] ) , { ' pending_a ' , ' pending_b ' } )
self . assertEqual ( self . _tag_parents_manager . ExpandTags ( CC . COMBINED_TAG_SERVICE_KEY , [ ' pending_b ' ] ) , { ' pending_b ' } )
2013-07-17 20:56:13 +00:00
class TestTagSiblings ( unittest . TestCase ) :
@classmethod
2017-04-05 21:16:40 +00:00
def setUpClass ( cls ) :
2013-07-17 20:56:13 +00:00
2017-04-05 21:16:40 +00:00
cls . _first_key = HydrusData . GenerateKey ( )
cls . _second_key = HydrusData . GenerateKey ( )
2013-07-17 20:56:13 +00:00
2015-03-25 22:04:19 +00:00
tag_siblings = collections . defaultdict ( HydrusData . default_dict_set )
2013-07-17 20:56:13 +00:00
2015-03-25 22:04:19 +00:00
first_dict = HydrusData . default_dict_set ( )
2013-07-17 20:56:13 +00:00
2017-03-02 02:14:56 +00:00
first_dict [ HC . CONTENT_STATUS_CURRENT ] = { ( ' ishygddt ' , ' i sure hope you guys don \' t do that ' ) , ( ' character:rei ayanami ' , ' character:ayanami rei ' ) , ( ' tree_1 ' , ' tree_3 ' ) , ( ' tree_2 ' , ' tree_3 ' ) , ( ' tree_3 ' , ' tree_5 ' ) , ( ' tree_4 ' , ' tree_5 ' ) , ( ' tree_5 ' , ' tree_6 ' ) , ( ' current_a ' , ' current_b ' ) , ( ' chain_a ' , ' chain_b ' ) , ( ' chain_b ' , ' chain_c ' ) , ( ' closed_loop ' , ' closed_loop ' ) , ( ' loop_a ' , ' loop_b ' ) , ( ' loop_b ' , ' loop_c ' ) , ( ' loop_c ' , ' loop_a ' ) }
first_dict [ HC . CONTENT_STATUS_DELETED ] = { ( ' deleted_a ' , ' deleted_b ' ) }
2013-07-17 20:56:13 +00:00
2015-03-25 22:04:19 +00:00
second_dict = HydrusData . default_dict_set ( )
2013-07-17 20:56:13 +00:00
2017-03-02 02:14:56 +00:00
second_dict [ HC . CONTENT_STATUS_CURRENT ] = { ( ' loop_c ' , ' loop_a ' ) , ( ' current_a ' , ' current_b ' ) , ( ' petitioned_a ' , ' petitioned_b ' ) }
second_dict [ HC . CONTENT_STATUS_DELETED ] = { ( ' pending_a ' , ' pending_b ' ) }
second_dict [ HC . CONTENT_STATUS_PENDING ] = { ( ' pending_a ' , ' pending_b ' ) }
second_dict [ HC . CONTENT_STATUS_PETITIONED ] = { ( ' petitioned_a ' , ' petitioned_b ' ) }
2013-07-17 20:56:13 +00:00
2017-04-05 21:16:40 +00:00
tag_siblings [ cls . _first_key ] = first_dict
tag_siblings [ cls . _second_key ] = second_dict
2013-07-17 20:56:13 +00:00
2017-05-10 21:33:58 +00:00
HG . test_controller . SetRead ( ' tag_siblings ' , tag_siblings )
2013-07-17 20:56:13 +00:00
2017-05-10 21:33:58 +00:00
cls . _tag_siblings_manager = ClientCaches . TagSiblingsManager ( HG . client_controller )
2013-07-17 20:56:13 +00:00
def test_autocomplete ( self ) :
2017-03-08 23:23:12 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _first_key , ' ishy* ' ) ) , set ( [ ' ishygddt ' , ' i sure hope you guys don \' t do that ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _first_key , ' i su* ' ) ) , set ( [ ' ishygddt ' , ' i sure hope you guys don \' t do that ' ] ) )
2013-07-17 20:56:13 +00:00
2017-03-08 23:23:12 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _first_key , ' ayan* ' ) ) , set ( [ ' character:rei ayanami ' , ' character:ayanami rei ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _first_key , ' rei* ' ) ) , set ( [ ' character:rei ayanami ' , ' character:ayanami rei ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _first_key , ' character:ayan* ' ) ) , set ( [ ' character:rei ayanami ' , ' character:ayanami rei ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _first_key , ' character:rei* ' ) ) , set ( [ ' character:rei ayanami ' , ' character:ayanami rei ' ] ) )
2013-07-17 20:56:13 +00:00
2017-03-08 23:23:12 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _second_key , ' ishy* ' ) ) , set ( ) )
2013-07-17 20:56:13 +00:00
def test_collapse_predicates ( self ) :
predicates = [ ]
2016-06-22 20:59:24 +00:00
predicates . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' chain_a ' , min_current_count = 10 ) )
predicates . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' chain_b ' , min_current_count = 5 ) )
predicates . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' chain_c ' , min_current_count = 20 ) )
2013-07-17 20:56:13 +00:00
2016-06-22 20:59:24 +00:00
results = [ ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' chain_c ' , min_current_count = 20 , max_current_count = 35 ) ]
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . CollapsePredicates ( self . _first_key , predicates ) , results )
2013-07-17 20:56:13 +00:00
predicates = [ ]
2016-06-22 20:59:24 +00:00
predicates . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' chain_a ' , min_current_count = 10 ) )
predicates . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' chain_b ' , min_current_count = 5 ) )
predicates . append ( ClientSearch . Predicate ( HC . PREDICATE_TYPE_TAG , ' chain_c ' , min_current_count = 20 ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
( result , ) = self . _tag_siblings_manager . CollapsePredicates ( self . _first_key , predicates )
2013-07-17 20:56:13 +00:00
2016-06-22 20:59:24 +00:00
self . assertEqual ( result . GetCount ( ) , 20 )
self . assertEqual ( result . GetUnicode ( ) , u ' chain_c (20-35) ' )
2013-07-17 20:56:13 +00:00
def test_chain ( self ) :
2017-03-08 23:23:12 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _first_key , ' chai* ' ) ) , set ( [ ' chain_a ' , ' chain_b ' , ' chain_c ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _first_key , ' chain_a ' ) , ' chain_c ' )
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _first_key , ' chain_b ' ) , ' chain_c ' )
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _first_key , ' chain_c ' ) , None )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _first_key , ' chain_a ' ) ) , set ( [ ' chain_a ' , ' chain_b ' , ' chain_c ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _first_key , ' chain_b ' ) ) , set ( [ ' chain_a ' , ' chain_b ' , ' chain_c ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _first_key , ' chain_c ' ) ) , set ( [ ' chain_a ' , ' chain_b ' , ' chain_c ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . CollapseTags ( self . _first_key , [ ' chain_a ' , ' chain_b ' ] ) ) , set ( [ ' chain_c ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . CollapseTags ( self . _first_key , [ ' chain_a ' , ' chain_b ' , ' chain_c ' ] ) ) , set ( [ ' chain_c ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
def test_current ( self ) :
2013-07-17 20:56:13 +00:00
2017-03-08 23:23:12 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _second_key , ' curr* ' ) ) , set ( [ ' current_a ' , ' current_b ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _second_key , ' current_a ' ) , ' current_b ' )
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _second_key , ' current_b ' ) , None )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _second_key , ' current_a ' ) ) , set ( [ ' current_a ' , ' current_b ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _second_key , ' current_b ' ) ) , set ( [ ' current_a ' , ' current_b ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . CollapseTags ( self . _first_key , [ ' chain_a ' , ' chain_b ' ] ) ) , set ( [ ' chain_c ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . CollapseTags ( self . _first_key , [ ' chain_a ' , ' chain_b ' , ' chain_c ' ] ) ) , set ( [ ' chain_c ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . CollapseTagsToCount ( self . _first_key , { ' chain_a ' : 10 , ' chain_b ' : 5 } ) , { ' chain_c ' : 15 } )
self . assertEqual ( self . _tag_siblings_manager . CollapseTagsToCount ( self . _first_key , { ' chain_a ' : 10 , ' chain_b ' : 5 , ' chain_c ' : 20 } ) , { ' chain_c ' : 35 } )
2013-07-17 20:56:13 +00:00
2014-09-24 21:50:07 +00:00
def test_deleted ( self ) :
2013-07-17 20:56:13 +00:00
2017-03-08 23:23:12 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _first_key , ' dele* ' ) ) , set ( ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _first_key , ' deleted_a ' ) , None )
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _first_key , ' deleted_b ' ) , None )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _first_key , ' deleted_a ' ) ) , set ( [ ' deleted_a ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _first_key , ' deleted_b ' ) ) , set ( [ ' deleted_b ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . CollapseTags ( self . _first_key , [ ' deleted_a ' , ' deleted_b ' ] ) ) , set ( [ ' deleted_a ' , ' deleted_b ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . CollapseTagsToCount ( self . _first_key , { ' deleted_a ' : 10 , ' deleted_b ' : 5 } ) , { ' deleted_a ' : 10 , ' deleted_b ' : 5 } )
2013-07-17 20:56:13 +00:00
def test_no_loop ( self ) :
2017-03-08 23:23:12 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _first_key , ' loop* ' ) ) , set ( [ ' loop_a ' , ' loop_b ' , ' loop_c ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _first_key , ' closed_loop ' ) , None )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _first_key , ' closed_loop ' ) ) , set ( [ ' closed_loop ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . CollapseTags ( self . _first_key , [ ' closed_loop ' ] ) ) , set ( [ ' closed_loop ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . CollapseTagsToCount ( self . _first_key , { ' closed_loop ' : 10 } ) , { ' closed_loop ' : 10 } )
2013-07-17 20:56:13 +00:00
def test_not_exist ( self ) :
2017-03-08 23:23:12 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _second_key , ' not_* ' ) ) , set ( ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _second_key , ' not_exist ' ) , None )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _second_key , ' not_exist ' ) ) , set ( [ ' not_exist ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . CollapseTags ( self . _second_key , [ ' not_exist ' ] ) ) , set ( [ ' not_exist ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . CollapseTagsToCount ( self . _second_key , { ' not_exist ' : 10 } ) , { ' not_exist ' : 10 } )
2013-07-17 20:56:13 +00:00
def test_pending_overwrite ( self ) :
2017-03-08 23:23:12 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _second_key , ' pend* ' ) ) , set ( [ ' pending_a ' , ' pending_b ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _second_key , ' pending_a ' ) , ' pending_b ' )
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _second_key , ' pending_b ' ) , None )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _second_key , ' pending_a ' ) ) , set ( [ ' pending_a ' , ' pending_b ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _second_key , ' pending_b ' ) ) , set ( [ ' pending_a ' , ' pending_b ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . CollapseTags ( self . _second_key , [ ' pending_a ' ] ) ) , set ( [ ' pending_b ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . CollapseTags ( self . _second_key , [ ' pending_a ' , ' pending_b ' ] ) ) , set ( [ ' pending_b ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . CollapseTagsToCount ( self . _second_key , { ' pending_a ' : 10 } ) , { ' pending_b ' : 10 } )
self . assertEqual ( self . _tag_siblings_manager . CollapseTagsToCount ( self . _second_key , { ' pending_a ' : 10 , ' pending_b ' : 5 } ) , { ' pending_b ' : 15 } )
2013-07-17 20:56:13 +00:00
def test_petitioned_no_overwrite ( self ) :
2017-03-08 23:23:12 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _second_key , ' petitioned_a* ' ) ) , set ( [ ' petitioned_a ' , ' petitioned_b ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _second_key , ' petitioned_a ' ) , ' petitioned_b ' )
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _second_key , ' petitioned_b ' ) , None )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _second_key , ' petitioned_a ' ) ) , set ( [ ' petitioned_a ' , ' petitioned_b ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _second_key , ' petitioned_b ' ) ) , set ( [ ' petitioned_a ' , ' petitioned_b ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . CollapseTags ( self . _second_key , [ ' petitioned_a ' ] ) ) , set ( [ ' petitioned_b ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . CollapseTags ( self . _second_key , [ ' petitioned_a ' , ' petitioned_b ' ] ) ) , set ( [ ' petitioned_b ' ] ) )
2013-07-17 20:56:13 +00:00
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . CollapseTagsToCount ( self . _second_key , { ' petitioned_a ' : 10 } ) , { ' petitioned_b ' : 10 } )
self . assertEqual ( self . _tag_siblings_manager . CollapseTagsToCount ( self . _second_key , { ' petitioned_a ' : 10 , ' petitioned_b ' : 5 } ) , { ' petitioned_b ' : 15 } )
2013-07-17 20:56:13 +00:00
def test_tree ( self ) :
2017-03-08 23:23:12 +00:00
self . assertEqual ( set ( self . _tag_siblings_manager . GetAutocompleteSiblings ( self . _first_key , ' tree* ' ) ) , set ( [ ' tree_1 ' , ' tree_2 ' , ' tree_3 ' , ' tree_4 ' , ' tree_5 ' , ' tree_6 ' ] ) )
2016-09-14 18:03:59 +00:00
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _first_key , ' tree_1 ' ) , ' tree_6 ' )
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _first_key , ' tree_2 ' ) , ' tree_6 ' )
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _first_key , ' tree_3 ' ) , ' tree_6 ' )
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _first_key , ' tree_4 ' ) , ' tree_6 ' )
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _first_key , ' tree_5 ' ) , ' tree_6 ' )
self . assertEqual ( self . _tag_siblings_manager . GetSibling ( self . _first_key , ' tree_6 ' ) , None )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _first_key , ' tree_1 ' ) ) , set ( [ ' tree_1 ' , ' tree_2 ' , ' tree_3 ' , ' tree_4 ' , ' tree_5 ' , ' tree_6 ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _first_key , ' tree_2 ' ) ) , set ( [ ' tree_1 ' , ' tree_2 ' , ' tree_3 ' , ' tree_4 ' , ' tree_5 ' , ' tree_6 ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _first_key , ' tree_3 ' ) ) , set ( [ ' tree_1 ' , ' tree_2 ' , ' tree_3 ' , ' tree_4 ' , ' tree_5 ' , ' tree_6 ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _first_key , ' tree_4 ' ) ) , set ( [ ' tree_1 ' , ' tree_2 ' , ' tree_3 ' , ' tree_4 ' , ' tree_5 ' , ' tree_6 ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _first_key , ' tree_5 ' ) ) , set ( [ ' tree_1 ' , ' tree_2 ' , ' tree_3 ' , ' tree_4 ' , ' tree_5 ' , ' tree_6 ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . GetAllSiblings ( self . _first_key , ' tree_6 ' ) ) , set ( [ ' tree_1 ' , ' tree_2 ' , ' tree_3 ' , ' tree_4 ' , ' tree_5 ' , ' tree_6 ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . CollapseTags ( self . _first_key , [ ' tree_1 ' ] ) ) , set ( [ ' tree_6 ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . CollapseTags ( self . _first_key , [ ' tree_1 ' , ' tree_3 ' , ' tree_5 ' ] ) ) , set ( [ ' tree_6 ' ] ) )
self . assertEqual ( set ( self . _tag_siblings_manager . CollapseTags ( self . _first_key , [ ' tree_1 ' , ' tree_2 ' , ' tree_3 ' , ' tree_4 ' , ' tree_5 ' , ' tree_6 ' ] ) ) , set ( [ ' tree_6 ' ] ) )
self . assertEqual ( self . _tag_siblings_manager . CollapseTagsToCount ( self . _first_key , { ' tree_1 ' : 10 } ) , { ' tree_6 ' : 10 } )
self . assertEqual ( self . _tag_siblings_manager . CollapseTagsToCount ( self . _first_key , { ' tree_1 ' : 10 , ' tree_3 ' : 5 , ' tree_5 ' : 20 } ) , { ' tree_6 ' : 35 } )
self . assertEqual ( self . _tag_siblings_manager . CollapseTagsToCount ( self . _first_key , { ' tree_1 ' : 10 , ' tree_2 ' : 3 , ' tree_3 ' : 5 , ' tree_4 ' : 2 , ' tree_5 ' : 20 , ' tree_6 ' : 30 } ) , { ' tree_6 ' : 70 } )
2013-07-17 20:56:13 +00:00
2017-03-02 02:14:56 +00:00