hydrus/include/TestClientConstants.py

126 lines
4.6 KiB
Python
Raw Normal View History

2019-01-09 22:59:03 +00:00
from . import ClientConstants as CC
from . import ClientGUIManagement
from . import ClientNetworking
from . import ClientCaches
from . import ClientServices
2013-08-07 22:25:18 +00:00
import collections
2019-01-09 22:59:03 +00:00
from . import HydrusConstants as HC
2013-08-07 22:25:18 +00:00
import os
import unittest
2019-01-09 22:59:03 +00:00
from . import HydrusData
from . import HydrusGlobals as HG
2013-08-07 22:25:18 +00:00
2013-11-06 18:22:07 +00:00
class TestManagers( unittest.TestCase ):
2014-08-27 22:15:22 +00:00
def test_services( self ):
2017-03-08 23:23:12 +00:00
def test_service( service, key, service_type, name ):
2014-08-27 22:15:22 +00:00
2014-09-17 21:28:26 +00:00
self.assertEqual( service.GetServiceKey(), key )
self.assertEqual( service.GetServiceType(), service_type )
2014-08-27 22:15:22 +00:00
self.assertEqual( service.GetName(), name )
2015-07-01 22:02:07 +00:00
repo_key = HydrusData.GenerateKey()
2014-08-27 22:15:22 +00:00
repo_type = HC.TAG_REPOSITORY
repo_name = 'test tag repo'
2017-03-02 02:14:56 +00:00
repo = ClientServices.GenerateService( repo_key, repo_type, repo_name )
2014-08-27 22:15:22 +00:00
2015-07-01 22:02:07 +00:00
other_key = HydrusData.GenerateKey()
2014-08-27 22:15:22 +00:00
2017-03-02 02:14:56 +00:00
other = ClientServices.GenerateService( other_key, HC.LOCAL_BOORU, 'booru' )
2014-08-27 22:15:22 +00:00
services = []
services.append( repo )
services.append( other )
2017-05-10 21:33:58 +00:00
HG.test_controller.SetRead( 'services', services )
2014-08-27 22:15:22 +00:00
2017-05-10 21:33:58 +00:00
services_manager = ClientCaches.ServicesManager( HG.client_controller )
2014-08-27 22:15:22 +00:00
#
service = services_manager.GetService( repo_key )
2017-03-08 23:23:12 +00:00
test_service( service, repo_key, repo_type, repo_name )
2014-08-27 22:15:22 +00:00
service = services_manager.GetService( other_key )
#
services = services_manager.GetServices( ( HC.TAG_REPOSITORY, ) )
self.assertEqual( len( services ), 1 )
2014-09-17 21:28:26 +00:00
self.assertEqual( services[0].GetServiceKey(), repo_key )
2014-08-27 22:15:22 +00:00
#
services = []
services.append( repo )
2017-05-10 21:33:58 +00:00
HG.test_controller.SetRead( 'services', services )
2014-08-27 22:15:22 +00:00
services_manager.RefreshServices()
self.assertRaises( Exception, services_manager.GetService, other_key )
2013-11-06 18:22:07 +00:00
def test_undo( self ):
2015-07-01 22:02:07 +00:00
hash_1 = HydrusData.GenerateKey()
hash_2 = HydrusData.GenerateKey()
hash_3 = HydrusData.GenerateKey()
2013-11-06 18:22:07 +00:00
2016-12-21 22:30:54 +00:00
command_1 = { CC.COMBINED_LOCAL_FILE_SERVICE_KEY : [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_FILES, HC.CONTENT_UPDATE_ARCHIVE, { hash_1 } ) ] }
command_2 = { CC.COMBINED_LOCAL_FILE_SERVICE_KEY : [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_FILES, HC.CONTENT_UPDATE_INBOX, { hash_2 } ) ] }
command_3 = { CC.COMBINED_LOCAL_FILE_SERVICE_KEY : [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_FILES, HC.CONTENT_UPDATE_ARCHIVE, { hash_1, hash_3 } ) ] }
2013-11-06 18:22:07 +00:00
2016-12-21 22:30:54 +00:00
command_1_inverted = { CC.COMBINED_LOCAL_FILE_SERVICE_KEY : [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_FILES, HC.CONTENT_UPDATE_INBOX, { hash_1 } ) ] }
command_2_inverted = { CC.COMBINED_LOCAL_FILE_SERVICE_KEY : [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_FILES, HC.CONTENT_UPDATE_ARCHIVE, { hash_2 } ) ] }
2013-11-06 18:22:07 +00:00
2017-05-10 21:33:58 +00:00
undo_manager = ClientCaches.UndoManager( HG.client_controller )
2013-11-06 18:22:07 +00:00
#
2019-02-13 22:26:43 +00:00
HG.test_controller.ClearWrites( 'content_updates' )
2013-11-06 18:22:07 +00:00
undo_manager.AddCommand( 'content_updates', command_1 )
2019-01-09 22:59:03 +00:00
self.assertEqual( ( 'undo archive 1 files', None ), undo_manager.GetUndoRedoStrings() )
2013-11-06 18:22:07 +00:00
undo_manager.AddCommand( 'content_updates', command_2 )
2019-01-09 22:59:03 +00:00
self.assertEqual( ( 'undo inbox 1 files', None ), undo_manager.GetUndoRedoStrings() )
2013-11-06 18:22:07 +00:00
undo_manager.Undo()
2019-01-09 22:59:03 +00:00
self.assertEqual( ( 'undo archive 1 files', 'redo inbox 1 files' ), undo_manager.GetUndoRedoStrings() )
2013-11-06 18:22:07 +00:00
2017-05-10 21:33:58 +00:00
self.assertEqual( HG.test_controller.GetWrite( 'content_updates' ), [ ( ( command_2_inverted, ), {} ) ] )
2013-11-06 18:22:07 +00:00
undo_manager.Redo()
2017-05-10 21:33:58 +00:00
self.assertEqual( HG.test_controller.GetWrite( 'content_updates' ), [ ( ( command_2, ), {} ) ] )
2013-11-06 18:22:07 +00:00
2019-01-09 22:59:03 +00:00
self.assertEqual( ( 'undo inbox 1 files', None ), undo_manager.GetUndoRedoStrings() )
2013-11-06 18:22:07 +00:00
undo_manager.Undo()
2017-05-10 21:33:58 +00:00
self.assertEqual( HG.test_controller.GetWrite( 'content_updates' ), [ ( ( command_2_inverted, ), {} ) ] )
2013-11-06 18:22:07 +00:00
undo_manager.Undo()
2017-05-10 21:33:58 +00:00
self.assertEqual( HG.test_controller.GetWrite( 'content_updates' ), [ ( ( command_1_inverted, ), {} ) ] )
2013-11-06 18:22:07 +00:00
2019-01-09 22:59:03 +00:00
self.assertEqual( ( None, 'redo archive 1 files' ), undo_manager.GetUndoRedoStrings() )
2013-11-06 18:22:07 +00:00
undo_manager.AddCommand( 'content_updates', command_3 )
2019-01-09 22:59:03 +00:00
self.assertEqual( ( 'undo archive 2 files', None ), undo_manager.GetUndoRedoStrings() )
2013-11-06 18:22:07 +00:00
2016-12-21 22:30:54 +00:00