Skip to content

Commit 31459ca

Browse files
committed
Add setSeedForVideoTests method in YoutubeStreamExtractor tests
In order to use still use mocks with the generation of random strings in player requests, we need to use YoutubeParsingHelper.setSeedForVideoTests() method in every stream test.
1 parent 25613c2 commit 31459ca

5 files changed

Lines changed: 37 additions & 20 deletions

File tree

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorAgeRestrictedTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class YoutubeStreamExtractorAgeRestrictedTest extends DefaultStreamExtrac
2929
public static void setUp() throws Exception {
3030
YoutubeParsingHelper.resetClientVersionAndKey();
3131
YoutubeParsingHelper.setNumberGenerator(new Random(1));
32+
YoutubeParsingHelper.setSeedForVideoTests();
3233
YoutubeStreamExtractor.resetDeobfuscationCode();
3334
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "ageRestricted"));
3435
extractor = YouTube.getStreamExtractor(URL);

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class YoutubeStreamExtractorControversialTest extends DefaultStreamExtrac
3333
public static void setUp() throws Exception {
3434
YoutubeParsingHelper.resetClientVersionAndKey();
3535
YoutubeParsingHelper.setNumberGenerator(new Random(1));
36+
YoutubeParsingHelper.setSeedForVideoTests();
3637
YoutubeStreamExtractor.resetDeobfuscationCode();
3738
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "controversial"));
3839
extractor = YouTube.getStreamExtractor(URL);

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorDefaultTest.java

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
/*
2+
* Created by Christian Schabesberger on 30.12.15.
3+
*
4+
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
5+
* YoutubeVideoExtractorDefault.java is part of NewPipe Extractor.
6+
*
7+
* NewPipe Extractor is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* NewPipe Extractor is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with NewPipe Extractor. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
121
package org.schabi.newpipe.extractor.services.youtube.stream;
222

323
import org.junit.jupiter.api.BeforeAll;
@@ -35,25 +55,6 @@
3555
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
3656
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
3757

38-
/*
39-
* Created by Christian Schabesberger on 30.12.15.
40-
*
41-
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
42-
* YoutubeVideoExtractorDefault.java is part of NewPipe.
43-
*
44-
* NewPipe is free software: you can redistribute it and/or modify
45-
* it under the terms of the GNU General Public License as published by
46-
* the Free Software Foundation, either version 3 of the License, or
47-
* (at your option) any later version.
48-
*
49-
* NewPipe is distributed in the hope that it will be useful,
50-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
51-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52-
* GNU General Public License for more details.
53-
*
54-
* You should have received a copy of the GNU General Public License
55-
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
56-
*/
5758
public class YoutubeStreamExtractorDefaultTest {
5859
private static final String RESOURCE_PATH = DownloaderFactory.RESOURCE_PATH + "services/youtube/extractor/stream/";
5960
static final String BASE_URL = "https://www.youtube.com/watch?v=";
@@ -64,6 +65,7 @@ public static class NotAvailable {
6465
public static void setUp() throws IOException {
6566
YoutubeParsingHelper.resetClientVersionAndKey();
6667
YoutubeParsingHelper.setNumberGenerator(new Random(1));
68+
YoutubeParsingHelper.setSeedForVideoTests();
6769
YoutubeStreamExtractor.resetDeobfuscationCode();
6870
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "notAvailable"));
6971
}
@@ -121,6 +123,7 @@ public static class DescriptionTestPewdiepie extends DefaultStreamExtractorTest
121123
public static void setUp() throws Exception {
122124
YoutubeParsingHelper.resetClientVersionAndKey();
123125
YoutubeParsingHelper.setNumberGenerator(new Random(1));
126+
YoutubeParsingHelper.setSeedForVideoTests();
124127
YoutubeStreamExtractor.resetDeobfuscationCode();
125128
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "pewdiwpie"));
126129
extractor = YouTube.getStreamExtractor(URL);
@@ -165,6 +168,7 @@ public static class DescriptionTestUnboxing extends DefaultStreamExtractorTest {
165168
public static void setUp() throws Exception {
166169
YoutubeParsingHelper.resetClientVersionAndKey();
167170
YoutubeParsingHelper.setNumberGenerator(new Random(1));
171+
YoutubeParsingHelper.setSeedForVideoTests();
168172
YoutubeStreamExtractor.resetDeobfuscationCode();
169173
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "unboxing"));
170174
extractor = YouTube.getStreamExtractor(URL);
@@ -219,6 +223,7 @@ public static class RatingsDisabledTest extends DefaultStreamExtractorTest {
219223
public static void setUp() throws Exception {
220224
YoutubeParsingHelper.resetClientVersionAndKey();
221225
YoutubeParsingHelper.setNumberGenerator(new Random(1));
226+
YoutubeParsingHelper.setSeedForVideoTests();
222227
YoutubeStreamExtractor.resetDeobfuscationCode();
223228
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "ratingsDisabled"));
224229
extractor = YouTube.getStreamExtractor(URL);
@@ -257,6 +262,7 @@ public static class StreamSegmentsTestTagesschau extends DefaultStreamExtractorT
257262
public static void setUp() throws Exception {
258263
YoutubeParsingHelper.resetClientVersionAndKey();
259264
YoutubeParsingHelper.setNumberGenerator(new Random(1));
265+
YoutubeParsingHelper.setSeedForVideoTests();
260266
YoutubeStreamExtractor.resetDeobfuscationCode();
261267
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "streamSegmentsTagesschau"));
262268
extractor = YouTube.getStreamExtractor(URL);
@@ -388,9 +394,10 @@ public static class PublicBroadcasterTest extends DefaultStreamExtractorTest {
388394
public static void setUp() throws Exception {
389395
YoutubeParsingHelper.resetClientVersionAndKey();
390396
YoutubeParsingHelper.setNumberGenerator(new Random(1));
397+
YoutubeParsingHelper.setSeedForVideoTests();
398+
YoutubeStreamExtractor.resetDeobfuscationCode();
391399
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "publicBroadcast"));
392400
extractor = YouTube.getStreamExtractor(URL);
393-
YoutubeStreamExtractor.resetDeobfuscationCode();
394401
extractor.fetchPage();
395402
}
396403

