Migrate podcast tests to use the internet archive snapshots.
This commit is contained in:
@@ -118,9 +118,9 @@ impl NewPodcast {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
// Ignore the following geters. They are used in unit tests mainly.
|
||||
impl NewPodcast {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn source_id(&self) -> i32 {
|
||||
self.source_id
|
||||
}
|
||||
@@ -141,3 +141,145 @@ impl NewPodcast {
|
||||
self.image_uri.as_ref().map(|s| s.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
// use tokio_core::reactor::Core;
|
||||
|
||||
use rss::Channel;
|
||||
|
||||
use models::NewPodcastBuilder;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
|
||||
#[test]
|
||||
fn test_new_podcast_intercepted() {
|
||||
let file = File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let descr = "The people behind The Intercept’s fearless reporting and incisive \
|
||||
commentary—Jeremy Scahill, Glenn Greenwald, Betsy Reed and others—discuss \
|
||||
the crucial issues of our time: national security, civil liberties, foreign \
|
||||
policy, and criminal justice. Plus interviews with artists, thinkers, and \
|
||||
newsmakers who challenge our preconceptions about the world we live in.";
|
||||
|
||||
let pd = NewPodcast::new(&channel, 0);
|
||||
let expected = NewPodcastBuilder::default()
|
||||
.title("Intercepted with Jeremy Scahill")
|
||||
.link("https://theintercept.com/podcasts")
|
||||
.description(descr)
|
||||
.image_uri(Some(String::from(
|
||||
"http://static.megaphone.fm/podcasts/d5735a50-d904-11e6-8532-73c7de466ea6/image/\
|
||||
uploads_2F1484252190700-qhn5krasklbce3dh-a797539282700ea0298a3a26f7e49b0b_\
|
||||
2FIntercepted_COVER%2B_281_29.png")
|
||||
))
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(pd, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_podcast_lup() {
|
||||
let file = File::open("tests/feeds/2018-01-20-LinuxUnplugged.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let descr = "An open show powered by community LINUX Unplugged takes the best attributes \
|
||||
of open collaboration and focuses them into a weekly lifestyle show about \
|
||||
Linux.";
|
||||
let pd = NewPodcast::new(&channel, 0);
|
||||
|
||||
let expected = NewPodcastBuilder::default()
|
||||
.title("LINUX Unplugged Podcast")
|
||||
.link("http://www.jupiterbroadcasting.com/")
|
||||
.description(descr)
|
||||
.image_uri(Some(String::from(
|
||||
"http://www.jupiterbroadcasting.com/images/LASUN-Badge1400.jpg",
|
||||
)))
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(pd, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_podcast_thetipoff() {
|
||||
let file = File::open("tests/feeds/2018-01-20-TheTipOff.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let desc = "Welcome to The Tip Off- the podcast where we take you behind the scenes of \
|
||||
some of the best investigative journalism from recent years. Each episode \
|
||||
we’ll be digging into an investigative scoop- hearing from the journalists \
|
||||
behind the work as they tell us about the leads, the dead-ends and of course, \
|
||||
the tip offs. There’ll be car chases, slammed doors, terrorist cells, \
|
||||
meetings in dimly lit bars and cafes, wrangling with despotic regimes and \
|
||||
much more. So if you’re curious about the fun, complicated detective work \
|
||||
that goes into doing great investigative journalism- then this is the podcast \
|
||||
for you.";
|
||||
let pd = NewPodcast::new(&channel, 0);
|
||||
|
||||
let expected = NewPodcastBuilder::default()
|
||||
.title("The Tip Off")
|
||||
.link("http://www.acast.com/thetipoff")
|
||||
.description(desc)
|
||||
.image_uri(Some(String::from(
|
||||
"https://imagecdn.acast.com/image?h=1500&w=1500&source=http%3A%2F%2Fi1.sndcdn.\
|
||||
com%2Favatars-000317856075-a2coqz-original.jpg",
|
||||
)))
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(pd, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_podcast_steal_the_stars() {
|
||||
let file = File::open("tests/feeds/2018-01-20-StealTheStars.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let descr = "<p>The first audio drama from Tor Labs and Gideon Media, Steal the Stars is \
|
||||
a gripping noir science fiction thriller in 14 episodes: Forbidden love, a \
|
||||
crashed UFO, an alien body, and an impossible heist unlike any ever \
|
||||
attempted - scripted by Mac Rogers, the award-winning playwright and writer \
|
||||
of the multi-million download The Message and LifeAfter.</p>";
|
||||
let img = "https://dfkfj8j276wwv.cloudfront.net/images/2c/5f/a0/1a/2c5fa01a-ae78-4a8c-\
|
||||
b183-7311d2e436c3/b3a4aa57a576bb662191f2a6bc2a436c8c4ae256ecffaff5c4c54fd42e\
|
||||
923914941c264d01efb1833234b52c9530e67d28a8cebbe3d11a4bc0fbbdf13ecdf1c3.jpeg";
|
||||
let pd = NewPodcast::new(&channel, 0);
|
||||
|
||||
let expected = NewPodcastBuilder::default()
|
||||
.title("Steal the Stars")
|
||||
.link("http://tor-labs.com/")
|
||||
.description(descr)
|
||||
.image_uri(Some(String::from(img)))
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(pd, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_podcast_greater_than_code() {
|
||||
let file = File::open("tests/feeds/2018-01-20-GreaterThanCode.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let descr = "A podcast about humans and technology. Panelists: Coraline Ada Ehmke, David \
|
||||
Brady, Jessica Kerr, Jay Bobo, Astrid Countee and Sam Livingston-Gray. \
|
||||
Brought to you by @therubyrep.";
|
||||
let pd = NewPodcast::new(&channel, 0);
|
||||
|
||||
let expected = NewPodcastBuilder::default()
|
||||
.title("Greater Than Code")
|
||||
.link("https://www.greaterthancode.com/")
|
||||
.description(descr)
|
||||
.image_uri(Some(String::from(
|
||||
"http://www.greaterthancode.com/wp-content/uploads/2016/10/code1400-4.jpg",
|
||||
)))
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(pd, expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,10 +171,7 @@ fn response_to_channel(res: Response) -> Box<Future<Item = Channel, Error = Erro
|
||||
.map_err(From::from)
|
||||
.and_then(|iter| ok(iter.collect::<Vec<u8>>()))
|
||||
.and_then(|utf_8_bytes| ok(String::from_utf8_lossy(&utf_8_bytes).into_owned()))
|
||||
.and_then(|buf| {
|
||||
println!("{:?}", buf);
|
||||
Channel::from_str(&buf).map_err(From::from)
|
||||
});
|
||||
.and_then(|buf| Channel::from_str(&buf).map_err(From::from));
|
||||
|
||||
Box::new(chan)
|
||||
}
|
||||
@@ -213,8 +210,7 @@ mod tests {
|
||||
use tokio_core::reactor::Core;
|
||||
|
||||
use database::truncate_db;
|
||||
use std::fs;
|
||||
use std::io::BufReader;
|
||||
use utils::get_feed;
|
||||
|
||||
#[test]
|
||||
fn test_into_feed() {
|
||||
@@ -229,23 +225,11 @@ mod tests {
|
||||
com/InterceptedWithJeremyScahill";
|
||||
let source = Source::from_url(url).unwrap();
|
||||
let id = source.id();
|
||||
println!("{:?}", source);
|
||||
|
||||
let feed = source.into_feed(&client, true);
|
||||
let feed = core.run(feed).unwrap();
|
||||
|
||||
let good = {
|
||||
// open the xml file
|
||||
let feed = fs::File::open("tests/feeds/2018-01-20-Intercepted.xml").unwrap();
|
||||
// parse it into a channel
|
||||
let chan = Channel::read_from(BufReader::new(feed)).unwrap();
|
||||
FeedBuilder::default()
|
||||
.channel(chan)
|
||||
.source_id(id)
|
||||
.build()
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
assert_eq!(good, feed);
|
||||
let expected = get_feed("tests/feeds/2018-01-20-Intercepted.xml", id);
|
||||
assert_eq!(expected, feed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ pub(crate) fn parse_itunes_duration(item: &Item) -> Option<i32> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use models::{NewEpisode, NewEpisodeBuilder};
|
||||
use models::{NewPodcast, NewPodcastBuilder};
|
||||
|
||||
use rss::{Channel, ItemBuilder};
|
||||
use rss::extension::itunes::ITunesItemExtensionBuilder;
|
||||
@@ -100,98 +99,6 @@ mod tests {
|
||||
assert_eq!(parse_itunes_duration(&item), Some(6970));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_podcast_intercepted() {
|
||||
let file = File::open("tests/feeds/Intercepted.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let descr = "The people behind The Intercept’s fearless reporting and incisive \
|
||||
commentary—Jeremy Scahill, Glenn Greenwald, Betsy Reed and others—discuss \
|
||||
the crucial issues of our time: national security, civil liberties, foreign \
|
||||
policy, and criminal justice. Plus interviews with artists, thinkers, and \
|
||||
newsmakers who challenge our preconceptions about the world we live in.";
|
||||
|
||||
let pd = NewPodcast::new(&channel, 0);
|
||||
let expected = NewPodcastBuilder::default()
|
||||
.title("Intercepted with Jeremy Scahill")
|
||||
.link("https://theintercept.com/podcasts")
|
||||
.description(descr)
|
||||
.image_uri(Some(String::from(
|
||||
"http://static.megaphone.fm/podcasts/d5735a50-d904-11e6-8532-73c7de466ea6/image/\
|
||||
uploads_2F1484252190700-qhn5krasklbce3dh-a797539282700ea0298a3a26f7e49b0b_\
|
||||
2FIntercepted_COVER%2B_281_29.png")
|
||||
))
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(pd, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_podcast_breakthrough() {
|
||||
let file = File::open("tests/feeds/TheBreakthrough.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let descr = "The podcast that takes you behind the scenes with journalists to hear how \
|
||||
they nailed their biggest stories.";
|
||||
let pd = NewPodcast::new(&channel, 0);
|
||||
|
||||
let expected = NewPodcastBuilder::default()
|
||||
.title("The Breakthrough")
|
||||
.link("http://www.propublica.org/podcast")
|
||||
.description(descr)
|
||||
.image_uri(Some(String::from(
|
||||
"http://www.propublica.org/images/podcast_logo_2.png",
|
||||
)))
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(pd, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_podcast_lup() {
|
||||
let file = File::open("tests/feeds/LinuxUnplugged.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let descr = "An open show powered by community LINUX Unplugged takes the best attributes \
|
||||
of open collaboration and focuses them into a weekly lifestyle show about \
|
||||
Linux.";
|
||||
let pd = NewPodcast::new(&channel, 0);
|
||||
|
||||
let expected = NewPodcastBuilder::default()
|
||||
.title("LINUX Unplugged Podcast")
|
||||
.link("http://www.jupiterbroadcasting.com/")
|
||||
.description(descr)
|
||||
.image_uri(Some(String::from(
|
||||
"http://www.jupiterbroadcasting.com/images/LASUN-Badge1400.jpg",
|
||||
)))
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(pd, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_podcast_r4explanation() {
|
||||
let file = File::open("tests/feeds/R4Explanation.xml").unwrap();
|
||||
let channel = Channel::read_from(BufReader::new(file)).unwrap();
|
||||
|
||||
let pd = NewPodcast::new(&channel, 0);
|
||||
|
||||
let expected = NewPodcastBuilder::default()
|
||||
.title("Request For Explanation")
|
||||
.link("https://request-for-explanation.github.io/podcast/")
|
||||
.description("A weekly discussion of Rust RFCs")
|
||||
.image_uri(Some(String::from(
|
||||
"https://request-for-explanation.github.io/podcast/podcast.png",
|
||||
)))
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(pd, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_episode_intercepted() {
|
||||
let file = File::open("tests/feeds/Intercepted.xml").unwrap();
|
||||
|
||||
@@ -147,6 +147,29 @@ pub fn delete_show(pd: &Podcast) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
use Feed;
|
||||
|
||||
#[cfg(test)]
|
||||
/// Helper function that open a local file, parse the rss::Channel and gives back a Feed object.
|
||||
/// Alternative Feed constructor to be used for tests.
|
||||
pub fn get_feed(file_path: &str, id: i32) -> Feed {
|
||||
use feed::FeedBuilder;
|
||||
use rss::Channel;
|
||||
use std::fs;
|
||||
use std::io::BufReader;
|
||||
|
||||
// open the xml file
|
||||
let feed = fs::File::open(file_path).unwrap();
|
||||
// parse it into a channel
|
||||
let chan = Channel::read_from(BufReader::new(feed)).unwrap();
|
||||
FeedBuilder::default()
|
||||
.channel(chan)
|
||||
.source_id(id)
|
||||
.build()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate tempdir;
|
||||
|
||||
Reference in New Issue
Block a user