Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Romain Courteaud
slapos
Commits
25da472d
Commit
25da472d
authored
Nov 18, 2022
by
Boxiang Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
peertube: add test_video_upload
parent
c848084e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
2 deletions
+89
-2
software/peertube/test/small.mp4
software/peertube/test/small.mp4
+0
-0
software/peertube/test/test.py
software/peertube/test/test.py
+89
-2
No files found.
software/peertube/test/small.mp4
0 → 100644
View file @
25da472d
File added
software/peertube/test/test.py
View file @
25da472d
...
...
@@ -28,6 +28,8 @@
import
os
import
requests
import
re
from
mimetypes
import
guess_type
from
json.decoder
import
JSONDecodeError
from
slapos.testing.testcase
import
makeModuleSetUpAndTestCaseClass
...
...
@@ -40,8 +42,6 @@ class TestPeerTube(SlapOSInstanceTestCase):
def
setUp
(
self
):
self
.
connection_parameters
=
self
.
computer_partition
.
getConnectionParameterDict
()
"""Test that the service url.${kind} responds Hello ${name}
"""
def
test_get
(
self
):
url
=
self
.
connection_parameters
[
'frontend-url'
]
response
=
requests
.
get
(
url
,
verify
=
False
)
...
...
@@ -50,3 +50,90 @@ class TestPeerTube(SlapOSInstanceTestCase):
response
=
requests
.
get
(
url
+
"/feeds/videos.xml?sort=-trending"
,
verify
=
False
)
self
.
assertEqual
(
requests
.
codes
[
'OK'
],
response
.
status_code
)
self
.
assertIn
(
'rss'
,
response
.
text
)
def
test_video_upload
(
self
):
api_url
=
self
.
connection_parameters
[
'frontend-url'
]
# api_url: https://[2001:67c:1254:fd::9ee2]:9443
# self.connection_parameters
# {'backend-url': 'https://[2001:67c:1254:fd::9ee2]:9443', 'frontend-hostname': '[2001:67c:1254:fd::9ee2]:9443', 'frontend-url': 'https://[2001:67c:1254:fd::9ee2]:9443', 'password': '8ydTfRpv', 'username': 'root'}
response
=
requests
.
get
(
api_url
+
'/api/v1/oauth-clients/local'
,
verify
=
False
)
self
.
assertEqual
(
requests
.
codes
[
'OK'
],
response
.
status_code
)
try
:
data
=
response
.
json
()
except
JSONDecodeError
:
self
.
fail
(
"No json file returned! Maybe your Peertube API is incorrect."
)
client_id
=
data
[
'client_id'
]
client_secret
=
data
[
'client_secret'
]
username
=
self
.
connection_parameters
[
'username'
]
password
=
self
.
connection_parameters
[
'password'
]
auth_data
=
{
'client_id'
:
client_id
,
'client_secret'
:
client_secret
,
'grant_type'
:
'password'
,
'response_type'
:
'code'
,
'username'
:
username
,
'password'
:
password
}
auth_result
=
requests
.
post
(
api_url
+
'/api/v1/users/token'
,
data
=
auth_data
,
verify
=
False
)
self
.
assertEqual
(
requests
.
codes
[
'OK'
],
auth_result
.
status_code
)
try
:
auth_result_json
=
auth_result
.
json
()
except
JSONDecodeError
:
self
.
fail
(
"No json file returned! Maybe your Peertube API is incorrect."
)
token_type
=
auth_result_json
[
'token_type'
]
access_token
=
auth_result_json
[
'access_token'
]
headers
=
{
'Authorization'
:
token_type
+
' '
+
access_token
}
video_name
=
"Small test video"
file_path
=
"./small.mp4"
file_mime_type
=
guess_type
(
file_path
)[
0
]
with
open
(
file_path
,
'rb'
)
as
f
:
video_data
=
{
'channelId'
:
1
,
'name'
:
video_name
,
'commentEnabled'
:
False
,
}
upload_response
=
requests
.
post
(
api_url
+
'/api/v1/videos/upload'
,
headers
=
headers
,
data
=
video_data
,
files
=
{
'videofile'
:
(
os
.
path
.
basename
(
file_path
),
f
,
file_mime_type
)},
verify
=
False
)
try
:
video_ids
=
upload_response
.
json
()
except
JSONDecodeError
:
self
.
fail
(
"No json file returned! Maybe your Peertube API is incorrect."
)
# {'video': {'id': 7, 'shortUUID': 'nrnKJNCsRP7NkwRr51TK3e', 'uuid': 'ad9ae99d-07db-4e4c-adc3-73566d59a4c5'}}
self
.
assertIn
(
'video'
,
video_ids
)
id
=
video_ids
[
'video'
][
'id'
]
# Check the video is uploaded, we can get its stats
response
=
requests
.
get
(
api_url
+
'/api/v1/videos/'
+
str
(
id
)
+
'/stats/overall'
,
headers
=
headers
,
verify
=
False
)
self
.
assertEqual
(
requests
.
codes
[
'OK'
],
response
.
status_code
)
try
:
result
=
response
.
json
()
except
JSONDecodeError
:
self
.
fail
(
"No json file returned! Maybe your Peertube API is incorrect."
)
self
.
assertIn
(
'totalWatchTime'
,
response
.
json
())
# Check the transcoding is enabled
response
=
requests
.
get
(
api_url
+
'/api/v1/config'
,
headers
=
headers
,
verify
=
False
)
try
:
result
=
response
.
json
()
except
JSONDecodeError
:
self
.
fail
(
"No json file returned! Maybe your Peertube API is incorrect."
)
# {
# 'hls': {'enabled': True},
# 'webtorrent': {'enabled': False},
# 'enabledResolutions': [144, 240, 360, 480, 720, 1080, 1440, 2160],
# 'profile': 'default',
# 'availableProfiles': ['default']
# }
self
.
assertIn
(
"hls"
,
result
[
'transcoding'
])
self
.
assertIn
(
"True"
,
str
(
result
[
'transcoding'
][
'hls'
]))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment