2016-03-25 17:21:18 +01:00
|
|
|
"""Test cases for the zencoder notifications."""
|
|
|
|
import json
|
|
|
|
|
2016-08-19 09:19:06 +02:00
|
|
|
from pillar.tests import AbstractPillarTest
|
2016-03-25 17:21:18 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ZencoderNotificationTest(AbstractPillarTest):
|
2018-01-26 12:15:42 +01:00
|
|
|
def setUp(self, **kwargs):
|
|
|
|
super().setUp(**kwargs)
|
|
|
|
self.enter_app_context()
|
|
|
|
self.secret = self.app.config['ZENCODER_NOTIFICATIONS_SECRET']
|
2016-03-25 17:21:18 +01:00
|
|
|
|
|
|
|
def test_missing_secret(self):
|
2018-01-26 12:15:42 +01:00
|
|
|
self.post('/api/encoding/zencoder/notifications',
|
|
|
|
expected_status=401)
|
2016-03-25 17:21:18 +01:00
|
|
|
|
|
|
|
def test_wrong_secret(self):
|
2018-01-26 12:15:42 +01:00
|
|
|
self.post('/api/encoding/zencoder/notifications',
|
|
|
|
headers={'X-Zencoder-Notification-Secret': 'koro'},
|
|
|
|
expected_status=401)
|
2016-03-25 17:21:18 +01:00
|
|
|
|
|
|
|
def test_good_secret_existing_file(self):
|
|
|
|
self.ensure_file_exists(file_overrides={
|
|
|
|
'processing': {'backend': 'zencoder',
|
|
|
|
'job_id': 'koro-007',
|
|
|
|
'status': 'processing'}
|
|
|
|
})
|
|
|
|
|
2018-01-26 12:15:42 +01:00
|
|
|
self.post('/api/encoding/zencoder/notifications',
|
|
|
|
json={'job': {'id': 'koro-007',
|
|
|
|
'state': 'done'},
|
|
|
|
'outputs': [{
|
|
|
|
'format': 'jpg',
|
|
|
|
'height': 1080,
|
|
|
|
'width': 2048,
|
|
|
|
'file_size_in_bytes': 15,
|
|
|
|
'md5_checksum': None,
|
|
|
|
}],
|
|
|
|
'input': {
|
|
|
|
'duration_in_ms': 5000,
|
|
|
|
}},
|
|
|
|
headers={'X-Zencoder-Notification-Secret': self.secret},
|
|
|
|
expected_status=204)
|
2016-03-25 17:21:18 +01:00
|
|
|
|
|
|
|
# TODO: check that the file in MongoDB is actually updated properly.
|