def test_downloader_order(self): downloads = self.tracked_items[:4] for i, item_ in enumerate(downloads): # simulate a the download being in progress item_.download() # ensure that the downloads goes from slowest to fastest rate = i * 1024 fake_status = { 'current_size': 0, 'total_size': None, 'state': u'downloading', 'rate': rate, 'eta': None, 'type': 'HTTP', 'dlid': item_.downloader.dlid, } downloader.RemoteDownloader.update_status(fake_status) app.db.finish_transaction() self.check_items_changed_after_message(downloads) query = itemtrack.ItemTrackerQuery() query.add_condition('remote_downloader.state', '=', 'downloading') query.set_order_by(['remote_downloader.rate']) self.tracker.change_query(query) # Need to manually fetch the items to compare to with self.connection_pool.context() as connection: id_list = [i.id for i in downloads] correct_items = item.fetch_item_infos(connection, id_list) self.check_tracker_items(correct_items)
def test_auto_sync(self): # Test that add_items() sets the auto_sync flag correctly # setup some auto-sync settings self.set_feed_item_file_sizes(10) self.set_playlist_item_file_size(10) self.setup_auto_fill_settings(feed_space=1.0, playlist_space=0.0) dsm = app.device_manager.get_sync_for_device(self.device) # get our sync items, they should all be from our feed auto_sync_items = dsm.get_auto_items(10000) for item in auto_sync_items: self.assertEquals(item.feed_id, self.feed.id) # call sync some items playlist_items = fetch_item_infos(app.db.connection, [i.id for i in self.playlist_items]) dsm.start() dsm.add_items(playlist_items) dsm.add_items(auto_sync_items, auto_sync=True) self.runPendingIdles() # check that the device items got created and that auto_sync is set # correctly db_info=self.device.db_info for item in self.playlist_items: device_item = models.DeviceItem.get_by_url(item.url, db_info=db_info) self.assertEquals(device_item.auto_sync, False) for item in self.feed_items: device_item = models.DeviceItem.get_by_url(item.url, db_info=db_info) self.assertEquals(device_item.auto_sync, True) # check auto_sync_view() auto_sync_items = models.DeviceItem.auto_sync_view(db_info=db_info) self.assertSameSet(set(i.title for i in self.feed_items), set(i.title for i in auto_sync_items))
def test_auto_sync(self): # Test that add_items() sets the auto_sync flag correctly # setup some auto-sync settings self.set_feed_item_file_sizes(10) self.set_playlist_item_file_size(10) self.setup_auto_fill_settings(feed_space=1.0, playlist_space=0.0) dsm = app.device_manager.get_sync_for_device(self.device) # get our sync items, they should all be from our feed auto_sync_items = dsm.get_auto_items(10000) for item in auto_sync_items: self.assertEquals(item.feed_id, self.feed.id) # call sync some items playlist_items = fetch_item_infos(app.db.connection, [i.id for i in self.playlist_items]) dsm.start() dsm.add_items(playlist_items) dsm.add_items(auto_sync_items, auto_sync=True) self.runPendingIdles() # check that the device items got created and that auto_sync is set # correctly db_info = self.device.db_info for item in self.playlist_items: device_item = models.DeviceItem.get_by_url(item.url, db_info=db_info) self.assertEquals(device_item.auto_sync, False) for item in self.feed_items: device_item = models.DeviceItem.get_by_url(item.url, db_info=db_info) self.assertEquals(device_item.auto_sync, True) # check auto_sync_view() auto_sync_items = models.DeviceItem.auto_sync_view(db_info=db_info) self.assertSameSet(set(i.title for i in self.feed_items), set(i.title for i in auto_sync_items))
def on_item_changes(self, change_tracker, msg): if self.query.could_list_change(msg): # items may have been added/removed from the list. We need to # re-fetch the items and calculate changes self.refetch_items(msg.changed) else: # items changed, but the list is the same. Just refetch the # changed items. changed_ids = msg.changed.intersection(self.item_ids) changed_items = item.fetch_item_infos(app.db.connection, changed_ids) for item_info in changed_items: self.item_map[item_info.id] = item_info self.emit('items-changed', [], changed_items, [])
def on_item_changes(self, change_tracker, msg): if app.db.is_closed(): return if self.query.could_list_change(msg): # items may have been added/removed from the list. We need to # re-fetch the items and calculate changes self.refetch_items(msg.changed) else: # items changed, but the list is the same. Just refetch the # changed items. changed_ids = msg.changed.intersection(self.item_ids) changed_items = item.fetch_item_infos(app.db.connection, changed_ids) for item_info in changed_items: self.item_map[item_info.id] = item_info self.emit('items-changed', [], changed_items, [])
def fetch_item_infos(self, item_objects): if len(item_objects) == 0: return [] return item.fetch_item_infos(app.db.connection, [i.id for i in item_objects])
def fetch_item_infos(self): return item.fetch_item_infos(app.db, [i.id for i in self.items])
def make_item_info(itemobj): return fetch_item_infos(app.db.connection, [itemobj.id])[0]
def _get_item(self, item_id): item_list = item.fetch_item_infos(app.db.connection, [item_id]) return item_list[0]
def _get_item(self, item_id): app.connection_pool = mock.Mock() item_list = item.fetch_item_infos(app.db.connection, [item_id]) return item_list[0]