mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-14 22:30:33 +05:30
Merge pull request #234 from TeamNewPipe/fix/YT_search_test
Fix and improve tests
This commit is contained in:
commit
82eff772fa
@ -34,7 +34,7 @@ public abstract class LinkHandlerFactory {
|
||||
public abstract String getUrl(String id) throws ParsingException;
|
||||
public abstract boolean onAcceptUrl(final String url) throws ParsingException;
|
||||
|
||||
public String getUrl(String id, String baseUrl) throws ParsingException{
|
||||
public String getUrl(String id, String baseUrl) throws ParsingException {
|
||||
return getUrl(id);
|
||||
}
|
||||
|
||||
@ -43,13 +43,14 @@ public abstract class LinkHandlerFactory {
|
||||
///////////////////////////////////
|
||||
|
||||
public LinkHandler fromUrl(String url) throws ParsingException {
|
||||
if (url == null) throw new IllegalArgumentException("url can not be null");
|
||||
final String baseUrl = Utils.getBaseUrl(url);
|
||||
return fromUrl(url, baseUrl);
|
||||
}
|
||||
|
||||
public LinkHandler fromUrl(String url, String baseUrl) throws ParsingException {
|
||||
if(url == null) throw new IllegalArgumentException("url can not be null");
|
||||
if(!acceptUrl(url)) {
|
||||
if (url == null) throw new IllegalArgumentException("url can not be null");
|
||||
if (!acceptUrl(url)) {
|
||||
throw new ParsingException("Malformed unacceptable url: " + url);
|
||||
}
|
||||
|
||||
@ -58,13 +59,13 @@ public abstract class LinkHandlerFactory {
|
||||
}
|
||||
|
||||
public LinkHandler fromId(String id) throws ParsingException {
|
||||
if(id == null) throw new IllegalArgumentException("id can not be null");
|
||||
if (id == null) throw new IllegalArgumentException("id can not be null");
|
||||
final String url = getUrl(id);
|
||||
return new LinkHandler(url, url, id);
|
||||
}
|
||||
|
||||
public LinkHandler fromId(String id, String baseUrl) throws ParsingException {
|
||||
if(id == null) throw new IllegalArgumentException("id can not be null");
|
||||
if (id == null) throw new IllegalArgumentException("id can not be null");
|
||||
final String url = getUrl(id, baseUrl);
|
||||
return new LinkHandler(url, url, id);
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public class MediaCCCStreamExtractorTest implements BaseExtractorTest {
|
||||
|
||||
@Test
|
||||
public void testGetTextualUploadDate() throws ParsingException {
|
||||
Assert.assertEquals("2018-05-11", extractor.getTextualUploadDate());
|
||||
Assert.assertEquals("2018-05-11T02:00:00.000+02:00", extractor.getTextualUploadDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -77,8 +77,8 @@ public class YoutubeStreamLinkHandlerFactoryTest {
|
||||
assertEquals("jZViOEv90dI", linkHandler.fromUrl("http://www.Youtube.com/embed/jZViOEv90dI").getId());
|
||||
assertEquals("jZViOEv90dI", linkHandler.fromUrl("http://www.youtube-nocookie.com/embed/jZViOEv90dI").getId());
|
||||
assertEquals("EhxJLojIE_o", linkHandler.fromUrl("http://www.youtube.com/attribution_link?a=JdfC0C9V6ZI&u=%2Fwatch%3Fv%3DEhxJLojIE_o%26feature%3Dshare").getId());
|
||||
assertEquals("jZViOEv90dI", linkHandler.fromUrl("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI").getId());
|
||||
assertEquals("jZViOEv90dI", linkHandler.fromUrl("vnd.youtube:jZViOEv90dI").getId());
|
||||
assertEquals("jZViOEv90dI", linkHandler.fromUrl("vnd.youtube://www.youtube.com/watch?v=jZViOEv90dI", "youtube.com").getId());
|
||||
assertEquals("jZViOEv90dI", linkHandler.fromUrl("vnd.youtube:jZViOEv90dI", "youtube.com").getId());
|
||||
assertEquals("O0EDx9WAelc", linkHandler.fromUrl("https://music.youtube.com/watch?v=O0EDx9WAelc").getId());
|
||||
}
|
||||
|
||||
|
@ -1,36 +0,0 @@
|
||||
package org.schabi.newpipe.extractor.services.youtube.search;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.DownloaderTestImpl;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
|
||||
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor;
|
||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
|
||||
|
||||
/**
|
||||
* Test for {@link YoutubeSearchExtractor}
|
||||
*/
|
||||
public class YoutubeSearchCountTest {
|
||||
public static class YoutubeChannelViewCountTest extends YoutubeSearchExtractorBaseTest {
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
NewPipe.init(DownloaderTestImpl.getInstance());
|
||||
extractor = (YoutubeSearchExtractor) YouTube.getSearchExtractor("pewdiepie",
|
||||
singletonList(YoutubeSearchQueryHandlerFactory.CHANNELS), null);
|
||||
extractor.fetchPage();
|
||||
itemsPage = extractor.getInitialPage();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testViewCount() {
|
||||
ChannelInfoItem ci = (ChannelInfoItem) itemsPage.getItems().get(0);
|
||||
assertTrue("Count does not fit: " + Long.toString(ci.getSubscriberCount()),
|
||||
69043316 < ci.getSubscriberCount() && ci.getSubscriberCount() < 103043316);
|
||||
}
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@ public class YoutubeSearchExtractorChannelOnlyTest extends YoutubeSearchExtracto
|
||||
boolean equals = true;
|
||||
for (int i = 0; i < secondPage.getItems().size()
|
||||
&& i < itemsPage.getItems().size(); i++) {
|
||||
if(!secondPage.getItems().get(i).getUrl().equals(
|
||||
if (!secondPage.getItems().get(i).getUrl().equals(
|
||||
itemsPage.getItems().get(i).getUrl())) {
|
||||
equals = false;
|
||||
}
|
||||
@ -58,7 +58,7 @@ public class YoutubeSearchExtractorChannelOnlyTest extends YoutubeSearchExtracto
|
||||
@Test
|
||||
public void testOnlyContainChannels() {
|
||||
for(InfoItem item : itemsPage.getItems()) {
|
||||
if(!(item instanceof ChannelInfoItem)) {
|
||||
if (!(item instanceof ChannelInfoItem)) {
|
||||
fail("The following item is no channel item: " + item.toString());
|
||||
}
|
||||
}
|
||||
@ -78,4 +78,11 @@ public class YoutubeSearchExtractorChannelOnlyTest extends YoutubeSearchExtracto
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreamCount() {
|
||||
ChannelInfoItem ci = (ChannelInfoItem) itemsPage.getItems().get(0);
|
||||
assertTrue("Stream count does not fit: " + ci.getStreamCount(),
|
||||
4000 < ci.getStreamCount() && ci.getStreamCount() < 5500);
|
||||
}
|
||||
}
|
||||
|
@ -122,13 +122,13 @@ public class YoutubeStreamExtractorControversialTest {
|
||||
|
||||
@Test
|
||||
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
|
||||
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
|
||||
// Video (/view?v=T4XJQO3qol8) set in the setUp() method has at least auto-generated (English) captions
|
||||
assertFalse(extractor.getSubtitlesDefault().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSubtitlesList() throws IOException, ExtractionException {
|
||||
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
|
||||
// Video (/view?v=T4XJQO3qol8) set in the setUp() method has at least auto-generated (English) captions
|
||||
assertFalse(extractor.getSubtitles(MediaFormat.TTML).isEmpty());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user