2015-03-04 22:44:32 +00:00
|
|
|
import ClientDaemons
|
2015-09-09 22:04:39 +00:00
|
|
|
import ClientImporting
|
2013-07-31 21:26:38 +00:00
|
|
|
import collections
|
|
|
|
import HydrusConstants as HC
|
|
|
|
import os
|
2015-05-06 20:26:18 +00:00
|
|
|
import shutil
|
|
|
|
import stat
|
2013-07-31 21:26:38 +00:00
|
|
|
import TestConstants
|
2015-03-25 22:04:19 +00:00
|
|
|
import tempfile
|
2013-07-31 21:26:38 +00:00
|
|
|
import unittest
|
2015-03-25 22:04:19 +00:00
|
|
|
import HydrusData
|
2015-06-03 21:05:13 +00:00
|
|
|
import ClientConstants as CC
|
2017-05-10 21:33:58 +00:00
|
|
|
import HydrusGlobals as HG
|
2016-08-17 20:07:22 +00:00
|
|
|
import HydrusPaths
|
2013-07-31 21:26:38 +00:00
|
|
|
|
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 ):
|
|
|
|
|
2017-09-20 19:47:31 +00:00
|
|
|
test_dir = HydrusPaths.GetTempDir()
|
2013-07-31 21:26:38 +00:00
|
|
|
|
2015-05-06 20:26:18 +00:00
|
|
|
try:
|
|
|
|
|
2017-07-19 21:21:41 +00:00
|
|
|
HG.test_controller.SetRead( 'hash_status', CC.STATUS_NEW )
|
|
|
|
|
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' ) )
|
|
|
|
|
2015-11-04 22:30:28 +00:00
|
|
|
with open( os.path.join( test_dir, '3' ), 'wb' ) as f: f.write( 'blarg' ) # broken
|
|
|
|
with open( os.path.join( test_dir, '4' ), 'wb' ) as f: f.write( 'blarg' ) # previously failed
|
2015-05-06 20:26:18 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
|
2017-08-09 21:33:51 +00:00
|
|
|
actions = {}
|
|
|
|
|
|
|
|
actions[ CC.STATUS_SUCCESSFUL ] = CC.IMPORT_FOLDER_DELETE
|
|
|
|
actions[ CC.STATUS_REDUNDANT ] = CC.IMPORT_FOLDER_DELETE
|
|
|
|
actions[ CC.STATUS_DELETED ] = CC.IMPORT_FOLDER_DELETE
|
|
|
|
actions[ CC.STATUS_FAILED ] = CC.IMPORT_FOLDER_IGNORE
|
|
|
|
|
|
|
|
import_folder = ClientImporting.ImportFolder( 'imp', path = test_dir, actions = actions )
|
2015-05-06 20:26:18 +00:00
|
|
|
|
2017-05-10 21:33:58 +00:00
|
|
|
HG.test_controller.SetRead( 'serialisable_named', [ import_folder ] )
|
2015-05-06 20:26:18 +00:00
|
|
|
|
2017-05-10 21:33:58 +00:00
|
|
|
ClientDaemons.DAEMONCheckImportFolders( HG.test_controller )
|
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
|
|
|
|