def get_files_no_section_no_extension_test(self): """ Test the AppLocation.get_files() method with no parameters passed. """ with patch('openlp.core.utils.AppLocation.get_data_path') as mocked_get_data_path, \ patch('openlp.core.utils.applocation.os.listdir') as mocked_listdir: # GIVEN: Our mocked modules/methods. mocked_get_data_path.return_value = 'test/dir' mocked_listdir.return_value = copy.deepcopy(FILE_LIST) # When: Get the list of files. result = AppLocation.get_files() # Then: check if the file lists are identical. assert result == FILE_LIST, 'The file lists should be identical.'
def get_files_test(self): """ Test the AppLocation.get_files() method with all parameters passed. """ with patch('openlp.core.utils.AppLocation.get_data_path') as mocked_get_data_path, \ patch('openlp.core.utils.applocation.os.listdir') as mocked_listdir: # GIVEN: Our mocked modules/methods. mocked_get_data_path.return_value = 'test/dir' mocked_listdir.return_value = copy.deepcopy(FILE_LIST) # When: Get the list of files. result = AppLocation.get_files('section', '.mp3') # Then: Check if the section parameter was used correctly. mocked_listdir.assert_called_with('test/dir/section') # Then: check if the file lists are identical. assert result == ['file5.mp3', 'file6.mp3'], 'The file lists should be identical.'
def reload_bibles(self): """ Reloads the Bibles from the available Bible databases on disk. If a web Bible is encountered, an instance of HTTPBible is loaded instead of the BibleDB class. """ log.debug('Reload bibles') files = AppLocation.get_files(self.settings_section, self.suffix) if 'alternative_book_names.sqlite' in files: files.remove('alternative_book_names.sqlite') log.debug('Bible Files %s', files) self.db_cache = {} self.old_bible_databases = [] for filename in files: bible = BibleDB(self.parent, path=self.path, file=filename) name = bible.get_name() # Remove corrupted files. if name is None: bible.session.close() delete_file(os.path.join(self.path, filename)) continue # Find old database versions. if bible.is_old_database(): self.old_bible_databases.append([filename, name]) bible.session.close() continue log.debug('Bible Name: "%s"', name) self.db_cache[name] = bible # Look to see if lazy load bible exists and get create getter. source = self.db_cache[name].get_object(BibleMeta, 'download_source') if source: download_name = self.db_cache[name].get_object(BibleMeta, 'download_name').value meta_proxy = self.db_cache[name].get_object(BibleMeta, 'proxy_server') web_bible = HTTPBible(self.parent, path=self.path, file=filename, download_source=source.value, download_name=download_name) if meta_proxy: web_bible.proxy_server = meta_proxy.value self.db_cache[name] = web_bible log.debug('Bibles reloaded')