4
4
from http import HTTPStatus
5
5
6
6
from django_peertube_runner_connector .factories import RunnerJobFactory
7
- import requests
8
- import responses
9
7
from rest_framework .test import APITestCase
10
8
11
9
from marsha .core import factories
@@ -26,30 +24,21 @@ def setUp(self):
26
24
)
27
25
self .url = f"/api/videos/{ self .video .pk } /transcript-source/"
28
26
serializer = VideoSerializer (self .video )
29
- self .video_url = serializer .data .get ("urls" ).get ("mp4" ).get (144 )
27
+ self .video_url = serializer .data .get ("urls" ).get ("mp4" ).get (720 )
30
28
runner_job = RunnerJobFactory ()
31
29
self .runner_job_data = {
32
30
"runnerToken" : runner_job .runner .runnerToken ,
33
31
"jobToken" : runner_job .processingJobToken ,
34
32
}
35
33
36
- @responses .activate
37
34
def test_api_video_transcript_source (self ):
38
- """The API should return the video source."""
39
- responses .get (
40
- url = self .video_url ,
41
- body = b"video content" ,
42
- status = 200 ,
43
- content_type = "video/mp4" ,
44
- )
35
+ """The API should redirect to the video url."""
45
36
46
37
response = self .client .post (self .url , data = self .runner_job_data )
47
38
48
- self .assertEqual (response .status_code , HTTPStatus .OK )
49
- self .assertEqual (response ["Content-Type" ], "video/mp4" )
50
- self .assertEqual (b"" .join (response .streaming_content ), b"video content" )
39
+ self .assertEqual (response .status_code , HTTPStatus .MOVED_PERMANENTLY )
40
+ self .assertEqual (response ["Location" ], self .video_url )
51
41
52
- @responses .activate
53
42
def test_api_video_transcript_source_missing_video_url (self ):
54
43
"""The API should return a 404 if the video source is not available."""
55
44
self .video .resolutions = []
@@ -63,28 +52,8 @@ def test_api_video_transcript_source_missing_video_url(self):
63
52
status_code = HTTPStatus .NOT_FOUND ,
64
53
)
65
54
66
- @responses .activate
67
- def test_api_video_transcript_source_request_failure (self ):
68
- """The API should return a 400 if the request to the video source fails."""
69
- responses .get (
70
- url = self .video_url ,
71
- body = requests .RequestException (),
72
- status = 500 ,
73
- )
74
-
75
- response = self .client .post (self .url , data = self .runner_job_data )
76
-
77
- self .assertEqual (response .status_code , HTTPStatus .BAD_REQUEST )
78
-
79
- @responses .activate
80
55
def test_api_video_transcript_source_no_runner (self ):
81
56
"""The API should return a 403 if the request is not from a runner job."""
82
- responses .get (
83
- url = self .video_url ,
84
- body = b"video content" ,
85
- status = 200 ,
86
- content_type = "video/mp4" ,
87
- )
88
57
data = {
89
58
"runnerToken" : "unknown-runner-token" ,
90
59
"jobToken" : "unknown-job-token" ,
0 commit comments