def setUp(self): self.setup_log_filter() self.tempdir = tempfile.mkdtemp() if not os.path.exists(self.tempdir): os.makedirs(self.tempdir) self.setup_downloader_log() models.initialize() app.in_unit_tests = True app.device_manager = devices.DeviceManager() models.Item._path_count_tracker.reset() testobjects.test_started(self) # Tweak Item to allow us to make up fake paths for FileItems models.Item._allow_nonexistent_paths = True # setup the deleted file checker item.setup_deleted_checker() item.start_deleted_checker() # Skip worker proccess for feedparser feed._RUN_FEED_PARSER_INLINE = True signals.system.connect('new-dialog', self.handle_new_dialog) # reload config and initialize it to temprary config.load_temporary() self.setup_config_watcher() self.platform = app.config.get(prefs.APP_PLATFORM) self.set_temp_support_directory() # for the unittests, both the database code and any UI code should run # in the main thread. threadcheck.set_eventloop_thread(threading.currentThread()) threadcheck.set_ui_thread(threading.currentThread()) self.raise_db_load_errors = True app.db = None self.allow_db_upgrade_error_dialog = False self.reload_database() self.setup_new_item_info_cache() self.setup_dummy_message_handlers() item.setup_metadata_manager(self.tempdir) searchengines._engines = [ searchengines.SearchEngineInfo(u"all", u"Search All", u"", -1) ] # reset the event loop util.chatter = False self.saw_error = False self.error_signal_okay = False signals.system.connect('error', self.handle_error) app.controller = DummyController() self.httpserver = None httpauth.init() # reset any logging records from our setUp call() self.log_filter.reset_records() # create an extension manager that searches our tempdir for extensions # NOTE: this doesn't actually load any extensions, since the directory # is currently empty. If you want to use the ExtensionManager you # need to put a .miroext file in the tempdir then call # app.extension_manager.load_extension() app.extension_manager = extensionmanager.ExtensionManager( [self.tempdir], []) # Create a download state object (but don't start the downloader # for the individual test unless necessary. In this case we override # the class to run the downloader). app.download_state_manager = downloader.DownloadStateManager() self.mock_patchers = []
def on_frontend_started(): """Perform startup actions that should happen after the frontend is already up and running. This function happens using an idle iterator. Before/after code that could take a while to run, we yield to other eventloop callbacks. """ conversions.conversion_manager.startup() item.setup_metadata_manager() item.setup_change_tracker() app.sharing_tracker = sharing.SharingTracker() app.sharing_manager.startup() app.sharing_tracker.start_tracking() app.device_manager = devices.DeviceManager() app.device_tracker = devicetracker.DeviceTracker() app.device_tracker.start_tracking() reconnect_downloaders() guide.download_guides() feed.remove_orphaned_feed_impls() app.download_state_manager = downloader.DownloadStateManager() app.download_state_manager.init_controller() itemsource.setup_handlers() if app.frontend_name == 'widgets': app.donate_manager = donate.DonateManager() else: logging.warn("frontend is %s, not starting DonateManager()", app.frontend_name) logging.info("Starting auto downloader...") autodler.start_downloader() app.icon_cache_updater.start_updates() yield None feed.expire_items() yield None commandline.startup() yield None autoupdate.check_for_updates() yield None app.local_metadata_manager.schedule_retry_net_lookup() # Delay running high CPU/IO operations for a bit eventloop.add_timeout(5, app.download_state_manager.startup_downloader, "start downloader daemon") eventloop.add_timeout(10, workerprocess.startup, "start worker process") eventloop.add_timeout(20, item.start_deleted_checker, "start checking deleted items") eventloop.add_timeout(30, feed.start_updates, "start feed updates") eventloop.add_timeout(60, item.update_incomplete_metadata, "update metadata data") eventloop.add_timeout(90, clear_icon_cache_orphans, "clear orphans")
app.startup_timer.log_time("after db upgrade") app.icon_cache_updater = iconcache.IconCacheUpdater() setup_global_feeds() # call fix_database_inconsistencies() ASAP after the manual feed is set up fix_database_inconsistencies() logging.info("setup tabs...") setup_tabs() logging.info("setup theme...") setup_theme() install_message_handler() app.sharing_manager = sharing.SharingManager() app.download_state_manager = downloader.DownloadStateManager() item.setup_change_tracker() item.setup_metadata_manager() _startup_checker.run_checks() def fix_database_inconsistencies(): item.fix_non_container_parents() item.move_orphaned_items() playlist.fix_missing_item_ids() folder.fix_playlist_missing_item_ids() class StartupChecker(object): """Handles various checks at startup. This class handles the first-time startup check and the movies directory gone check.
def test_live_storage_converts(self): # run upgrade 88 old_db_path = resources.path("testdata/olddatabase.predbupgrade88") shutil.copyfile(old_db_path, self.tmp_path) self.reload_database(self.tmp_path) app.db.upgrade_database() # reload the metadata manager since we now have a new DB setup_metadata_manager(self.tempdir) # figure out which maps were created folder_maps = set() playlist_maps = set() for map in PlaylistFolderItemMap.make_view(): folder_maps.add((map.playlist_id, map.item_id, map.position, map.count)) self.assert_(map.id is not None) for map in PlaylistItemMap.make_view(): playlist_maps.add((map.playlist_id, map.item_id, map.position)) self.assert_(map.id is not None) playlist1 = SavedPlaylist.make_view("title='playlist1'").get_singleton() playlist2 = SavedPlaylist.make_view("title='playlist2'").get_singleton() folder = PlaylistFolder.make_view().get_singleton() # Double check that we have the right item ids self.assertEquals(Item.get_by_id(242).get_title(), u"Berliner Brats n' Kraut") self.assertEquals(Item.get_by_id(240).get_title(), u"White Bean & Basil Bruschetta") self.assertEquals(Item.get_by_id(79).get_title(), u"Meet the GIMP!") self.assertEquals(Item.get_by_id(69).get_title(), u"Delicious TV Vegetarian (video)") # check that folder contains playlist 1 self.assertEquals(playlist1.folder_id, folder.id) self.assertEquals(playlist2.folder_id, folder.id) # Check that the playlist maps follow the following structure: # # folder1: # - Berliner Brats n' Kraut (id: 242) # - White Bean & Basil Bruschetta (id: 240) # - Meet the GIMP! (id: 79) # - Delicious TV Vegetarian (video) (id: 69) # playlist1 # - White Bean & Basil Bruschetta (id: 240) # - Berliner Brats n' Kraut (id: 242) # playlist2 # - Meet the GIMP! (id: 79) # - Delicious TV Vegetarian (video) (id: 69) # - White Bean & Basil Bruschetta (id: 240) self.assertEquals( folder_maps, set([(folder.id, 242, 0, 1), (folder.id, 240, 1, 2), (folder.id, 79, 2, 1), (folder.id, 69, 3, 1)]), ) self.assertEquals( playlist_maps, set( [ (playlist1.id, 240, 0), (playlist1.id, 242, 1), (playlist2.id, 79, 0), (playlist2.id, 69, 1), (playlist2.id, 240, 2), ] ), )