From b488ba1e26b803ac6c637e8b11bdd444ca4c803f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 30 Jul 2020 09:43:12 +0200 Subject: Don't rely on youtube for tests Use another import URL when possible, and disable import tests when we want to do a youtube import test --- server/tests/api/check-params/users.ts | 13 ++++++------ server/tests/api/check-params/video-imports.ts | 24 ++++++++++------------ .../tests/api/notifications/user-notifications.ts | 10 ++++----- server/tests/api/videos/video-blacklist.ts | 10 ++++----- server/tests/api/videos/video-imports.ts | 14 +++++++------ 5 files changed, 35 insertions(+), 36 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 2fea2cbd5..3e53c445d 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -1,10 +1,10 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import { omit } from 'lodash' import 'mocha' +import { expect } from 'chai' +import { omit } from 'lodash' import { join } from 'path' import { User, UserRole, VideoImport, VideoImportState } from '../../../../shared' - import { addVideoChannel, blockUser, @@ -31,17 +31,16 @@ import { uploadVideo, userLogin } from '../../../../shared/extra-utils' +import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' -import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' -import { VideoPrivacy } from '../../../../shared/models/videos' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { expect } from 'chai' +import { getMagnetURI, getMyVideoImports, getGoodVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' -import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' +import { VideoPrivacy } from '../../../../shared/models/videos' describe('Test users API validators', function () { const path = '/api/v1/users/' @@ -1047,7 +1046,7 @@ describe('Test users API validators', function () { channelId: 1, privacy: VideoPrivacy.PUBLIC } - await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getYoutubeVideoUrl() })) + await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getGoodVideoUrl() })) await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() })) await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any })) diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 3759e47c4..f954ba089 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -1,9 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import { omit } from 'lodash' import 'mocha' +import { omit } from 'lodash' import { join } from 'path' -import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' import { cleanupTests, createUser, @@ -23,7 +22,8 @@ import { checkBadSortPagination, checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' -import { getMagnetURI, getYoutubeVideoUrl } from '../../../../shared/extra-utils/videos/video-imports' +import { getMagnetURI, getGoodVideoUrl } from '../../../../shared/extra-utils/videos/video-imports' +import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' describe('Test video imports API validator', function () { const path = '/api/v1/videos/imports' @@ -76,7 +76,7 @@ describe('Test video imports API validator', function () { before(function () { baseCorrectParams = { - targetUrl: getYoutubeVideoUrl(), + targetUrl: getGoodVideoUrl(), name: 'my super name', category: 5, licence: 1, @@ -246,15 +246,13 @@ describe('Test video imports API validator', function () { it('Should succeed with the correct parameters', async function () { this.timeout(30000) - { - await makePostBodyRequest({ - url: server.url, - path, - token: server.accessToken, - fields: baseCorrectParams, - statusCodeExpected: 200 - }) - } + await makePostBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields: baseCorrectParams, + statusCodeExpected: 200 + }) }) it('Should forbid to import http videos', async function () { diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index e5f6aa864..af4ff42b0 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -24,7 +24,7 @@ import { prepareNotificationsTest } from '../../../../shared/extra-utils/users/user-notifications' import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' -import { getBadVideoUrl, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' +import { getBadVideoUrl, getGoodVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' import { UserNotification, UserNotificationType } from '../../../../shared/models/users' import { VideoPrivacy } from '../../../../shared/models/videos' @@ -213,7 +213,7 @@ describe('Test user notifications', function () { name, channelId, privacy: VideoPrivacy.PUBLIC, - targetUrl: getYoutubeVideoUrl() + targetUrl: getGoodVideoUrl() } const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) const uuid = res.body.video.uuid @@ -284,7 +284,7 @@ describe('Test user notifications', function () { name, channelId, privacy: VideoPrivacy.PUBLIC, - targetUrl: getYoutubeVideoUrl(), + targetUrl: getGoodVideoUrl(), waitTranscoding: true } const res = await importVideo(servers[1].url, servers[1].accessToken, attributes) @@ -371,13 +371,13 @@ describe('Test user notifications', function () { name, channelId, privacy: VideoPrivacy.PRIVATE, - targetUrl: getYoutubeVideoUrl() + targetUrl: getGoodVideoUrl() } const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) const uuid = res.body.video.uuid await waitJobs(servers) - await checkMyVideoImportIsFinished(baseParams, name, uuid, getYoutubeVideoUrl(), true, 'presence') + await checkMyVideoImportIsFinished(baseParams, name, uuid, getGoodVideoUrl(), true, 'presence') }) }) diff --git a/server/tests/api/videos/video-blacklist.ts b/server/tests/api/videos/video-blacklist.ts index a8500627b..52cac20d9 100644 --- a/server/tests/api/videos/video-blacklist.ts +++ b/server/tests/api/videos/video-blacklist.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ +import 'mocha' import * as chai from 'chai' import { orderBy } from 'lodash' -import 'mocha' import { addVideoToBlacklist, cleanupTests, @@ -25,10 +25,10 @@ import { } from '../../../../shared/extra-utils/index' import { doubleFollow } from '../../../../shared/extra-utils/server/follows' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' -import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' +import { getGoodVideoUrl, getMagnetURI, importVideo } from '../../../../shared/extra-utils/videos/video-imports' import { User, UserRole } from '../../../../shared/models/users' -import { getMagnetURI, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' +import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' +import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' const expect = chai.expect @@ -424,7 +424,7 @@ describe('Test video blacklist', function () { this.timeout(15000) const attributes = { - targetUrl: getYoutubeVideoUrl(), + targetUrl: getGoodVideoUrl(), name: 'URL import', channelId: channelOfUserWithoutFlag } diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 05ee36b27..efda4fc7b 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -1,8 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { VideoDetails, VideoImport, VideoPrivacy, VideoCaption } from '../../../../shared/models/videos' +import * as chai from 'chai' import { cleanupTests, doubleFollow, @@ -11,15 +10,16 @@ import { getMyVideos, getVideo, getVideosList, - listVideoCaptions, - testCaptionFile, immutableAssign, + listVideoCaptions, ServerInfo, - setAccessTokensToServers + setAccessTokensToServers, + testCaptionFile } from '../../../../shared/extra-utils' +import { areHttpImportTestsDisabled, testImage } from '../../../../shared/extra-utils/miscs/miscs' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' -import { testImage } from '../../../../shared/extra-utils/miscs/miscs' +import { VideoCaption, VideoDetails, VideoImport, VideoPrivacy } from '../../../../shared/models/videos' const expect = chai.expect @@ -28,6 +28,8 @@ describe('Test video imports', function () { let channelIdServer1: number let channelIdServer2: number + if (areHttpImportTestsDisabled()) return + async function checkVideosServer1 (url: string, idHttp: string, idMagnet: string, idTorrent: string) { const resHttp = await getVideo(url, idHttp) const videoHttp: VideoDetails = resHttp.body -- cgit v1.2.3