diff --git a/tests/test_captions.py b/tests/test_captions.py index 1e57155..67e764e 100644 --- a/tests/test_captions.py +++ b/tests/test_captions.py @@ -1,12 +1,11 @@ ''' -Last Updated: 11/30/2018 +Last Updated: 12/20/2018 Tests the parameters for the `get_captions` method in the YoutubeDataApi TO DO ===== -* parser -* LIST OF VALID VIDEO IDS DOES NOT WORK AND I HAVE NO IDEA WHY +NONE! Functions Tested ================ @@ -16,6 +15,7 @@ def get_captions(self, video_id, lang_code='en', parser=P.parse_caption_track, * ==== * video_id * lang_code +* parser ''' import sys @@ -26,16 +26,16 @@ def get_captions(self, video_id, lang_code='en', parser=P.parse_caption_track, * from collections import OrderedDict from youtube_api import YoutubeDataApi +from youtube_api import parsers as P class TestVideo(unittest.TestCase): - - @classmethod - def setUpClass(cls): - cls.key = os.environ.get('YT_KEY') - cls.yt = YoutubeDataApi(cls.key) - cls.video_id = 'wmxDZeh8W34' - cls.video_id_list = ['wmxDZeh8W34', 'PIXQdfiRZNk','nvEFb_dWJdQ'] - cls.fake_vid = '12345' + + def __init__(): + self.key = os.environ.get('YT_KEY') + self.yt = YoutubeDataApi(self.key) + self.video_id = 'wmxDZeh8W34' + self.video_id_list = ['wmxDZeh8W34', 'PIXQdfiRZNk','nvEFb_dWJdQ'] + self.fake_vid = '12345' #Verified by Megan Brown on 11/30/2018 def test_valid_caption(self): @@ -44,12 +44,12 @@ def test_valid_caption(self): self.assertEqual(type(resp), dict) self.assertEqual(type(resp['video_id']), str) - '''#Written by Megan Brown on 11/30/2018 + #Written by Megan Brown on 11/30/2018 def test_valid_list_of_captions(self): resp = self.yt.get_captions(self.video_id_list) self.assertEqual(type(resp), list) - self.assertEqual(type(resp[0]['video_id']), str)''' + self.assertEqual(type(resp[0]['video_id']), str) #Written by Megan Brown on 11/30/2018 def test_invalid_short_caption(self): @@ -63,6 +63,11 @@ def test_list_of_captions_with_invalid_string(self): with self.assertRaises(Exception): resp = self.yt.get_captions(error_list) + + #Written by Megan Brown on 12/20/2018 + def test_caption_parser_w_raw_json(self): + captions = self.yt.get_captions(self.video_id, parser=P.raw_json) + self.assertTrue(isinstance(self.captions, dict)) if __name__ == '__main__': unittest.main() diff --git a/tests/test_channel_methods.py b/tests/test_channel_methods.py index fae31fa..502d01e 100644 --- a/tests/test_channel_methods.py +++ b/tests/test_channel_methods.py @@ -1,5 +1,5 @@ ''' -Last Updated: 11/30/2018 +Last Updated: 12/28/2018 Tests the parameters for the channel methods in the YoutubeDataApi @@ -69,18 +69,21 @@ def get_featured_channels_gen(self, channel_id, parser=P.parse_featured_channels class TestVideo(unittest.TestCase): - @classmethod - def setUpClass(cls): - cls.key = os.environ.get('YT_KEY') - cls.yt = YoutubeDataApi(cls.key) - cls.channel_id = 'UC3XTzVzaHQEd30rQbuvCtTQ' - cls.channel_title = 'LastWeekTonight' + def __init__(): + self.key = os.environ.get('YT_KEY') + self.yt = YoutubeDataApi(self.key) + self.channel_id = 'UC3XTzVzaHQEd30rQbuvCtTQ' + self.channel_title = 'LastWeekTonight' #written by Megan Brown on 11/30/2018 def test_channel_id(self): resp = self.yt.get_channel_id_from_user(channel_title) self.assertEqual(resp, self.channel_id) + def test_get_channel_metadata_channel_id(self): + resp = self.yt.get_channel_metadata(self.channel_id) + self.assertEqual(resp['channel_id'], self.channel_id) + self.assertEqual(resp['channel_title']) if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/tests/test_initialization.py b/tests/test_initialization.py index 395143c..94fd661 100644 --- a/tests/test_initialization.py +++ b/tests/test_initialization.py @@ -5,6 +5,7 @@ TO DO ===== +NONE Functions Tested @@ -32,10 +33,10 @@ def verify_key(self) class TestAPI(unittest.TestCase): @classmethod - def setUpClass(cls): - cls.key = os.environ.get('YT_KEY') - cls.wrong_key = 'xxxxxxxxx' - cls.yt = YoutubeDataApi(cls.key) + def setUpClass(): + self.key = os.environ.get('YT_KEY') + self.wrong_key = 'xxxxxxxxx' + self.yt = YoutubeDataApi(cls.key) #Verified by Megan Brown on 11/30/2018 def test_init(self):