@@ -440,6 +447,9 @@ public static class UnlistedTest {
440447

441448
@BeforeAll
442449
public static void setUp() throws Exception {
450+
YoutubeParsingHelper.resetClientVersionAndKey();
451+
YoutubeParsingHelper.setNumberGenerator(new Random(1));
452+
YoutubeParsingHelper.setSeedForVideoTests();
443453
YoutubeStreamExtractor.resetDeobfuscationCode();
444454
NewPipe.init(DownloaderTestImpl.getInstance());
445455
extractor = (YoutubeStreamExtractor) YouTube
@@ -460,6 +470,9 @@ public static class CCLicensed {
460470

461471
@BeforeAll
462472
public static void setUp() throws Exception {
473+
YoutubeParsingHelper.resetClientVersionAndKey();
474+
YoutubeParsingHelper.setNumberGenerator(new Random(1));
475+
YoutubeParsingHelper.setSeedForVideoTests();
463476
YoutubeStreamExtractor.resetDeobfuscationCode();
464477
NewPipe.init(DownloaderTestImpl.getInstance());
465478
extractor = YouTube.getStreamExtractor(URL);

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class YoutubeStreamExtractorLivestreamTest extends DefaultStreamExtractor
3030
public static void setUp() throws Exception {
3131
YoutubeParsingHelper.resetClientVersionAndKey();
3232
YoutubeParsingHelper.setNumberGenerator(new Random(1));
33+
YoutubeParsingHelper.setSeedForVideoTests();
3334
YoutubeStreamExtractor.resetDeobfuscationCode();
3435
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "live"));
3536
extractor = YouTube.getStreamExtractor(URL);

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorUnlistedTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class YoutubeStreamExtractorUnlistedTest extends DefaultStreamExtractorTe
2929
public static void setUp() throws Exception {
3030
YoutubeParsingHelper.resetClientVersionAndKey();
3131
YoutubeParsingHelper.setNumberGenerator(new Random(1));
32+
YoutubeParsingHelper.setSeedForVideoTests();
3233
YoutubeStreamExtractor.resetDeobfuscationCode();
3334
NewPipe.init(new DownloaderFactory().getDownloader(RESOURCE_PATH + "unlisted"));
3435
extractor = YouTube.getStreamExtractor(URL);

0 commit comments

Comments
 (0)