hydrus/hydrus/test/TestClientDaemons.py

81 lines
3.2 KiB
Python
Raw Normal View History

2013-07-31 21:26:38 +00:00
import os
2015-05-06 20:26:18 +00:00
import shutil
2013-07-31 21:26:38 +00:00
import unittest
2020-07-29 20:52:44 +00:00
from hydrus.core import HydrusConstants as HC
2020-04-22 21:00:35 +00:00
from hydrus.core import HydrusGlobals as HG
from hydrus.core import HydrusPaths
from hydrus.core import HydrusTemp
2013-07-31 21:26:38 +00:00
2020-07-29 20:52:44 +00:00
from hydrus.client import ClientConstants as CC
from hydrus.client import ClientDaemons
2021-06-30 21:27:35 +00:00
from hydrus.client.importing import ClientImportFiles
2020-07-29 20:52:44 +00:00
from hydrus.client.importing import ClientImportLocal
2016-12-07 22:12:52 +00:00
with open( os.path.join( HC.STATIC_DIR, 'hydrus.png' ), 'rb' ) as f:
EXAMPLE_FILE = f.read()
2013-07-31 21:26:38 +00:00
class TestDaemons( unittest.TestCase ):
def test_import_folders_daemon( self ):
test_dir = HydrusTemp.GetTempDir()
2013-07-31 21:26:38 +00:00
2015-05-06 20:26:18 +00:00
try:
2021-06-30 21:27:35 +00:00
HG.test_controller.SetRead( 'hash_status', ClientImportFiles.FileImportStatus.STATICGetUnknownStatus() )
2017-07-19 21:21:41 +00:00
2016-08-17 20:07:22 +00:00
HydrusPaths.MakeSureDirectoryExists( test_dir )
2015-05-06 20:26:18 +00:00
2017-07-19 21:21:41 +00:00
hydrus_png_path = os.path.join( HC.STATIC_DIR, 'hydrus.png' )
HydrusPaths.MirrorFile( hydrus_png_path, os.path.join( test_dir, '0' ) )
HydrusPaths.MirrorFile( hydrus_png_path, os.path.join( test_dir, '1' ) ) # previously imported
HydrusPaths.MirrorFile( hydrus_png_path, os.path.join( test_dir, '2' ) )
2019-01-09 22:59:03 +00:00
with open( os.path.join( test_dir, '3' ), 'wb' ) as f: f.write( b'blarg' ) # broken
with open( os.path.join( test_dir, '4' ), 'wb' ) as f: f.write( b'blarg' ) # previously failed
2015-05-06 20:26:18 +00:00
#
2017-08-09 21:33:51 +00:00
actions = {}
2018-04-25 22:07:52 +00:00
actions[ CC.STATUS_SUCCESSFUL_AND_NEW ] = CC.IMPORT_FOLDER_DELETE
actions[ CC.STATUS_SUCCESSFUL_BUT_REDUNDANT ] = CC.IMPORT_FOLDER_DELETE
2017-08-09 21:33:51 +00:00
actions[ CC.STATUS_DELETED ] = CC.IMPORT_FOLDER_DELETE
2018-04-25 22:07:52 +00:00
actions[ CC.STATUS_ERROR ] = CC.IMPORT_FOLDER_IGNORE
2017-08-09 21:33:51 +00:00
2018-08-01 20:44:57 +00:00
import_folder = ClientImportLocal.ImportFolder( 'imp', path = test_dir, actions = actions )
2015-05-06 20:26:18 +00:00
2017-10-25 21:45:15 +00:00
HG.test_controller.SetRead( 'serialisable_names', [ 'imp' ] )
HG.test_controller.SetRead( 'serialisable_named', import_folder )
2015-05-06 20:26:18 +00:00
2019-02-13 22:26:43 +00:00
HG.test_controller.ClearWrites( 'import_file' )
HG.test_controller.ClearWrites( 'serialisable' )
ClientDaemons.DAEMONCheckImportFolders()
2015-05-06 20:26:18 +00:00
2017-05-10 21:33:58 +00:00
import_file = HG.test_controller.GetWrite( 'import_file' )
2015-05-06 20:26:18 +00:00
self.assertEqual( len( import_file ), 3 )
# I need to expand tests here with the new file system
2017-05-10 21:33:58 +00:00
[ ( ( updated_import_folder, ), empty_dict ) ] = HG.test_controller.GetWrite( 'serialisable' )
2015-05-06 20:26:18 +00:00
2015-09-09 22:04:39 +00:00
self.assertEqual( updated_import_folder, import_folder )
2015-05-06 20:26:18 +00:00
2015-11-04 22:30:28 +00:00
self.assertTrue( not os.path.exists( os.path.join( test_dir, '0' ) ) )
self.assertTrue( not os.path.exists( os.path.join( test_dir, '1' ) ) )
self.assertTrue( not os.path.exists( os.path.join( test_dir, '2' ) ) )
self.assertTrue( os.path.exists( os.path.join( test_dir, '3' ) ) )
self.assertTrue( os.path.exists( os.path.join( test_dir, '4' ) ) )
2015-05-06 20:26:18 +00:00
finally:
shutil.rmtree( test_dir )
2013-07-31 21:26:38 +00:00
2016-12-07 22:12:52 +00:00