-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_playlistr.py
57 lines (40 loc) · 1.63 KB
/
test_playlistr.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
import unittest
import sys
import os
from apiclient.discovery import build
from flaskapp import app
import playlistr
class TestPlaylistr(unittest.TestCase):
def assert_video_in_list(self, videoId, relative_dir):
script_dir = os.path.dirname(__file__)
with open(os.path.join(script_dir, relative_dir), 'r') as tracklist:
pl = playlistr.make_playlist(tracklist.read())
self.assertIn(videoId, pl)
def test_youtube_search(self):
yt = build(playlistr.YOUTUBE_API_SERVICE_NAME,
playlistr.YOUTUBE_API_VERSION,
developerKey=playlistr.DEVELOPER_KEY)
videoId = playlistr.youtube_search('gangam style')
self.assertEqual(videoId[0], '9bZkp7q19f0')
def test_make_playlist1(self):
tracklist = ' 01. gangam style \n \t never gonna give '
pl = playlistr.make_playlist(tracklist)
self.assertIn('9bZkp7q19f0', pl)
def test_make_playlist2(self):
self.assert_video_in_list('OPf0YbXqDm0', 'datalists/tracklist1.txt')
def test_make_playlist3(self):
self.assert_video_in_list('mxvG-_KvWlw', 'datalists/tracklist2.txt')
class TestFlask(unittest.TestCase):
def setUp(self):
self.app = app.test_client()
self.app.testing = True
def tearDown(self):
pass
def test_home_response(self):
result = self.app.get('/')
self.assertEqual(result.status_code, 200)
def test_home_data(self):
result = self.app.get('/')
self.assertIn('Playlistr', str(result.data))
if __name__ == '__main__':
unittest.main()