New Bandcamp tests for channel extractor

This commit is contained in:
Fynn Godau 2020-05-25 20:22:23 +02:00
parent e08256ebc6
commit 89b0639faa
2 changed files with 69 additions and 28 deletions

View File

@ -8,54 +8,89 @@ import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor; import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper;
import static org.junit.Assert.assertEquals; import java.io.IOException;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.schabi.newpipe.extractor.ServiceList.Bandcamp; import static org.schabi.newpipe.extractor.ServiceList.Bandcamp;
public class BandcampChannelExtractorTest { public class BandcampChannelExtractorTest implements BaseChannelExtractorTest {
private static BandcampChannelExtractor extractor; private static ChannelExtractor extractor;
private static ChannelExtractor noAvatarExtractor;
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance()); NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (BandcampChannelExtractor) Bandcamp extractor = Bandcamp.getChannelExtractor("https://npet.bandcamp.com/releases");
.getChannelExtractor("https://zachbenson.bandcamp.com/");
extractor.fetchPage(); extractor.fetchPage();
noAvatarExtractor = Bandcamp.getChannelExtractor("https://npet.bandcamp.com/");
noAvatarExtractor.fetchPage();
} }
@Test @Test
public void testTranslateIdsToUrl() throws ParsingException { public void testLength() throws ExtractionException, IOException {
assertEquals("https://zachbenson.bandcamp.com/album/covers", BandcampExtractorHelper.getStreamUrlFromIds(2862267535L, 2063639444L, "album")); assertTrue(extractor.getInitialPage().getItems().size() >= 1);
// TODO write more test cases
} }
@Override
@Test @Test
public void testLength() throws ParsingException { public void testDescription() throws Exception {
assertTrue(extractor.getInitialPage().getItems().size() > 2); assertEquals("This string will be tested for in NewPipeExtractor tests.", extractor.getDescription());
} }
@Test @Override
public void testGetBannerUrl() throws ParsingException { public void testAvatarUrl() throws Exception {
// Why is this picture in png format when all other pictures are jpg? // Has no avatar
assertTrue(extractor.getBannerUrl().endsWith(".png")); assertEquals("", extractor.getAvatarUrl());
} }
@Test @Override
public void testGetNoAvatar() throws ExtractionException { public void testBannerUrl() throws Exception {
assertEquals("", noAvatarExtractor.getAvatarUrl()); // Has no banner
assertEquals("", extractor.getBannerUrl());
} }
@Test @Override
public void testGetNoBanner() throws ExtractionException { public void testFeedUrl() throws Exception {
assertEquals("", noAvatarExtractor.getBannerUrl()); assertNull(extractor.getFeedUrl());
}
@Override
public void testSubscriberCount() throws Exception {
assertEquals(-1, extractor.getSubscriberCount());
}
@Override
public void testRelatedItems() throws Exception {
// not implemented
}
@Override
public void testMoreRelatedItems() throws Exception {
// not implemented
}
@Override
public void testServiceId() throws Exception {
assertEquals(4, extractor.getServiceId());
}
@Override
public void testName() throws Exception {
assertEquals("NewPipeExtractorTest", extractor.getName());
}
@Override
public void testId() throws Exception {
assertEquals("https://npet.bandcamp.com/", extractor.getId());
}
@Override
public void testUrl() throws Exception {
assertEquals("https://npet.bandcamp.com/releases", extractor.getUrl());
}
@Override
public void testOriginalUrl() throws Exception {
assertEquals("https://npet.bandcamp.com/releases", extractor.getUrl());
} }
} }

View File

@ -8,6 +8,7 @@ import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper;
import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor; import org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamExtractor; import org.schabi.newpipe.extractor.stream.StreamExtractor;
@ -84,5 +85,10 @@ public class BandcampStreamExtractorTest {
assertEquals("CC BY 3.0", se.getLicence()); assertEquals("CC BY 3.0", se.getLicence());
} }
@Test
public void testTranslateIdsToUrl() throws ParsingException {
assertEquals("https://zachbenson.bandcamp.com/album/covers", BandcampExtractorHelper.getStreamUrlFromIds(2862267535L, 2063639444L, "album"));
// TODO write more test cases
}
} }