Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Video AG Infrastruktur
website
Commits
1ebee253
Commit
1ebee253
authored
Jan 22, 2018
by
Andreas Valder
Browse files
added unit tests for livestreams
parent
31005d24
Changes
5
Hide whitespace changes
Inline
Side-by-side
encoding.py
View file @
1ebee253
...
@@ -114,7 +114,6 @@ def update_lecture_videos(jobid, jobtype, data, state, status):
...
@@ -114,7 +114,6 @@ def update_lecture_videos(jobid, jobtype, data, state, status):
@
edit_handler
(
'chapters'
)
@
edit_handler
(
'chapters'
)
def
chapter_changed
(
table
,
column
,
value
,
id
,
user
):
def
chapter_changed
(
table
,
column
,
value
,
id
,
user
):
print
(
'chapter_changed'
)
chapters
=
query
(
'SELECT * FROM chapters WHERE id = ?'
,
id
)
chapters
=
query
(
'SELECT * FROM chapters WHERE id = ?'
,
id
)
if
not
chapters
:
if
not
chapters
:
return
return
...
...
jobs.py
View file @
1ebee253
...
@@ -2,6 +2,7 @@ from server import *
...
@@ -2,6 +2,7 @@ from server import *
import
traceback
import
traceback
import
json
import
json
import
random
import
random
from
time
import
sleep
job_handlers
=
{}
job_handlers
=
{}
def
job_handler
(
*
types
,
state
=
'finished'
):
def
job_handler
(
*
types
,
state
=
'finished'
):
...
@@ -147,8 +148,7 @@ def jobs_schedule(hostname):
...
@@ -147,8 +148,7 @@ def jobs_schedule(hostname):
try
:
try
:
query
(
"BEGIN"
)
query
(
"BEGIN"
)
for
i
in
query
(
'SELECT * FROM jobs WHERE state = "ready" ORDER BY priority DESC'
):
for
i
in
query
(
'SELECT * FROM jobs WHERE state = "ready" ORDER BY priority DESC'
):
if
i
[
'type'
]
in
hostdata
[
'jobtypes'
]
and
\
if
i
[
'type'
]
in
hostdata
[
'jobtypes'
]
and
i
[
'queue'
]
in
hostdata
[
'queues'
]:
i
[
'queue'
]
in
hostdata
[
'queues'
]:
job
=
i
job
=
i
break
break
if
not
job
:
if
not
job
:
...
...
livestreams.py
View file @
1ebee253
...
@@ -10,9 +10,10 @@ def livestream_thumbnail():
...
@@ -10,9 +10,10 @@ def livestream_thumbnail():
@
app
.
route
(
'/internal/streaming/legacy_auth/<server>'
,
methods
=
[
'GET'
,
'POST'
])
@
app
.
route
(
'/internal/streaming/legacy_auth/<server>'
,
methods
=
[
'GET'
,
'POST'
])
def
streamauth
(
server
=
None
):
def
streamauth
(
server
=
None
):
internal
=
False
internal
=
False
for
net
in
config
.
get
(
'FSMPI_IP_RANGES'
,
[]):
if
'X-Real-IP'
in
request
.
headers
:
if
ip_address
(
request
.
headers
[
'X-Real-IP'
])
in
ip_network
(
net
):
for
net
in
config
.
get
(
'FSMPI_IP_RANGES'
,
[]):
internal
=
True
if
ip_address
(
request
.
headers
[
'X-Real-IP'
])
in
ip_network
(
net
):
internal
=
True
if
request
.
values
[
'app'
]
!=
'live'
:
if
request
.
values
[
'app'
]
!=
'live'
:
return
'Bad request'
,
400
return
'Bad request'
,
400
if
not
internal
:
if
not
internal
:
...
...
server.py
View file @
1ebee253
...
@@ -36,6 +36,7 @@ if sys.argv[0].endswith('tests.py'):
...
@@ -36,6 +36,7 @@ if sys.argv[0].endswith('tests.py'):
config
[
'SQLITE_INIT_SCHEMA'
]
=
True
config
[
'SQLITE_INIT_SCHEMA'
]
=
True
config
[
'DEBUG'
]
=
True
config
[
'DEBUG'
]
=
True
config
[
'DISABLE_SCHEDULER'
]
=
True
config
[
'DISABLE_SCHEDULER'
]
=
True
config
[
'JOBS_API_KEY'
]
=
'1'
if
config
[
'DEBUG'
]:
if
config
[
'DEBUG'
]:
app
.
jinja_env
.
auto_reload
=
True
app
.
jinja_env
.
auto_reload
=
True
...
...
tests.py
View file @
1ebee253
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
import
os
import
os
import
unittest
import
unittest
import
server
import
server
import
json
import
flask
import
flask
from
flask
import
url_for
from
flask
import
url_for
...
@@ -210,6 +211,41 @@ class VideoTestCase(unittest.TestCase):
...
@@ -210,6 +211,41 @@ class VideoTestCase(unittest.TestCase):
assert
r
.
status_code
==
302
assert
r
.
status_code
==
302
assert
url_for
(
'embed'
,
id
=
'4105'
,
course
=
'14ws-ex3'
)
in
r
.
data
.
decode
()
assert
url_for
(
'embed'
,
id
=
'4105'
,
course
=
'14ws-ex3'
)
in
r
.
data
.
decode
()
def
test_livestream
(
self
):
with
self
.
app
as
c
:
# fails because no ip is sent
r
=
self
.
app
.
get
(
'/internal/streaming/legacy_auth'
,
data
=
{
'app'
:
'live'
,
'call'
:
'publish'
,
'pass'
:
'caisoh8aht0wuSu'
,
'lecture'
:
7011
,
'name'
:
'16ss-dsal'
})
assert
r
.
status_code
==
403
r
=
self
.
app
.
get
(
'/internal/streaming/legacy_auth/testserver'
,
data
=
{
'app'
:
'live'
,
'call'
:
'publish'
,
'pass'
:
'caisoh8aht0wuSu'
,
'lecture'
:
6981
,
'name'
:
'15ws-afi'
},
headers
=
{
'X-Real-IP'
:
'137.226.35.193'
})
assert
r
.
status_code
==
200
# test for livestream job
r
=
self
.
app
.
post
(
'/internal/jobs/api/worker/test/schedule'
,
data
=
json
.
dumps
({
'jobtypes'
:
[
'simple_live_transcode'
],
'queues'
:
[
'default'
],
'apikey'
:
'1'
}),
content_type
=
'application/json'
)
assert
r
.
status_code
==
200
jobdata
=
json
.
loads
(
json
.
loads
(
r
.
data
.
decode
())[
'data'
])
assert
jobdata
.
get
(
'src'
)
==
'rtmp://testserver/live/15ws-afi'
# test for thumbnail job
import
livestreams
livestreams
.
livestream_thumbnail
()
r
=
self
.
app
.
post
(
'/internal/jobs/api/worker/test/schedule'
,
data
=
json
.
dumps
({
'jobtypes'
:
[
'thumbnail'
],
'queues'
:
[
'default'
],
'apikey'
:
'1'
}),
content_type
=
'application/json'
)
assert
r
.
status_code
==
200
jobdata
=
json
.
loads
(
json
.
loads
(
r
.
data
.
decode
())[
'data'
])
assert
jobdata
.
get
(
'lectureid'
)
==
'6981'
assert
jobdata
.
get
(
'path'
)
==
'pub/hls/15ws-afi.m3u8'
r
=
self
.
app
.
get
(
'/internal/streaming/legacy_auth/testserver'
,
data
=
{
'app'
:
'live'
,
'call'
:
'publish_done'
,
'pass'
:
'caisoh8aht0wuSu'
,
'lecture'
:
6981
,
'name'
:
'15ws-afi'
},
headers
=
{
'X-Real-IP'
:
'137.226.35.193'
})
assert
r
.
status_code
==
200
# test if there are more jobs
r
=
self
.
app
.
post
(
'/internal/jobs/api/worker/test/schedule'
,
data
=
json
.
dumps
({
'jobtypes'
:
[
'simple_live_transcode'
],
'queues'
:
[
'default'
],
'apikey'
:
'1'
}),
content_type
=
'application/json'
)
assert
r
.
status_code
==
503
# test if job was cancled
r
=
self
.
app
.
post
(
'/internal/jobs/api/job/1/ping'
,
data
=
{
'apikey'
:
'1'
,
'host'
:
'test'
,
'status'
:
'{}'
,
'state'
:
'{}'
})
assert
r
.
status_code
==
205
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
Write
Preview
Supports
Markdown
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