Skip to content

Commit

Permalink
searchfilters: Test: adjust SoundCloud tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evermind-zz committed Oct 11, 2022
1 parent c7c794f commit a590010
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.search.filter.FilterItem;
import org.schabi.newpipe.extractor.services.DefaultSearchExtractorTest;
import org.schabi.newpipe.extractor.services.soundcloud.search.filter.SoundcloudFilters;

import javax.annotation.Nullable;
import java.io.IOException;
Expand All @@ -22,7 +24,6 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoDuplicatedItems;
import static org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudSearchQueryHandlerFactory.*;
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;

public class SoundcloudSearchExtractorTest {
Expand Down Expand Up @@ -57,7 +58,9 @@ public static class Tracks extends DefaultSearchExtractorTest {
@BeforeAll
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = SoundCloud.getSearchExtractor(QUERY, singletonList(TRACKS), "");
final FilterItem item = getFilterItem(
SoundCloud, SoundcloudFilters.ID_CF_MAIN_TRACKS);
extractor = SoundCloud.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand All @@ -81,7 +84,9 @@ public static class Users extends DefaultSearchExtractorTest {
@BeforeAll
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = SoundCloud.getSearchExtractor(QUERY, singletonList(USERS), "");
final FilterItem item = getFilterItem(
SoundCloud, SoundcloudFilters.ID_CF_MAIN_USERS);
extractor = SoundCloud.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand All @@ -105,7 +110,9 @@ public static class Playlists extends DefaultSearchExtractorTest {
@BeforeAll
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = SoundCloud.getSearchExtractor(QUERY, singletonList(PLAYLISTS), "");
final FilterItem item = getFilterItem(
SoundCloud, SoundcloudFilters.ID_CF_MAIN_PLAYLISTS);
extractor = SoundCloud.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand All @@ -126,7 +133,9 @@ public static class PagingTest {
@Test
public void duplicatedItemsCheck() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
final SearchExtractor extractor = SoundCloud.getSearchExtractor("cirque du soleil", singletonList(TRACKS), "");
final FilterItem item = DefaultSearchExtractorTest.getFilterItem(
SoundCloud, SoundcloudFilters.ID_CF_MAIN_TRACKS);
final SearchExtractor extractor = SoundCloud.getSearchExtractor("cirque du soleil", singletonList(item), null);
extractor.fetchPage();

final InfoItemsPage<InfoItem> page1 = extractor.getInitialPage();
Expand All @@ -151,7 +160,9 @@ public static class UserVerified extends DefaultSearchExtractorTest {
@BeforeAll
public static void setUp() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = SoundCloud.getSearchExtractor(QUERY, singletonList(USERS), "");
final FilterItem item = getFilterItem(
SoundCloud, SoundcloudFilters.ID_CF_MAIN_USERS);
extractor = SoundCloud.getSearchExtractor(QUERY, singletonList(item), null);
extractor.fetchPage();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import org.junit.jupiter.api.Test;
import org.schabi.newpipe.downloader.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.search.filter.FilterContainer;
import org.schabi.newpipe.extractor.search.filter.FilterItem;
import org.schabi.newpipe.extractor.services.DefaultSearchExtractorTest;
import org.schabi.newpipe.extractor.services.soundcloud.search.filter.SoundcloudFilters;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
import static org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudSearchQueryHandlerFactory.*;

public class SoundcloudSearchQHTest {

Expand Down Expand Up @@ -38,37 +41,61 @@ public void testRegularValues() throws Exception {

@Test
public void testGetContentFilter() throws Exception {
assertEquals("tracks", SoundCloud.getSearchQHFactory()
.fromQuery("", asList(new String[]{"tracks"}), "").getContentFilters().get(0));
assertEquals("users", SoundCloud.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{"users"}), "").getContentFilters().get(0));
final FilterItem trackFilterItem = DefaultSearchExtractorTest.getFilterItem(
SoundCloud, SoundcloudFilters.ID_CF_MAIN_TRACKS);
final FilterItem usersFilterItem = DefaultSearchExtractorTest.getFilterItem(
SoundCloud, SoundcloudFilters.ID_CF_MAIN_USERS);

assertEquals(SoundcloudFilters.ID_CF_MAIN_TRACKS, SoundCloud.getSearchQHFactory()
.fromQuery("", singletonList(trackFilterItem), null)
.getContentFilters().get(0).getIdentifier());
assertEquals(SoundcloudFilters.ID_CF_MAIN_USERS, SoundCloud.getSearchQHFactory()
.fromQuery("asdf", singletonList(usersFilterItem), null)
.getContentFilters().get(0).getIdentifier());
}

@Test
public void testWithContentfilter() throws Exception {
final FilterItem trackFilterItem = DefaultSearchExtractorTest.getFilterItem(
SoundCloud, SoundcloudFilters.ID_CF_MAIN_TRACKS);
final FilterItem usersFilterItem = DefaultSearchExtractorTest.getFilterItem(
SoundCloud, SoundcloudFilters.ID_CF_MAIN_USERS);
final FilterItem playlistsFilterItem = DefaultSearchExtractorTest.getFilterItem(
SoundCloud, SoundcloudFilters.ID_CF_MAIN_PLAYLISTS);

assertEquals("https://api-v2.soundcloud.com/search/tracks?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{TRACKS}), "").getUrl()));
.fromQuery("asdf", singletonList(trackFilterItem), null).getUrl()));
assertEquals("https://api-v2.soundcloud.com/search/users?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{USERS}), "").getUrl()));
.fromQuery("asdf", singletonList(usersFilterItem), null).getUrl()));
assertEquals("https://api-v2.soundcloud.com/search/playlists?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{PLAYLISTS}), "").getUrl()));
.fromQuery("asdf", singletonList(playlistsFilterItem), null).getUrl()));
assertEquals("https://api-v2.soundcloud.com/search?q=asdf&limit=10&offset=0", removeClientId(SoundCloud.getSearchQHFactory()
.fromQuery("asdf", asList(new String[]{"fjiijie"}), "").getUrl()));
.fromQuery("asdf", singletonList(null), null).getUrl()));
}

@Test
public void testGetAvailableContentFilter() {
final String[] contentFilter = SoundCloud.getSearchQHFactory().getAvailableContentFilter();
assertEquals(4, contentFilter.length);
assertEquals("all", contentFilter[0]);
assertEquals("tracks", contentFilter[1]);
assertEquals("users", contentFilter[2]);
assertEquals("playlists", contentFilter[3]);
final FilterContainer contentFilter =
SoundCloud.getSearchQHFactory().getAvailableContentFilter();
final int noOfContentFilters = DefaultSearchExtractorTest.getNoOfFilterItems(contentFilter);

assertEquals(4, noOfContentFilters);
assertEquals(SoundcloudFilters.ID_CF_MAIN_ALL,
contentFilter.getFilterGroups()[0].getFilterItems()[0].getIdentifier());
assertEquals(SoundcloudFilters.ID_CF_MAIN_TRACKS,
contentFilter.getFilterGroups()[0].getFilterItems()[1].getIdentifier());
assertEquals(SoundcloudFilters.ID_CF_MAIN_USERS,
contentFilter.getFilterGroups()[0].getFilterItems()[2].getIdentifier());
assertEquals(SoundcloudFilters.ID_CF_MAIN_PLAYLISTS,
contentFilter.getFilterGroups()[0].getFilterItems()[3].getIdentifier());
}

@Test
public void testGetAvailableSortFilter() {
final String[] contentFilter = SoundCloud.getSearchQHFactory().getAvailableSortFilter();
assertEquals(0, contentFilter.length);
final FilterContainer contentFilterContainer =
SoundCloud.getSearchQHFactory().getAvailableContentFilter();
final int noOfSortFilters =
DefaultSearchExtractorTest.getNoOfSortFilterItems(contentFilterContainer);
assertEquals(13, noOfSortFilters);
}
}

0 comments on commit a590010

Please sign in to comment.