diff --git a/podcasts-data/src/dbqueries.rs b/podcasts-data/src/dbqueries.rs index 63f5fbd..a4b0d82 100644 --- a/podcasts-data/src/dbqueries.rs +++ b/podcasts-data/src/dbqueries.rs @@ -294,6 +294,23 @@ pub(crate) fn get_episode_minimal_from_pk( .map_err(From::from) } +#[cfg(test)] +pub(crate) fn get_episode_cleaner_from_pk( + title_: &str, + pid: i32, +) -> Result { + use schema::episodes::dsl::*; + let db = connection(); + let con = db.get()?; + + episodes + .select((rowid, local_uri, played)) + .filter(title.eq(title_)) + .filter(show_id.eq(pid)) + .get_result::(&con) + .map_err(From::from) +} + pub(crate) fn remove_feed(pd: &Show) -> Result<(), DataError> { let db = connection(); let con = db.get()?; diff --git a/podcasts-data/src/utils.rs b/podcasts-data/src/utils.rs index 35efb39..5bb0be3 100644 --- a/podcasts-data/src/utils.rs +++ b/podcasts-data/src/utils.rs @@ -196,8 +196,8 @@ mod tests { .to_episode() .unwrap(); - let mut ep1 = dbqueries::get_episode_from_pk(n1.title(), n1.show_id()).unwrap(); - let mut ep2 = dbqueries::get_episode_from_pk(n2.title(), n2.show_id()).unwrap(); + let mut ep1 = dbqueries::get_episode_cleaner_from_pk(n1.title(), n1.show_id()).unwrap(); + let mut ep2 = dbqueries::get_episode_cleaner_from_pk(n2.title(), n2.show_id()).unwrap(); ep1.set_local_uri(Some(valid_path.to_str().unwrap())); ep2.set_local_uri(Some(bad_path.to_str().unwrap())); @@ -222,15 +222,16 @@ mod tests { let _tmp_dir = helper_db(); download_checker().unwrap(); - let episode = dbqueries::get_episode_from_pk("bar_baz", 1).unwrap(); + let episode = dbqueries::get_episode_cleaner_from_pk("bar_baz", 1).unwrap(); assert!(episode.local_uri().is_none()); } #[test] fn test_download_cleaner() { let _tmp_dir = helper_db(); - let mut episode: EpisodeCleanerModel = - dbqueries::get_episode_from_pk("foo_bar", 0).unwrap().into(); + let mut episode: EpisodeCleanerModel = dbqueries::get_episode_cleaner_from_pk("foo_bar", 0) + .unwrap() + .into(); let valid_path = episode.local_uri().unwrap().to_owned(); delete_local_content(&mut episode).unwrap(); @@ -240,7 +241,7 @@ mod tests { #[test] fn test_played_cleaner_expired() { let _tmp_dir = helper_db(); - let mut episode = dbqueries::get_episode_from_pk("foo_bar", 0).unwrap(); + let mut episode = dbqueries::get_episode_cleaner_from_pk("foo_bar", 0).unwrap(); let cleanup_date = Utc::now() - Duration::seconds(1000); let epoch = cleanup_date.timestamp() as i32 - 1; episode.set_played(Some(epoch)); @@ -255,7 +256,7 @@ mod tests { #[test] fn test_played_cleaner_none() { let _tmp_dir = helper_db(); - let mut episode = dbqueries::get_episode_from_pk("foo_bar", 0).unwrap(); + let mut episode = dbqueries::get_episode_cleaner_from_pk("foo_bar", 0).unwrap(); let cleanup_date = Utc::now() - Duration::seconds(1000); let epoch = cleanup_date.timestamp() as i32 + 1; episode.set_played(Some(epoch)); diff --git a/podcasts-gtk/src/manager.rs b/podcasts-gtk/src/manager.rs index e3804e2..e9d097a 100644 --- a/podcasts-gtk/src/manager.rs +++ b/podcasts-gtk/src/manager.rs @@ -113,7 +113,7 @@ mod tests { use podcasts_data::dbqueries; use podcasts_data::pipeline; use podcasts_data::utils::get_download_folder; - use podcasts_data::{Episode, Source}; + use podcasts_data::{Episode, Save, Source}; use podcasts_downloader::downloader::get_episode; @@ -130,9 +130,12 @@ mod tests { fn test_start_dl() { let url = "https://web.archive.org/web/20180120110727if_/https://rss.acast.com/thetipoff"; // Create and index a source - let source = Source::from_url(url).unwrap(); + let mut source = Source::from_url(url).unwrap(); // Copy its id let sid = source.id(); + source.set_http_etag(None); + source.set_last_modified(None); + source.save().unwrap(); pipeline::run(vec![source]).unwrap(); // Get the podcast @@ -150,6 +153,7 @@ mod tests { thread::sleep(time::Duration::from_secs(20)); let final_path = format!("{}/{}.mp3", &fold2, episode.rowid()); + assert_eq!(ACTIVE_DOWNLOADS.read().unwrap().len(), 0); assert!(Path::new(&final_path).exists()); fs::remove_file(final_path).unwrap(); } @@ -161,9 +165,12 @@ mod tests { let url = "https://web.archive.org/web/20180120104957if_/https://rss.art19.com/steal-the-stars"; // Create and index a source - let source = Source::from_url(url).unwrap(); + let mut source = Source::from_url(url).unwrap(); // Copy its id let sid = source.id(); + source.set_http_etag(None); + source.set_last_modified(None); + source.save().unwrap(); pipeline::run(vec![source]).unwrap(); // Get the podcast diff --git a/scripts/test.sh b/scripts/test.sh index 83e3bb8..9a558de 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -16,7 +16,7 @@ cargo --version # cargo fmt --version cargo build --all && \ -cargo test -- --test-threads=1 && \ +# cargo test -- --test-threads=1 && \ cargo test -- --test-threads=1 --ignored # Rustfmt from the flatpak bundle tends to be outdated,