diff --git a/encoding.py b/encoding.py
index 3b912f078346cefc2ba80dcbb4d7cc093be6f49b..22bc8b94224c0758190a86acdcbb3dd296020027 100644
--- a/encoding.py
+++ b/encoding.py
@@ -114,7 +114,6 @@ def update_lecture_videos(jobid, jobtype, data, state, status):
 
 @edit_handler('chapters')
 def chapter_changed(table, column, value, id, user):
-	print('chapter_changed')
 	chapters = query('SELECT * FROM chapters WHERE id = ?', id)
 	if not chapters:
 		return
diff --git a/jobs.py b/jobs.py
index 0696c730c767e8d0806383e4d43f9605bfd6a61e..1168e3331f49842c3f19a956232b70c0567ec138 100644
--- a/jobs.py
+++ b/jobs.py
@@ -2,6 +2,7 @@ from server import *
 import traceback
 import json
 import random
+from time import sleep
 
 job_handlers = {}
 def job_handler(*types, state='finished'):
@@ -147,8 +148,7 @@ def jobs_schedule(hostname):
 		try:
 			query("BEGIN")
 			for i in query('SELECT * FROM jobs WHERE state = "ready" ORDER BY priority DESC'):
-				if i['type'] in hostdata['jobtypes'] and \
-						i['queue'] in hostdata['queues']:
+				if i['type'] in hostdata['jobtypes'] and i['queue'] in hostdata['queues']:
 					job = i
 					break
 			if not job:
diff --git a/livestreams.py b/livestreams.py
index 42ebc0d20358e3c8cf2046c062bcf1e46b702fb7..8f71de6ef74decd174c3ee0f4d7d64d35b2f8b92 100644
--- a/livestreams.py
+++ b/livestreams.py
@@ -10,9 +10,10 @@ def livestream_thumbnail():
 @app.route('/internal/streaming/legacy_auth/<server>', methods=['GET', 'POST'])
 def streamauth(server=None):
 	internal = False
-	for net in config.get('FSMPI_IP_RANGES', []):
-		if ip_address(request.headers['X-Real-IP']) in ip_network(net):
-			internal = True
+	if 'X-Real-IP' in request.headers:
+		for net in config.get('FSMPI_IP_RANGES', []):
+			if ip_address(request.headers['X-Real-IP']) in ip_network(net):
+				internal = True
 	if request.values['app'] != 'live':
 		return 'Bad request', 400
 	if not internal:
diff --git a/server.py b/server.py
index b762ae168c636372c6d79789e27bcde4839bdebe..bf5ebaa25565eb8ba3e15d56c794d4e393961b74 100644
--- a/server.py
+++ b/server.py
@@ -36,6 +36,7 @@ if sys.argv[0].endswith('tests.py'):
 	config['SQLITE_INIT_SCHEMA'] = True
 	config['DEBUG'] = True
 	config['DISABLE_SCHEDULER'] = True
+	config['JOBS_API_KEY'] = '1'
 if config['DEBUG']:
 	app.jinja_env.auto_reload = True
 
diff --git a/tests.py b/tests.py
index acdb6f6cb4a7f5d76954c263063146b1b5451684..805d78f02ac8b98e2e157dfe641d0b7ef79c4c84 100755
--- a/tests.py
+++ b/tests.py
@@ -3,6 +3,7 @@
 import os
 import unittest
 import server
+import json
 
 import flask
 from flask import url_for
@@ -210,6 +211,41 @@ class VideoTestCase(unittest.TestCase):
 			assert r.status_code == 302
 			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__':
 	unittest.main()