hydrus/include/TestClientDaemons.py

65 lines
2.8 KiB
Python
Raw Normal View History

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
2015-03-25 22:04:19 +00:00
import HydrusGlobals
2016-08-17 20:07:22 +00:00
import HydrusPaths
2013-07-31 21:26:38 +00:00
class TestDaemons( unittest.TestCase ):
def test_import_folders_daemon( self ):
2015-03-25 22:04:19 +00:00
test_dir = tempfile.mkdtemp()
2013-07-31 21:26:38 +00:00
2015-05-06 20:26:18 +00:00
try:
2016-08-17 20:07:22 +00:00
HydrusPaths.MakeSureDirectoryExists( test_dir )
2015-05-06 20:26:18 +00:00
2015-11-04 22:30:28 +00:00
with open( os.path.join( test_dir, '0' ), 'wb' ) as f: f.write( TestConstants.tinest_gif )
with open( os.path.join( test_dir, '1' ), 'wb' ) as f: f.write( TestConstants.tinest_gif ) # previously imported
with open( os.path.join( test_dir, '2' ), 'wb' ) as f: f.write( TestConstants.tinest_gif )
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
#
2015-10-28 21:29:05 +00:00
import_folder = ClientImporting.ImportFolder( 'imp', path = test_dir )
2015-05-06 20:26:18 +00:00
2015-10-21 21:53:10 +00:00
HydrusGlobals.test_controller.SetRead( 'serialisable_named', [ import_folder ] )
2015-05-06 20:26:18 +00:00
2015-11-04 22:30:28 +00:00
ClientDaemons.DAEMONCheckImportFolders( HydrusGlobals.test_controller )
2015-05-06 20:26:18 +00:00
#(('C:\\code\\Hydrus\\temp\\7baa9a818a14b7a9cbefb04c16bdc45ac651eb7400c1996e66e2efeef9e3ee5d',), {'service_keys_to_tags': {HC.LOCAL_TAG_SERVICE_KEY: set(['local tag'])}})
#(('C:\\code\\Hydrus\\temp\\e0dbdcb1a13c0565ffb73f2f497528adbe1703ca1dfc69680202487187b9fcfa',), {'service_keys_to_tags': {HC.LOCAL_TAG_SERVICE_KEY: set(['local tag'])}})
#(('C:\\code\\Hydrus\\temp\\182c4eecf2a5b4dfc8b74813bcff5d967ed53d92a982d8ae18520e1504fa5902',), {'service_keys_to_tags': {HC.LOCAL_TAG_SERVICE_KEY: set(['local tag'])}})
2015-09-16 18:11:00 +00:00
import_file = HydrusGlobals.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
2015-10-21 21:53:10 +00:00
[ ( ( updated_import_folder, ), empty_dict ) ] = HydrusGlobals.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