def createMultipleAssetsFromPresentationOrPdf(asset, conn): uri = asset['uri'] name = asset['name'] uri_new = uri if (asset['mimetype'] == 'presentation'): convertToPdf(name, uri) extractFrames(uri + ".pdf") unlink(uri + ".pdf") uri_new = uri_new + ".pdf" else: extractFrames(uri) unlink(uri) new_assets = [] for index, fileName in list(enumerate(glob.glob(uri_new + '*.png'))): new_asset = copy.deepcopy(asset) new_asset['asset_id'] = uuid.uuid4().hex new_asset['name'] = name + str(index + 1) + ".png" #new_asset['uri'] = fileName new_asset['uri'] = path.join(settings['assetdir'], new_asset['asset_id']) rename(fileName, new_asset['uri']) new_assets.append(new_asset) assets_helper.create_multiple(conn, new_assets) #assets_helper.save_ordering(conn, [asset['asset_id'] for asset in new_assets]) return new_assets
def test_generate_asset_list_check_deadline_if_asset_scheduled(self): """If asset_x is active and asset_x[end_date] == (now + 3) and asset_tomorrow will be active tomorrow then deadline should be asset_tomorrow[start_date] """ assets_helper.create_multiple(viewer.db_conn, [asset_x, asset_tomorrow]) _, deadline = viewer.generate_asset_list() self.assertEqual(deadline, asset_tomorrow['start_date'])
def test_get_next_asset_should_be_y_and_x(self): assets_helper.create_multiple(viewer.db_conn, [asset_x, asset_y]) sch = viewer.Scheduler() expect_y = sch.get_next_asset() expect_x = sch.get_next_asset() self.assertEqual([expect_y, expect_x], [asset_y, asset_x])
def test_set_order_empty(self): assets = [asset_x, asset_y, asset_z] assets_helper.create_multiple(self.conn, assets) assets_helper.save_ordering(self.conn, []) fetched = assets_helper.read(self.conn) self.assertEquals([0, 0, 0], [asset['play_order'] for asset in fetched])
def test_keep_same_position_on_playlist_update(self): assets_helper.create_multiple(viewer.db_conn, [asset_x, asset_y]) sch = viewer.Scheduler() sch.get_next_asset() assets_helper.create(viewer.db_conn, asset_z) sch.update_playlist() self.assertEqual(sch.index, 1)
def test_playlist_should_be_updated_after_deadline_reached(self): assets_helper.create_multiple(viewer.db_conn, [asset_x, asset_y]) _, deadline = viewer.generate_asset_list() fake = FakeDatetime(deadline + timedelta(seconds=1)) viewer.datetime, assets_helper.get_time = fake, lambda: fake.utcnow() sch = viewer.Scheduler() sch.refresh_playlist() self.assertEqual([asset_x], sch.assets)
def test_counter_should_increment_after_full_asset_loop(self): settings.settings['shuffle_playlist'] = True assets_helper.create_multiple(viewer.db_conn, [asset_x, asset_y]) sch = viewer.Scheduler() self.assertEqual(sch.counter, 0) sch.get_next_asset() sch.get_next_asset() self.assertEqual(sch.counter, 1)
def test_set_order(self): assets = [asset_x, asset_y, asset_z, asset_w] for_order = [asset_y, asset_x] assets_helper.create_multiple(self.conn, assets) assets_helper.save_ordering(self.conn, [asset['asset_id'] for asset in for_order]) fetched = assets_helper.read(self.conn) self.assertEquals([(0, asset_y['asset_id']), (1, asset_x['asset_id']), (2, asset_z['asset_id']), (2, asset_w['asset_id'])], [(asset['play_order'], asset['asset_id']) for asset in fetched])
def test_set_order(self): assets = [asset_x, asset_y, asset_z, asset_w] for_order = [asset_y, asset_x] assets_helper.create_multiple(self.conn, assets) assets_helper.save_ordering(self.conn, [asset['asset_id'] for asset in for_order]) fetched = assets_helper.read(self.conn) self.assertEquals( [(0, asset_y['asset_id']), (1, asset_x['asset_id']), (2, asset_z['asset_id']), (2, asset_w['asset_id'])], [(asset['play_order'], asset['asset_id']) for asset in fetched])
def test_generate_asset_list_check_deadline(self): assets_helper.create_multiple(viewer.db_conn, [asset_x, asset_y]) _, deadline = viewer.generate_asset_list() self.assertEqual(deadline, asset_y['end_date'])
def test_generate_asset_list_check_deadline_if_both_active(self): # if x and y currently active assets_helper.create_multiple(viewer.db_conn, [asset_x, asset_y]) _, deadline = viewer.generate_asset_list() self.assertEqual(deadline, asset_y['end_date'])
def test_generate_asset_list_assets_should_be_y_and_x(self): assets_helper.create_multiple(viewer.db_conn, [asset_x, asset_y]) assets, _ = viewer.generate_asset_list() self.assertEqual(assets, [asset_y, asset_x])