-
Notifications
You must be signed in to change notification settings - Fork 7
/
tests.py
80 lines (65 loc) · 2.94 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import unittest
from m3u8_generator import PlaylistGenerator
class TestPlaylistCase(unittest.TestCase):
def setUp(self):
self.playlist_entries = [
{
'name': 'awesome_video_001.mp4',
'duration': '10.0',
'start': '0.00',
'end': '10.0'
},
{
'name': 'awesome_video_002.mp4',
'duration': '10.0',
'start': '10.0',
'end': '20.0'
},
{
'name': 'awesome_video_003.mp4',
'duration': '10.0',
'start': '20.00',
'end': '30.01'
},
{
'name': 'awesome_video_004.mp4',
'duration': '10.0',
'start': '30.00',
'end': '40.0'
}
]
def test_playlist_durataion_generation(self):
"""When a user provides a playlist it needs to count the total duration."""
playlist_duration = PlaylistGenerator(playlist_entries=self.playlist_entries).duration
self.assertEquals(playlist_duration, 40, msg="Ensure duration is counted")
def test_playlist_header_generation(self):
"""Make sure there is the EXTM3U on the firstline"""
header = PlaylistGenerator(self.playlist_entries, version=3)._m3u8_header_template()
self.assertTrue('EXTM3U' in header)
def test_playlist_header_version_generation(self):
"""Make sure there is the version identifier"""
header = PlaylistGenerator(self.playlist_entries, version=3)._m3u8_header_template()
self.assertTrue('EXT-X-VERSION:3' in header)
def test_playlist_header_duration_generation(self):
"""Make sure there is the duration identifier """
header = PlaylistGenerator(self.playlist_entries, version=3)._m3u8_header_template()
self.assertTrue('EXT-X-TARGETDURATION:40' in header)
def test_playlist_header_sequence_generation(self):
"""Make sure there is the sequence"""
header = PlaylistGenerator(self.playlist_entries, version=3)._m3u8_header_template()
self.assertTrue('EXT-X-MEDIA-SEQUENCE:0' in header)
def test_end_of_playlist(self):
"""Ensures that the end playlist is included"""
playlist = PlaylistGenerator(self.playlist_entries, version=3).generate()
self.assertTrue('#EXT-X-ENDLIST' in playlist)
def test_end_of_is_included(self):
"""Ensures that the end playlist is included"""
playlist = PlaylistGenerator(self.playlist_entries, version=3).generate()
self.assertTrue('#EXT-X-ENDLIST' in playlist)
def test_end_of_is_not_included(self):
"""Ensures that the end playlist is included"""
playlist = PlaylistGenerator(self.playlist_entries, version=3)
playlist.end_playlist = False
self.assertTrue('#EXT-X-ENDLIST' not in playlist.generate())
if __name__ == '__main__':
unittest.main()