Add method to allow resetting youtube client version and key
This is needed so that a request is made for each test class when running multiple at once. This way RecordingDownloader records all necessary requests. This works as long as tests are run sequentially and not in parallel.
This commit is contained in:
parent
f447a7a450
commit
35e299759e
|
@ -353,6 +353,11 @@ public class YoutubeParsingHelper {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void resetClientVersionAndKey() {
|
||||||
|
clientVersion = null;
|
||||||
|
key = null;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean areHardcodedYoutubeMusicKeysValid() throws IOException, ReCaptchaException {
|
public static boolean areHardcodedYoutubeMusicKeysValid() throws IOException, ReCaptchaException {
|
||||||
final String url = "https://music.youtube.com/youtubei/v1/search?alt=json&key=" + HARDCODED_YOUTUBE_MUSIC_KEYS[0];
|
final String url = "https://music.youtube.com/youtubei/v1/search?alt=json&key=" + HARDCODED_YOUTUBE_MUSIC_KEYS[0];
|
||||||
|
|
||||||
|
|
|
@ -31,15 +31,6 @@ class MockDownloader extends Downloader {
|
||||||
reader.close();
|
reader.close();
|
||||||
mocks.put(response.getRequest(), response.getResponse());
|
mocks.put(response.getRequest(), response.getResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
//shared find proper solution
|
|
||||||
File clientVersion = new File("src/test/resources/org/schabi/newpipe/extractor/services/youtube/client_version.json");
|
|
||||||
final FileReader reader = new FileReader(clientVersion);
|
|
||||||
final TestRequestResponse response = new GsonBuilder()
|
|
||||||
.create()
|
|
||||||
.fromJson(reader, TestRequestResponse.class);
|
|
||||||
reader.close();
|
|
||||||
mocks.put(response.getRequest(), response.getResponse());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -53,6 +53,7 @@ public class YoutubeMixPlaylistExtractorTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
|
YoutubeParsingHelper.resetClientVersionAndKey();
|
||||||
final File file = new File(RESOURCE_PATH + "mix");
|
final File file = new File(RESOURCE_PATH + "mix");
|
||||||
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
|
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
|
||||||
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
||||||
|
@ -131,6 +132,7 @@ public class YoutubeMixPlaylistExtractorTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
|
YoutubeParsingHelper.resetClientVersionAndKey();
|
||||||
final File file = new File(RESOURCE_PATH + "mixWithIndex");
|
final File file = new File(RESOURCE_PATH + "mixWithIndex");
|
||||||
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
|
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
|
||||||
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
||||||
|
@ -201,6 +203,7 @@ public class YoutubeMixPlaylistExtractorTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
|
YoutubeParsingHelper.resetClientVersionAndKey();
|
||||||
final File file = new File(RESOURCE_PATH + "myMix");
|
final File file = new File(RESOURCE_PATH + "myMix");
|
||||||
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
|
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
|
||||||
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
||||||
|
@ -274,6 +277,7 @@ public class YoutubeMixPlaylistExtractorTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws IOException {
|
public static void setUp() throws IOException {
|
||||||
|
YoutubeParsingHelper.resetClientVersionAndKey();
|
||||||
final File file = new File(RESOURCE_PATH + "invalid");
|
final File file = new File(RESOURCE_PATH + "invalid");
|
||||||
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
|
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
|
||||||
}
|
}
|
||||||
|
@ -306,6 +310,7 @@ public class YoutubeMixPlaylistExtractorTest {
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
|
YoutubeParsingHelper.resetClientVersionAndKey();
|
||||||
final File file = new File(RESOURCE_PATH + "channelMix");
|
final File file = new File(RESOURCE_PATH + "channelMix");
|
||||||
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
|
NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath()));
|
||||||
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
extractor = (YoutubeMixPlaylistExtractor) YouTube
|
||||||
|
|
Loading…
Reference in New Issue