def test_is_vod_file_exists(self, mocker): # type: (MockFixture) -> None mocks = self.create_mocks(mocker) def side_effect_os_path_exists(path): # type: (str) -> bool return path in ['/tmp/nas'] mocks['os.path.exists'] = mocker.patch( 'os.path.exists', side_effect=side_effect_os_path_exists) obj = StorageNASAsyncImplement() obj.is_vod_dir_exists('filename') mocks['os.path.exists'].assert_called_with('/tmp/nas/vod/filename')
def test_delete_vod_dir(self, mocker): # type: (MockFixture) -> None mocks = self.create_mocks(mocker) def side_effect_os_path_exists(path): # type: (str) -> bool return path in ['/tmp/nas', '/tmp/nas/vod/dirname'] mocks['os.path.exists'] = mocker.patch( 'os.path.exists', side_effect=side_effect_os_path_exists) obj = StorageNASAsyncImplement() obj.delete_vod_dir('dirname') mocks['os.path.exists'].assert_called_with('/tmp/nas/vod/dirname') mocks['shutil.rmtree'].assert_called_once_with('/tmp/nas/vod/dirname')
def test_delete_upload_file(self, mocker): # type: (MockFixture) -> None mocks = self.create_mocks(mocker) def side_effect_os_path_exists(path): # type: (str) -> bool return path in ['/tmp/nas', '/tmp/nas/upload/filename'] mocks['os.path.exists'] = mocker.patch( 'os.path.exists', side_effect=side_effect_os_path_exists) obj = StorageNASAsyncImplement() filename, src_file = 'filename', '/tmp/nas/upload/filename' obj.delete_upload_file(filename) mocks['os.path.exists'].assert_called_with(src_file) mocks['os.remove'].assert_called_with(src_file)
def test_copy_vod_dir(self, mocker): # type: (MockFixture) -> None mocks = self.create_mocks(mocker) def side_effect_os_path_exists(path): # type: (str) -> bool return path in ['/tmp/nas', '/tmp/nas/vod/dirname'] mocks['os.path.exists'] = mocker.patch( 'os.path.exists', side_effect=side_effect_os_path_exists) obj = StorageNASAsyncImplement() src_dir, dst_dir = '/tmp/vod/dirname', '/tmp/nas/vod/dirname' obj.copy_vod_dir(src_dir) mocks['os.path.exists'].call_args_list == [ call(obj.VOD_PATH), call(dst_dir) ] mocks['shutil.rmtree'].assert_called_once_with(dst_dir) mocks['shutil.copytree'].assert_called_once_with(src_dir, dst_dir)
def test_get_upload_file(self, mocker): # type: (MockFixture) -> None mocks = self.create_mocks(mocker) def side_effect_os_path_exists(path): # type: (str) -> bool return path in [ '/tmp/nas', '/tmp/nas/upload/filename', '/tmp/upload/filename' ] mocks['os.path.exists'] = mocker.patch( 'os.path.exists', side_effect=side_effect_os_path_exists) obj = StorageNASAsyncImplement() dst_path, filename = '/tmp/upload', 'filename' src_file, dst_file = '/tmp/nas/upload/filename', dst_path + '/filename' obj.get_upload_file(filename, dst_path) mocks['os.path.exists'].assert_called_with(dst_file) mocks['os.remove'].assert_called_with(dst_file) mocks['shutil.copy'].assert_called_once_with(src_file, dst_path)
def test_move_upload_file(self, mocker): # type: (MockFixture) -> None mocks = self.create_mocks(mocker) def side_effect_os_path_exists(path): # type: (str) -> bool return path in ['/tmp/nas', '/tmp/nas/upload/filename'] mocks['os.path.exists'] = mocker.patch( 'os.path.exists', side_effect=side_effect_os_path_exists) obj = StorageNASAsyncImplement() src_file, filename = '/tmp/src_file', 'filename' dst_file = '/tmp/nas/upload/filename' obj.move_upload_file(src_file, filename) mocks['os.mkdir'].assert_called_once_with(obj.UPLOAD_PATH) mocks['os.path.exists'].call_args_list == [ call(obj.UPLOAD_PATH), call(dst_file) ] mocks['shutil.move'].assert_called_once_with(src_file, dst_file)