Exemple #1
0
	def test_NEW_file_not_in_db_exists( self ):
		ev = Event( 'filename', '', False,self.DEFAULT_CFG[0] )
		ev.action = Event.ACTION.NEW
		with unittest.mock.patch( 'os.path.exists', return_value = True ) as exists_test:
			newEv = self.engine.prepareEvent( ev.path, self.DEFAULT_CFG[0], ev.action )
			exists_test.assert_called_once_with( ev.path )
		ev.isInDB = False
		ev.info = None
		self.assertEqual( ev, newEv )
Exemple #2
0
	def test_MISSING_file_not_in_db_exists( self ):
		ev = Event( 'filename', '', False, self.DEFAULT_CFG[0] )
		ev.action = Event.ACTION.MISSING
		with unittest.mock.patch( 'os.path.exists', return_value = True ) as exists_test:
			newEv = self.engine.prepareEvent( ev.path, self.DEFAULT_CFG[0], ev.action )
			exists_test.assert_called_once_with( ev.path )
		ev.action = Event.ACTION.NEW		# Пришло событие об удалении файла, а он есть, добавляем в базу.
		ev.isInDB = False
		ev.info = None
		self.assertEqual( ev, newEv )
Exemple #3
0
	def test_MISSING_file_already_in_db_exists_bad_hash( self ):
		self.engine.db.add( file = 'filename', hash = 'xxx' )
		ev = Event( 'filename', '', False, self.DEFAULT_CFG[0] )
		ev.action = Event.ACTION.MISSING
		with unittest.mock.patch( 'os.path.exists', return_value = True ) as exists_test:
			newEv = self.engine.prepareEvent( ev.path, self.DEFAULT_CFG[0], ev.action )
			exists_test.assert_called_once_with( ev.path )
		ev.isInDB = True
		ev.action = Event.ACTION.BAD_HASH					# Файл на диске есть, в базе есть, но они не совпали.
		ev.info = self.engine.db.find( file = 'filename' )
		self.assertEqual( ev, newEv )
Exemple #4
0
	def test_NEW_file_already_in_db_exists_bad_hash( self ):
		self.engine.db.add( file = 'filename', hash = 'xxx' )
		ev = Event( 'filename', '', False, self.DEFAULT_CFG[0] )
		ev.action = Event.ACTION.NEW
		with unittest.mock.patch( 'os.path.exists', return_value = True ) as exists_test:
			newEv = self.engine.prepareEvent( ev.path, self.DEFAULT_CFG[0], ev.action )
			exists_test.assert_called_once_with( ev.path )
		ev.isInDB = True
		ev.action = Event.ACTION.BAD_HASH	# Так как оказывается, что тот файл, который сейчас на диске не совпадает с тем, что в базе.
		ev.info = self.engine.db.find( file = 'filename' )
		self.assertEqual( ev, newEv )
Exemple #5
0
	def test_UPDATED_file_already_in_db_diff_hash( self ):
		self.engine.db.add( file = 'filename', hash = 'old' )
		ev = Event( 'filename', '', False, self.DEFAULT_CFG[0] )
		ev.action = Event.ACTION.UPDATED
		with unittest.mock.patch( 'fileutils.get_hash', return_value = 'new' ) as hash_test:
			with unittest.mock.patch( 'os.path.exists', return_value = True ) as exists_test:
				newEv = self.engine.prepareEvent( ev.path, self.DEFAULT_CFG[0], ev.action )
				exists_test.assert_called_once_with( ev.path )
				hash_test.assert_called_once_with( ev.path )
		ev.isInDB = True
		ev.info = 'new'
		self.assertEqual( ev, newEv )