From 0ee2072de58bf18b1b9ff072de501217f1ee98ab Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Sun, 16 Jul 2023 20:40:52 +0200 Subject: [PATCH] [PeerTube] Implement link handlers and channels tabs and tags changes on tests Co-authored-by: ThetaDev --- .../PeertubeAccountExtractorTest.java | 69 +++--- .../PeertubeAccountTabExtractorTest.java | 150 +++++++++++++ .../PeertubeChannelExtractorTest.java | 72 +++--- .../PeertubeChannelTabExtractorTest.java | 212 ++++++++++++++++++ ...eertubeTrendingLinkHandlerFactoryTest.java | 2 +- 5 files changed, 421 insertions(+), 84 deletions(-) create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeAccountTabExtractorTest.java create mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelTabExtractorTest.java diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeAccountExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeAccountExtractorTest.java index ec5bac31d..4bedb0b07 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeAccountExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeAccountExtractorTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test; import org.schabi.newpipe.downloader.DownloaderTestImpl; import org.schabi.newpipe.extractor.ExtractorAsserts; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.channel.ChannelExtractor; +import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest; import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeAccountExtractor; @@ -14,11 +14,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; +import static org.schabi.newpipe.extractor.ExtractorAsserts.assertTabsContained; import static org.schabi.newpipe.extractor.ServiceList.PeerTube; -import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestGetPageInNewExtractor; -import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestMoreItems; -import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems; /** * Test for {@link PeertubeAccountExtractor} @@ -67,20 +66,6 @@ public class PeertubeAccountExtractorTest { assertEquals("https://framatube.org/accounts/framasoft", extractor.getOriginalUrl()); } - /*////////////////////////////////////////////////////////////////////////// - // ListExtractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testRelatedItems() throws Exception { - defaultTestRelatedItems(extractor); - } - - @Test - public void testMoreRelatedItems() throws Exception { - defaultTestMoreItems(extractor); - } - /*////////////////////////////////////////////////////////////////////////// // ChannelExtractor //////////////////////////////////////////////////////////////////////////*/ @@ -114,6 +99,18 @@ public class PeertubeAccountExtractorTest { public void testVerified() throws Exception { assertFalse(extractor.isVerified()); } + + @Test + @Override + public void testTabs() throws Exception { + assertTabsContained(extractor.getTabs(), ChannelTabs.VIDEOS, ChannelTabs.CHANNELS); + } + + @Test + @Override + public void testTags() throws Exception { + assertTrue(extractor.getTags().isEmpty()); + } } public static class FreeSoftwareFoundation implements BaseChannelExtractorTest { @@ -129,16 +126,6 @@ public class PeertubeAccountExtractorTest { extractor.fetchPage(); } - /*////////////////////////////////////////////////////////////////////////// - // Additional Testing - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testGetPageInNewExtractor() throws Exception { - final ChannelExtractor newExtractor = PeerTube.getChannelExtractor(extractor.getUrl()); - defaultTestGetPageInNewExtractor(extractor, newExtractor); - } - /*////////////////////////////////////////////////////////////////////////// // Extractor //////////////////////////////////////////////////////////////////////////*/ @@ -168,20 +155,6 @@ public class PeertubeAccountExtractorTest { assertEquals("https://framatube.org/api/v1/accounts/fsf", extractor.getOriginalUrl()); } - /*////////////////////////////////////////////////////////////////////////// - // ListExtractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testRelatedItems() throws Exception { - defaultTestRelatedItems(extractor); - } - - @Test - public void testMoreRelatedItems() throws Exception { - defaultTestMoreItems(extractor); - } - /*////////////////////////////////////////////////////////////////////////// // ChannelExtractor //////////////////////////////////////////////////////////////////////////*/ @@ -215,5 +188,17 @@ public class PeertubeAccountExtractorTest { public void testVerified() throws Exception { assertFalse(extractor.isVerified()); } + + @Test + @Override + public void testTabs() throws Exception { + assertTabsContained(extractor.getTabs(), ChannelTabs.VIDEOS, ChannelTabs.CHANNELS); + } + + @Test + @Override + public void testTags() throws Exception { + assertTrue(extractor.getTags().isEmpty()); + } } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeAccountTabExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeAccountTabExtractorTest.java new file mode 100644 index 000000000..fa339b41b --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeAccountTabExtractorTest.java @@ -0,0 +1,150 @@ +package org.schabi.newpipe.extractor.services.peertube; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.schabi.newpipe.downloader.DownloaderTestImpl; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.services.BaseListExtractorTest; +import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeChannelTabExtractor; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.schabi.newpipe.extractor.ServiceList.PeerTube; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestMoreItems; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems; + +class PeertubeAccountTabExtractorTest { + + static class Videos implements BaseListExtractorTest { + private static PeertubeChannelTabExtractor extractor; + + @BeforeAll + static void setUp() throws Exception { + NewPipe.init(DownloaderTestImpl.getInstance()); + // setting instance might break test when running in parallel + PeerTube.setInstance(new PeertubeInstance("https://framatube.org", "Framatube")); + extractor = (PeertubeChannelTabExtractor) PeerTube + .getChannelTabExtractorFromId("accounts/framasoft", ChannelTabs.VIDEOS); + extractor.fetchPage(); + } + + /*////////////////////////////////////////////////////////////////////////// + // Extractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + @Override + public void testServiceId() { + assertEquals(PeerTube.getServiceId(), extractor.getServiceId()); + } + + @Test + @Override + public void testName() throws ParsingException { + assertEquals(ChannelTabs.VIDEOS, extractor.getName()); + } + + @Test + @Override + public void testId() throws ParsingException { + assertEquals("accounts/framasoft", extractor.getId()); + } + + @Test + @Override + public void testUrl() throws ParsingException { + assertEquals("https://framatube.org/accounts/framasoft/videos", + extractor.getUrl()); + } + + @Test + @Override + public void testOriginalUrl() throws ParsingException { + assertEquals("https://framatube.org/accounts/framasoft/videos", + extractor.getOriginalUrl()); + } + + /*////////////////////////////////////////////////////////////////////////// + // ListExtractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + @Override + public void testRelatedItems() throws Exception { + defaultTestRelatedItems(extractor); + } + + @Test + @Override + public void testMoreRelatedItems() throws Exception { + defaultTestMoreItems(extractor); + } + } + + static class Channels implements BaseListExtractorTest { + private static PeertubeChannelTabExtractor extractor; + + @BeforeAll + static void setUp() throws Exception { + NewPipe.init(DownloaderTestImpl.getInstance()); + // setting instance might break test when running in parallel + PeerTube.setInstance(new PeertubeInstance("https://framatube.org", "Framatube")); + extractor = (PeertubeChannelTabExtractor) PeerTube + .getChannelTabExtractorFromId("accounts/framasoft", ChannelTabs.CHANNELS); + extractor.fetchPage(); + } + + /*////////////////////////////////////////////////////////////////////////// + // Extractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + @Override + public void testServiceId() { + assertEquals(PeerTube.getServiceId(), extractor.getServiceId()); + } + + @Test + @Override + public void testName() throws ParsingException { + assertEquals(ChannelTabs.CHANNELS, extractor.getName()); + } + + @Test + @Override + public void testId() throws ParsingException { + assertEquals("accounts/framasoft", extractor.getId()); + } + + @Test + @Override + public void testUrl() throws ParsingException { + assertEquals("https://framatube.org/accounts/framasoft/video-channels", + extractor.getUrl()); + } + + @Test + @Override + public void testOriginalUrl() throws ParsingException { + assertEquals("https://framatube.org/accounts/framasoft/video-channels", + extractor.getOriginalUrl()); + } + + /*////////////////////////////////////////////////////////////////////////// + // ListExtractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + @Override + public void testRelatedItems() throws Exception { + defaultTestRelatedItems(extractor); + } + + @Test + @Override + public void testMoreRelatedItems() throws Exception { + defaultTestMoreItems(extractor); + } + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelExtractorTest.java index a51755efb..48d1e62fc 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelExtractorTest.java @@ -5,15 +5,19 @@ import org.junit.jupiter.api.Test; import org.schabi.newpipe.downloader.DownloaderTestImpl; import org.schabi.newpipe.extractor.ExtractorAsserts; import org.schabi.newpipe.extractor.NewPipe; -import org.schabi.newpipe.extractor.channel.ChannelExtractor; +import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest; import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeChannelExtractor; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; +import static org.schabi.newpipe.extractor.ExtractorAsserts.assertTabsContained; import static org.schabi.newpipe.extractor.ServiceList.PeerTube; -import static org.schabi.newpipe.extractor.services.DefaultTests.*; /** * Test for {@link PeertubeChannelExtractor} @@ -62,20 +66,6 @@ public class PeertubeChannelExtractorTest { assertEquals("https://framatube.org/video-channels/lqdn_channel@video.lqdn.fr/videos", extractor.getOriginalUrl()); } - /*////////////////////////////////////////////////////////////////////////// - // ListExtractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testRelatedItems() throws Exception { - defaultTestRelatedItems(extractor); - } - - @Test - public void testMoreRelatedItems() throws Exception { - defaultTestMoreItems(extractor); - } - /*////////////////////////////////////////////////////////////////////////// // ChannelExtractor //////////////////////////////////////////////////////////////////////////*/ @@ -124,6 +114,18 @@ public class PeertubeChannelExtractorTest { public void testVerified() throws Exception { assertFalse(extractor.isVerified()); } + + @Test + @Override + public void testTabs() throws Exception { + assertTabsContained(extractor.getTabs(), ChannelTabs.VIDEOS, ChannelTabs.PLAYLISTS); + } + + @Test + @Override + public void testTags() throws Exception { + assertTrue(extractor.getTags().isEmpty()); + } } public static class ChatSceptique implements BaseChannelExtractorTest { @@ -140,16 +142,6 @@ public class PeertubeChannelExtractorTest { extractor.fetchPage(); } - /*////////////////////////////////////////////////////////////////////////// - // Additional Testing - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testGetPageInNewExtractor() throws Exception { - final ChannelExtractor newExtractor = PeerTube.getChannelExtractor(extractor.getUrl()); - defaultTestGetPageInNewExtractor(extractor, newExtractor); - } - /*////////////////////////////////////////////////////////////////////////// // Extractor //////////////////////////////////////////////////////////////////////////*/ @@ -179,20 +171,6 @@ public class PeertubeChannelExtractorTest { assertEquals("https://framatube.org/api/v1/video-channels/chatsceptique@skeptikon.fr", extractor.getOriginalUrl()); } - /*////////////////////////////////////////////////////////////////////////// - // ListExtractor - //////////////////////////////////////////////////////////////////////////*/ - - @Test - public void testRelatedItems() throws Exception { - defaultTestRelatedItems(extractor); - } - - @Test - public void testMoreRelatedItems() throws Exception { - defaultTestMoreItems(extractor); - } - /*////////////////////////////////////////////////////////////////////////// // ChannelExtractor //////////////////////////////////////////////////////////////////////////*/ @@ -241,5 +219,17 @@ public class PeertubeChannelExtractorTest { public void testVerified() throws Exception { assertFalse(extractor.isVerified()); } + + @Test + @Override + public void testTabs() throws Exception { + assertTabsContained(extractor.getTabs(), ChannelTabs.VIDEOS, ChannelTabs.PLAYLISTS); + } + + @Test + @Override + public void testTags() throws Exception { + assertTrue(extractor.getTags().isEmpty()); + } } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelTabExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelTabExtractorTest.java new file mode 100644 index 000000000..71477fff8 --- /dev/null +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelTabExtractorTest.java @@ -0,0 +1,212 @@ +package org.schabi.newpipe.extractor.services.peertube; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.schabi.newpipe.downloader.DownloaderTestImpl; +import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.channel.tabs.ChannelTabExtractor; +import org.schabi.newpipe.extractor.channel.tabs.ChannelTabs; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.services.BaseListExtractorTest; +import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeChannelTabExtractor; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.schabi.newpipe.extractor.ServiceList.PeerTube; +import static org.schabi.newpipe.extractor.services.DefaultTests.*; + +class PeertubeChannelTabExtractorTest { + + static class Videos implements BaseListExtractorTest { + private static PeertubeChannelTabExtractor extractor; + + @BeforeAll + static void setUp() throws Exception { + NewPipe.init(DownloaderTestImpl.getInstance()); + // setting instance might break test when running in parallel + PeerTube.setInstance(new PeertubeInstance("https://framatube.org", "Framatube")); + extractor = (PeertubeChannelTabExtractor) PeerTube.getChannelTabExtractorFromId( + "video-channels/lqdn_channel@video.lqdn.fr", ChannelTabs.VIDEOS); + extractor.fetchPage(); + } + + /*////////////////////////////////////////////////////////////////////////// + // Extractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + @Override + public void testServiceId() { + assertEquals(PeerTube.getServiceId(), extractor.getServiceId()); + } + + @Test + @Override + public void testName() throws ParsingException { + assertEquals(ChannelTabs.VIDEOS, extractor.getName()); + } + + @Test + @Override + public void testId() throws ParsingException { + assertEquals("video-channels/lqdn_channel@video.lqdn.fr", extractor.getId()); + } + + @Test + @Override + public void testUrl() throws ParsingException { + assertEquals("https://framatube.org/video-channels/lqdn_channel@video.lqdn.fr/videos", + extractor.getUrl()); + } + + @Test + @Override + public void testOriginalUrl() throws ParsingException { + assertEquals("https://framatube.org/video-channels/lqdn_channel@video.lqdn.fr/videos", + extractor.getOriginalUrl()); + } + + /*////////////////////////////////////////////////////////////////////////// + // ListExtractor + //////////////////////////////////////////////////////////////////////////*/ + + @Test + @Override + public void testRelatedItems() throws Exception { + defaultTestRelatedItems(extractor); + } + + @Test + @Override + public void testMoreRelatedItems() throws Exception { + defaultTestMoreItems(extractor); + } + + /*////////////////////////////////////////////////////////////////////////// + // Additional Testing + //////////////////////////////////////////////////////////////////////////*/ + + @Test + void testGetPageInNewExtractor() throws Exception { + final ChannelTabExtractor newTabExtractor = PeerTube.getChannelTabExtractorFromId( + "video-channels/lqdn_channel@video.lqdn.fr", ChannelTabs.VIDEOS); + defaultTestGetPageInNewExtractor(extractor, newTabExtractor); + } + } + + static class Playlists implements BaseListExtractorTest { + private static PeertubeChannelTabExtractor extractor; + + @BeforeAll + static void setUp() throws IOException, ExtractionException { + NewPipe.init(DownloaderTestImpl.getInstance()); + extractor = (PeertubeChannelTabExtractor) + PeerTube.getChannelTabExtractorFromIdAndBaseUrl( + "video-channels/lqdn_channel@video.lqdn.fr", ChannelTabs.PLAYLISTS, + "https://framatube.org"); + extractor.fetchPage(); + } + + @Test + @Override + public void testServiceId() { + assertEquals(PeerTube.getServiceId(), extractor.getServiceId()); + } + + @Test + @Override + public void testName() throws Exception { + assertEquals(ChannelTabs.PLAYLISTS, extractor.getName()); + } + + @Test + @Override + public void testId() throws ParsingException { + assertEquals("video-channels/lqdn_channel@video.lqdn.fr", extractor.getId()); + } + + @Test + @Override + public void testUrl() throws ParsingException { + assertEquals("https://framatube.org/video-channels/lqdn_channel@video.lqdn.fr/video-playlists", + extractor.getUrl()); + } + + @Test + @Override + public void testOriginalUrl() throws Exception { + assertEquals("https://framatube.org/video-channels/lqdn_channel@video.lqdn.fr/video-playlists", + extractor.getOriginalUrl()); + } + + @Test + @Override + public void testRelatedItems() throws Exception { + defaultTestRelatedItems(extractor); + } + + @Override + public void testMoreRelatedItems() throws Exception { + defaultTestMoreItems(extractor); + } + } + + static class Channels implements BaseListExtractorTest { + private static PeertubeChannelTabExtractor extractor; + + @BeforeAll + static void setUp() throws IOException, ExtractionException { + NewPipe.init(DownloaderTestImpl.getInstance()); + extractor = (PeertubeChannelTabExtractor) + PeerTube.getChannelTabExtractorFromIdAndBaseUrl("accounts/framasoft", + ChannelTabs.CHANNELS, "https://framatube.org"); + extractor.fetchPage(); + } + + @Test + @Override + public void testServiceId() { + assertEquals(PeerTube.getServiceId(), extractor.getServiceId()); + } + + @Test + @Override + public void testName() throws Exception { + assertEquals(ChannelTabs.CHANNELS, extractor.getName()); + } + + @Test + @Override + public void testId() throws ParsingException { + assertEquals("accounts/framasoft", extractor.getId()); + } + + @Test + @Override + public void testUrl() throws ParsingException { + assertEquals("https://framatube.org/accounts/framasoft/video-channels", + extractor.getUrl()); + } + + @Test + @Override + public void testOriginalUrl() throws Exception { + assertEquals("https://framatube.org/accounts/framasoft/video-channels", + extractor.getOriginalUrl()); + } + + @Test + @Override + public void testRelatedItems() throws Exception { + defaultTestRelatedItems(extractor); + } + + @Test + @Override + public void testMoreRelatedItems() throws Exception { + defaultTestMoreItems(extractor); + } + } +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingLinkHandlerFactoryTest.java index b721057ec..cdff0bec9 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingLinkHandlerFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeTrendingLinkHandlerFactoryTest.java @@ -22,7 +22,7 @@ public class PeertubeTrendingLinkHandlerFactoryTest { public static void setUp() throws Exception { // setting instance might break test when running in parallel PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host")); - LinkHandlerFactory = new PeertubeTrendingLinkHandlerFactory(); + LinkHandlerFactory = PeertubeTrendingLinkHandlerFactory.getInstance(); NewPipe.init(DownloaderTestImpl.getInstance()); }