Some code simplifications & logging for Zencoder notifications.

This commit is contained in:
2016-03-25 17:21:18 +01:00
parent d7ee2121d9
commit fd5bcaec52
2 changed files with 102 additions and 45 deletions

50
tests/test_encoding.py Normal file
View File

@@ -0,0 +1,50 @@
"""Test cases for the zencoder notifications."""
import json
from common_test_class import AbstractPillarTest
class ZencoderNotificationTest(AbstractPillarTest):
def test_missing_secret(self):
with self.app.test_request_context():
resp = self.client.post('/encoding/zencoder/notifications')
self.assertEqual(401, resp.status_code)
def test_wrong_secret(self):
with self.app.test_request_context():
resp = self.client.post('/encoding/zencoder/notifications',
headers={'X-Zencoder-Notification-Secret': 'koro'})
self.assertEqual(401, resp.status_code)
def test_good_secret_missing_file(self):
with self.app.test_request_context():
secret = self.app.config['ZENCODER_NOTIFICATIONS_SECRET']
resp = self.client.post('/encoding/zencoder/notifications',
data=json.dumps({'job': {'id': 'koro-007'}}),
headers={'X-Zencoder-Notification-Secret': secret,
'Content-Type': 'application/json'})
self.assertEqual(404, resp.status_code)
def test_good_secret_existing_file(self):
self.ensure_file_exists(file_overrides={
'processing': {'backend': 'zencoder',
'job_id': 'koro-007',
'status': 'processing'}
})
with self.app.test_request_context():
secret = self.app.config['ZENCODER_NOTIFICATIONS_SECRET']
resp = self.client.post('/encoding/zencoder/notifications',
data=json.dumps({'job': {'id': 'koro-007',
'state': 'done'},
'outputs': [{
'format': 'jpg',
'width': 2048,
'file_size_in_bytes': 15,
}]}),
headers={'X-Zencoder-Notification-Secret': secret,
'Content-Type': 'application/json'})
# TODO: check that the file in MongoDB is actually updated properly.
self.assertEqual(200, resp.status_code)