Centralize test URLs

This commit is contained in:
Chocobozzz 2021-07-16 10:19:16 +02:00
parent 254d3579f5
commit 59bbcced37
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
11 changed files with 74 additions and 85 deletions

View File

@ -6,7 +6,7 @@ import { HttpStatusCode, randomInt } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
createSingleServer, createSingleServer,
ImportsCommand, FIXTURE_URLS,
PeerTubeServer, PeerTubeServer,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
@ -76,8 +76,8 @@ describe('Test upload quota', function () {
channelId: server.store.channel.id, channelId: server.store.channel.id,
privacy: VideoPrivacy.PUBLIC privacy: VideoPrivacy.PUBLIC
} }
await server.imports.importVideo({ attributes: { ...baseAttributes, targetUrl: ImportsCommand.getGoodVideoUrl() } }) await server.imports.importVideo({ attributes: { ...baseAttributes, targetUrl: FIXTURE_URLS.goodVideo } })
await server.imports.importVideo({ attributes: { ...baseAttributes, magnetUri: ImportsCommand.getMagnetURI() } }) await server.imports.importVideo({ attributes: { ...baseAttributes, magnetUri: FIXTURE_URLS.magnet } })
await server.imports.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } }) await server.imports.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } })
await waitJobs([ server ]) await waitJobs([ server ])

View File

