From 35e299759ecd09c020b93f59f2f94ad1c3d58b7e Mon Sep 17 00:00:00 2001 From: XiangRongLin <41164160+XiangRongLin@users.noreply.github.com> Date: Sun, 10 Jan 2021 20:24:50 +0100 Subject: [PATCH] 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. --- .../extractor/services/youtube/YoutubeParsingHelper.java | 5 +++++ .../org/schabi/newpipe/downloader/MockDownloader.java | 9 --------- .../youtube/YoutubeMixPlaylistExtractorTest.java | 5 +++++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java index 40d15288a..5d89350b0 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java @@ -353,6 +353,11 @@ public class YoutubeParsingHelper { return key; } + static void resetClientVersionAndKey() { + clientVersion = null; + key = null; + } + 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]; diff --git a/extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java b/extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java index b15c949c0..1dfa78471 100644 --- a/extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java +++ b/extractor/src/test/java/org/schabi/newpipe/downloader/MockDownloader.java @@ -31,15 +31,6 @@ class MockDownloader extends Downloader { reader.close(); 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 diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMixPlaylistExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMixPlaylistExtractorTest.java index ffda7aac6..689b3329c 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMixPlaylistExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMixPlaylistExtractorTest.java @@ -53,6 +53,7 @@ public class YoutubeMixPlaylistExtractorTest { @BeforeClass public static void setUp() throws Exception { + YoutubeParsingHelper.resetClientVersionAndKey(); final File file = new File(RESOURCE_PATH + "mix"); NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath())); extractor = (YoutubeMixPlaylistExtractor) YouTube @@ -131,6 +132,7 @@ public class YoutubeMixPlaylistExtractorTest { @BeforeClass public static void setUp() throws Exception { + YoutubeParsingHelper.resetClientVersionAndKey(); final File file = new File(RESOURCE_PATH + "mixWithIndex"); NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath())); extractor = (YoutubeMixPlaylistExtractor) YouTube @@ -201,6 +203,7 @@ public class YoutubeMixPlaylistExtractorTest { @BeforeClass public static void setUp() throws Exception { + YoutubeParsingHelper.resetClientVersionAndKey(); final File file = new File(RESOURCE_PATH + "myMix"); NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath())); extractor = (YoutubeMixPlaylistExtractor) YouTube @@ -274,6 +277,7 @@ public class YoutubeMixPlaylistExtractorTest { @BeforeClass public static void setUp() throws IOException { + YoutubeParsingHelper.resetClientVersionAndKey(); final File file = new File(RESOURCE_PATH + "invalid"); NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath())); } @@ -306,6 +310,7 @@ public class YoutubeMixPlaylistExtractorTest { @BeforeClass public static void setUp() throws Exception { + YoutubeParsingHelper.resetClientVersionAndKey(); final File file = new File(RESOURCE_PATH + "channelMix"); NewPipe.init(new DownloaderFactory().getDownloader(file.getAbsolutePath())); extractor = (YoutubeMixPlaylistExtractor) YouTube