@ -10,7 +10,7 @@ import {
checkBadStartPagination, checkBadStartPagination,
cleanupTests, cleanupTests,
createSingleServer, createSingleServer,
ImportsCommand, FIXTURE_URLS,
makeGetRequest, makeGetRequest,
makePostBodyRequest, makePostBodyRequest,
makeUploadRequest, makeUploadRequest,
@ -70,7 +70,7 @@ describe('Test video imports API validator', function () {
before(function () { before(function () {
baseCorrectParams = { baseCorrectParams = {
targetUrl: ImportsCommand.getGoodVideoUrl(), targetUrl: FIXTURE_URLS.goodVideo,
name: 'my super name', name: 'my super name',
category: 5, category: 5,
licence: 1, licence: 1,
@ -297,7 +297,7 @@ describe('Test video imports API validator', function () {
}) })
let fields = omit(baseCorrectParams, 'targetUrl') let fields = omit(baseCorrectParams, 'targetUrl')
fields = { ...fields, magnetUri: ImportsCommand.getMagnetURI() } fields = { ...fields, magnetUri: FIXTURE_URLS.magnet }
await makePostBodyRequest({ await makePostBodyRequest({
url: server.url, url: server.url,

View File

@ -6,9 +6,9 @@ import { orderBy } from 'lodash'
import { import {
BlacklistCommand, BlacklistCommand,
cleanupTests, cleanupTests,
doubleFollow,
createMultipleServers, createMultipleServers,
ImportsCommand, doubleFollow,
FIXTURE_URLS,
killallServers, killallServers,
PeerTubeServer, PeerTubeServer,
setAccessTokensToServers, setAccessTokensToServers,
@ -387,7 +387,7 @@ describe('Test video blacklist', function () {
this.timeout(15000) this.timeout(15000)
const attributes = { const attributes = {
targetUrl: ImportsCommand.getGoodVideoUrl(), targetUrl: FIXTURE_URLS.goodVideo,
name: 'URL import', name: 'URL import',
channelId: channelOfUserWithoutFlag channelId: channelOfUserWithoutFlag
} }
@ -400,7 +400,7 @@ describe('Test video blacklist', function () {
it('Should auto blacklist a video on torrent import', async function () { it('Should auto blacklist a video on torrent import', async function () {
const attributes = { const attributes = {
magnetUri: ImportsCommand.getMagnetURI(), magnetUri: FIXTURE_URLS.magnet,
name: 'Torrent import', name: 'Torrent import',
channelId: channelOfUserWithoutFlag channelId: channelOfUserWithoutFlag
} }

View File

@ -10,10 +10,10 @@ import {
checkNewVideoFromSubscription, checkNewVideoFromSubscription,
checkVideoIsPublished, checkVideoIsPublished,
cleanupTests, cleanupTests,
ImportsCommand, FIXTURE_URLS,
MockSmtpServer, MockSmtpServer,
prepareNotificationsTest,
PeerTubeServer, PeerTubeServer,
prepareNotificationsTest,
uploadRandomVideoOnServers, uploadRandomVideoOnServers,
wait, wait,
waitJobs waitJobs
@ -205,7 +205,7 @@ describe('Test user notifications', function () {
name, name,
channelId, channelId,
privacy: VideoPrivacy.PUBLIC, privacy: VideoPrivacy.PUBLIC,
targetUrl: ImportsCommand.getGoodVideoUrl() targetUrl: FIXTURE_URLS.goodVideo
} }
const { video } = await servers[0].imports.importVideo({ attributes }) const { video } = await servers[0].imports.importVideo({ attributes })
@ -275,7 +275,7 @@ describe('Test user notifications', function () {
name, name,
channelId, channelId,
privacy: VideoPrivacy.PUBLIC, privacy: VideoPrivacy.PUBLIC,
targetUrl: ImportsCommand.getGoodVideoUrl(), targetUrl: FIXTURE_URLS.goodVideo,
waitTranscoding: true waitTranscoding: true
} }
const { video } = await servers[1].imports.importVideo({ attributes }) const { video } = await servers[1].imports.importVideo({ attributes })
@ -343,12 +343,12 @@ describe('Test user notifications', function () {
name, name,
channelId, channelId,
privacy: VideoPrivacy.PRIVATE, privacy: VideoPrivacy.PRIVATE,
targetUrl: ImportsCommand.getBadVideoUrl() targetUrl: FIXTURE_URLS.badVideo
} }
const { video } = await servers[0].imports.importVideo({ attributes }) const { video } = await servers[0].imports.importVideo({ attributes })
await waitJobs(servers) await waitJobs(servers)
await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getBadVideoUrl(), false, 'presence') await checkMyVideoImportIsFinished(baseParams, name, video.uuid, FIXTURE_URLS.badVideo, false, 'presence')
}) })
it('Should send a notification when the video import succeeded', async function () { it('Should send a notification when the video import succeeded', async function () {
@ -360,12 +360,12 @@ describe('Test user notifications', function () {
name, name,
channelId, channelId,
privacy: VideoPrivacy.PRIVATE, privacy: VideoPrivacy.PRIVATE,
targetUrl: ImportsCommand.getGoodVideoUrl() targetUrl: FIXTURE_URLS.goodVideo
} }
const { video } = await servers[0].imports.importVideo({ attributes }) const { video } = await servers[0].imports.importVideo({ attributes })
await waitJobs(servers) await waitJobs(servers)
await checkMyVideoImportIsFinished(baseParams, name, video.uuid, ImportsCommand.getGoodVideoUrl(), true, 'presence') await checkMyVideoImportIsFinished(baseParams, name, video.uuid, FIXTURE_URLS.goodVideo, true, 'presence')
}) })
}) })

View File

@ -5,9 +5,9 @@ import * as chai from 'chai'
import { import {
areHttpImportTestsDisabled, areHttpImportTestsDisabled,
cleanupTests, cleanupTests,
doubleFollow,
createMultipleServers, createMultipleServers,
ImportsCommand, doubleFollow,
FIXTURE_URLS,
PeerTubeServer, PeerTubeServer,
setAccessTokensToServers, setAccessTokensToServers,
testCaptionFile, testCaptionFile,
@ -110,7 +110,7 @@ describe('Test video imports', function () {
} }
{ {
const attributes = { ...baseAttributes, targetUrl: ImportsCommand.getYoutubeVideoUrl() } const attributes = { ...baseAttributes, targetUrl: FIXTURE_URLS.youtube }
const { video } = await servers[0].imports.importVideo({ attributes }) const { video } = await servers[0].imports.importVideo({ attributes })
expect(video.name).to.equal('small video - youtube') expect(video.name).to.equal('small video - youtube')
@ -162,7 +162,7 @@ Ajouter un sous-titre est vraiment facile`)
{ {
const attributes = { const attributes = {
...baseAttributes, ...baseAttributes,
magnetUri: ImportsCommand.getMagnetURI(), magnetUri: FIXTURE_URLS.magnet,
description: 'this is a super torrent description', description: 'this is a super torrent description',
tags: [ 'tag_torrent1', 'tag_torrent2' ] tags: [ 'tag_torrent1', 'tag_torrent2' ]
} }
@ -199,13 +199,13 @@ Ajouter un sous-titre est vraiment facile`)
expect(videoImports).to.have.lengthOf(3) expect(videoImports).to.have.lengthOf(3)
expect(videoImports[2].targetUrl).to.equal(ImportsCommand.getYoutubeVideoUrl()) expect(videoImports[2].targetUrl).to.equal(FIXTURE_URLS.youtube)
expect(videoImports[2].magnetUri).to.be.null expect(videoImports[2].magnetUri).to.be.null
expect(videoImports[2].torrentName).to.be.null expect(videoImports[2].torrentName).to.be.null
expect(videoImports[2].video.name).to.equal('small video - youtube') expect(videoImports[2].video.name).to.equal('small video - youtube')
expect(videoImports[1].targetUrl).to.be.null expect(videoImports[1].targetUrl).to.be.null
expect(videoImports[1].magnetUri).to.equal(ImportsCommand.getMagnetURI()) expect(videoImports[1].magnetUri).to.equal(FIXTURE_URLS.magnet)
expect(videoImports[1].torrentName).to.be.null expect(videoImports[1].torrentName).to.be.null
expect(videoImports[1].video.name).to.equal('super peertube2 video') expect(videoImports[1].video.name).to.equal('super peertube2 video')
@ -234,7 +234,7 @@ Ajouter un sous-titre est vraiment facile`)
this.timeout(60_000) this.timeout(60_000)
const attributes = { const attributes = {
targetUrl: ImportsCommand.getYoutubeVideoUrl(), targetUrl: FIXTURE_URLS.youtube,
channelId: channelIdServer2, channelId: channelIdServer2,
privacy: VideoPrivacy.PUBLIC, privacy: VideoPrivacy.PUBLIC,
category: 10, category: 10,
@ -270,7 +270,7 @@ Ajouter un sous-titre est vraiment facile`)
const attributes = { const attributes = {
name: 'transcoded video', name: 'transcoded video',
magnetUri: ImportsCommand.getMagnetURI(), magnetUri: FIXTURE_URLS.magnet,
channelId: channelIdServer2, channelId: channelIdServer2,
privacy: VideoPrivacy.PUBLIC privacy: VideoPrivacy.PUBLIC
} }
@ -320,7 +320,7 @@ Ajouter un sous-titre est vraiment facile`)
const attributes = { const attributes = {
name: 'hdr video', name: 'hdr video',
targetUrl: ImportsCommand.getYoutubeHDRVideoUrl(), targetUrl: FIXTURE_URLS.youtubeHDR,
channelId: channelIdServer1, channelId: channelIdServer1,
privacy: VideoPrivacy.PUBLIC privacy: VideoPrivacy.PUBLIC
} }

View File

@ -7,9 +7,9 @@ import {
buildAbsoluteFixturePath, buildAbsoluteFixturePath,
cleanupTests, cleanupTests,
CLICommand, CLICommand,
doubleFollow,
createSingleServer, createSingleServer,
ImportsCommand, doubleFollow,
FIXTURE_URLS,
PeerTubeServer, PeerTubeServer,
setAccessTokensToServers, setAccessTokensToServers,
testHelloWorldRegisteredSettings, testHelloWorldRegisteredSettings,
@ -117,7 +117,7 @@ describe('Test CLI wrapper', function () {
this.timeout(60000) this.timeout(60000)
const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} --channel-name user_channel` const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel`
await cliCommand.execWithEnv(`${cmd} import ${params}`) await cliCommand.execWithEnv(`${cmd} import ${params}`)
}) })
@ -148,7 +148,7 @@ describe('Test CLI wrapper', function () {
this.timeout(60000) this.timeout(60000)
const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} ` + const params = `--target-url ${FIXTURE_URLS.youtube} ` +
`--channel-name user_channel --video-name toto --nsfw --support support` `--channel-name user_channel --video-name toto --nsfw --support support`
await cliCommand.execWithEnv(`${cmd} import ${params}`) await cliCommand.execWithEnv(`${cmd} import ${params}`)

View File

@ -4,7 +4,7 @@ import 'mocha'
import { expect } from 'chai' import { expect } from 'chai'
import { pathExists, remove } from 'fs-extra' import { pathExists, remove } from 'fs-extra'
import { join } from 'path' import { join } from 'path'
import { get4KFileUrl, root, wait } from '../../../shared/extra-utils' import { FIXTURE_URLS, root, wait } from '../../../shared/extra-utils'
import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
describe('Request helpers', function () { describe('Request helpers', function () {
@ -13,7 +13,7 @@ describe('Request helpers', function () {
it('Should throw an error when the bytes limit is exceeded for request', async function () { it('Should throw an error when the bytes limit is exceeded for request', async function () {
try { try {
await doRequest(get4KFileUrl(), { bodyKBLimit: 3 }) await doRequest(FIXTURE_URLS.video4K, { bodyKBLimit: 3 })
} catch { } catch {
return return
} }
@ -23,7 +23,7 @@ describe('Request helpers', function () {
it('Should throw an error when the bytes limit is exceeded for request and save file', async function () { it('Should throw an error when the bytes limit is exceeded for request and save file', async function () {
try { try {
await doRequestAndSaveToFile(get4KFileUrl(), destPath1, { bodyKBLimit: 3 }) await doRequestAndSaveToFile(FIXTURE_URLS.video4K, destPath1, { bodyKBLimit: 3 })
} catch { } catch {
await wait(500) await wait(500)
@ -35,8 +35,8 @@ describe('Request helpers', function () {
}) })
it('Should succeed if the file is below the limit', async function () { it('Should succeed if the file is below the limit', async function () {
await doRequest(get4KFileUrl(), { bodyKBLimit: 5 }) await doRequest(FIXTURE_URLS.video4K, { bodyKBLimit: 5 })
await doRequestAndSaveToFile(get4KFileUrl(), destPath2, { bodyKBLimit: 5 }) await doRequestAndSaveToFile(FIXTURE_URLS.video4K, destPath2, { bodyKBLimit: 5 })
expect(await pathExists(destPath2)).to.be.true expect(await pathExists(destPath2)).to.be.true
}) })

View File

@ -5,12 +5,12 @@ import * as chai from 'chai'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { import {
cleanupTests, cleanupTests,
doubleFollow,
createMultipleServers, createMultipleServers,
ImportsCommand, doubleFollow,
FIXTURE_URLS,
makeRawRequest, makeRawRequest,
PluginsCommand,
PeerTubeServer, PeerTubeServer,
PluginsCommand,
setAccessTokensToServers, setAccessTokensToServers,
setDefaultVideoChannel, setDefaultVideoChannel,
waitJobs waitJobs
@ -136,7 +136,7 @@ describe('Test plugin filter hooks', function () {
name: 'normal title', name: 'normal title',
privacy: VideoPrivacy.PUBLIC, privacy: VideoPrivacy.PUBLIC,
channelId: servers[0].store.channel.id, channelId: servers[0].store.channel.id,
targetUrl: ImportsCommand.getGoodVideoUrl() + 'bad' targetUrl: FIXTURE_URLS.goodVideo + 'bad'
} }
await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
}) })
@ -161,7 +161,7 @@ describe('Test plugin filter hooks', function () {
name: 'title with bad word', name: 'title with bad word',
privacy: VideoPrivacy.PUBLIC, privacy: VideoPrivacy.PUBLIC,
channelId: servers[0].store.channel.id, channelId: servers[0].store.channel.id,
targetUrl: ImportsCommand.getGoodVideoUrl() targetUrl: FIXTURE_URLS.goodVideo
} }
const body = await servers[0].imports.importVideo({ attributes }) const body = await servers[0].imports.importVideo({ attributes })
videoImportId = body.id videoImportId = body.id
@ -273,7 +273,7 @@ describe('Test plugin filter hooks', function () {
const attributes = { const attributes = {
name: 'video please blacklist me', name: 'video please blacklist me',
targetUrl: ImportsCommand.getGoodVideoUrl(), targetUrl: FIXTURE_URLS.goodVideo,
channelId: servers[0].store.channel.id channelId: servers[0].store.channel.id
} }
const body = await servers[0].imports.importVideo({ attributes }) const body = await servers[0].imports.importVideo({ attributes })

View File

@ -1,6 +1,36 @@
import { stat } from 'fs-extra' import { stat } from 'fs-extra'
import { basename, isAbsolute, join, resolve } from 'path' import { basename, isAbsolute, join, resolve } from 'path'
const FIXTURE_URLS = {
youtube: 'https://www.youtube.com/watch?v=msX3jv1XdvM',
/**
* The video is used to check format-selection correctness wrt. HDR,
* which brings its own set of oddities outside of a MediaSource.
* FIXME: refactor once HDR is supported at playback
*
* The video needs to have the following format_ids:
* (which you can check by using `youtube-dl <url> -F`):
* - 303 (1080p webm vp9)
* - 299 (1080p mp4 avc1)
* - 335 (1080p webm vp9.2 HDR)
*
* 15 jan. 2021: TEST VIDEO NOT CURRENTLY PROVIDING
* - 400 (1080p mp4 av01)
* - 315 (2160p webm vp9 HDR)
* - 337 (2160p webm vp9.2 HDR)
* - 401 (2160p mp4 av01 HDR)
*/
youtubeHDR: 'https://www.youtube.com/watch?v=qR5vOXbZsI4',
// eslint-disable-next-line max-len
magnet: 'magnet:?xs=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Ftorrents%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.torrent&xt=urn:btih:0f498834733e8057ed5c6f2ee2b4efd8d84a76ee&dn=super+peertube2+video&tr=wss%3A%2F%2Fpeertube2.cpy.re%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube2.cpy.re%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Fwebseed%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.mp4',
badVideo: 'https://download.cpy.re/peertube/bad_video.mp4',
goodVideo: 'https://download.cpy.re/peertube/good_video.mp4',
video4K: 'https://download.cpy.re/peertube/4k_file.txt'
}
function parallelTests () { function parallelTests () {
return process.env.MOCHA_PARALLEL === 'true' return process.env.MOCHA_PARALLEL === 'true'
} }
@ -51,6 +81,8 @@ function buildRequestStub (): any {
} }
export { export {
FIXTURE_URLS,
parallelTests, parallelTests,
isGithubCI, isGithubCI,
areHttpImportTestsDisabled, areHttpImportTestsDisabled,

View File

@ -7,10 +7,6 @@ import { URL } from 'url'
import { HttpStatusCode } from '@shared/core-utils' import { HttpStatusCode } from '@shared/core-utils'
import { buildAbsoluteFixturePath, root } from '../miscs/tests' import { buildAbsoluteFixturePath, root } from '../miscs/tests'
function get4KFileUrl () {
return 'https://download.cpy.re/peertube/4k_file.txt'
}
function makeRawRequest (url: string, statusCodeExpected?: HttpStatusCode, range?: string) { function makeRawRequest (url: string, statusCodeExpected?: HttpStatusCode, range?: string) {
const { host, protocol, pathname } = new URL(url) const { host, protocol, pathname } = new URL(url)
@ -227,7 +223,6 @@ function unwrapText (test: request.Test): Promise<string> {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
export { export {
get4KFileUrl,
makeHTMLRequest, makeHTMLRequest,
makeGetRequest, makeGetRequest,
decodeQueryString, decodeQueryString,

View File

@ -7,44 +7,6 @@ import { AbstractCommand, OverrideCommandOptions } from '../shared'
export class ImportsCommand extends AbstractCommand { export class ImportsCommand extends AbstractCommand {
static getYoutubeVideoUrl () {
return 'https://www.youtube.com/watch?v=msX3jv1XdvM'
}
static getYoutubeHDRVideoUrl () {
/**
* The video is used to check format-selection correctness wrt. HDR,
* which brings its own set of oddities outside of a MediaSource.
* FIXME: refactor once HDR is supported at playback
*
* The video needs to have the following format_ids:
* (which you can check by using `youtube-dl <url> -F`):
* - 303 (1080p webm vp9)
* - 299 (1080p mp4 avc1)
* - 335 (1080p webm vp9.2 HDR)
*
* 15 jan. 2021: TEST VIDEO NOT CURRENTLY PROVIDING
* - 400 (1080p mp4 av01)
* - 315 (2160p webm vp9 HDR)
* - 337 (2160p webm vp9.2 HDR)
* - 401 (2160p mp4 av01 HDR)
*/
return 'https://www.youtube.com/watch?v=qR5vOXbZsI4'
}
static getMagnetURI () {
// eslint-disable-next-line max-len
return 'magnet:?xs=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Ftorrents%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.torrent&xt=urn:btih:0f498834733e8057ed5c6f2ee2b4efd8d84a76ee&dn=super+peertube2+video&tr=wss%3A%2F%2Fpeertube2.cpy.re%3A443%2Ftracker%2Fsocket&tr=https%3A%2F%2Fpeertube2.cpy.re%2Ftracker%2Fannounce&ws=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Fwebseed%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.mp4'
}
static getBadVideoUrl () {
return 'https://download.cpy.re/peertube/bad_video.mp4'
}
static getGoodVideoUrl () {
return 'https://download.cpy.re/peertube/good_video.mp4'
}
importVideo (options: OverrideCommandOptions & { importVideo (options: OverrideCommandOptions & {
attributes: VideoImportCreate & { torrentfile?: string } attributes: VideoImportCreate & { torrentfile?: string }
}) { }) {