11import tracemalloc
22import unittest
3+ from typing import Dict , Any
34
45import responses
56
67import twitch
8+ from .test_helix_user import TestHelixUser
79
810tracemalloc .start ()
911
1012
1113class TestHelixVideo (unittest .TestCase ):
12-
13- @responses .activate
14- def test_video (self ):
14+ video : Dict [str , Dict [str , Any ]] = {
15+ '471855782' : {
16+ 'id' : '471855782' ,
17+ 'user_id' : '26301881' ,
18+ 'user_name' : 'sodapoppin' ,
19+ 'title' : '2 days til Classic, passing the time til then. ' ,
20+ 'description' : '' ,
21+ 'created_at' : '2019-08-24T21:34:03Z' ,
22+ 'published_at' : '2019-08-24T21:34:03Z' ,
23+ 'url' : 'https://www.twitch.tv/videos/471855782' ,
24+ 'thumbnail_url' : '' ,
25+ 'viewable' : 'public' ,
26+ 'view_count' : 329 ,
27+ 'language' : 'en' ,
28+ 'type' : 'archive' ,
29+ 'duration' : '2h14m55s'
30+ },
31+ '471295896' : {
32+ 'id' : '471295896' ,
33+ 'user_id' : '26301881' ,
34+ 'user_name' : 'sodapoppin' ,
35+ 'title' : '3 days til Classic, passing the time til then. ' ,
36+ 'description' : '' ,
37+ 'created_at' : '2019-08-23T18:40:05Z' ,
38+ 'published_at' : '2019-08-23T18:40:05Z' ,
39+ 'url' : 'https://www.twitch.tv/videos/471295896' ,
40+ 'thumbnail_url' : 'https://static-cdn.jtvnw.net/s3_vods/7d5ae2c2918cf4ca8579_sodapoppin_35403289856_1281380185/thumb/thumb0-%{width}x%{height}.jpg' ,
41+ 'viewable' : 'public' ,
42+ 'view_count' : 5892 ,
43+ 'language' : 'en' ,
44+ 'type' : 'archive' ,
45+ 'duration' : '6h4m13s' }
46+ }
47+
48+ def setUp (self ) -> None :
1549 responses .add (responses .GET , 'https://api.twitch.tv/helix/videos?id=471855782' ,
1650 match_querystring = True ,
1751 json = {
18- 'data' : [{
19- 'id' : '471855782' ,
20- 'user_id' : '26301881' ,
21- 'user_name' : 'sodapoppin' ,
22- 'title' : '2 days til Classic, passing the time til then. ' ,
23- 'description' : '' ,
24- 'created_at' : '2019-08-24T21:34:03Z' ,
25- 'published_at' : '2019-08-24T21:34:03Z' ,
26- 'url' : 'https://www.twitch.tv/videos/471855782' ,
27- 'thumbnail_url' : '' ,
28- 'viewable' : 'public' ,
29- 'view_count' : 329 ,
30- 'language' : 'en' ,
31- 'type' : 'archive' ,
32- 'duration' : '2h14m55s' }],
52+ 'data' : [TestHelixVideo .video ['471855782' ]],
3353 'pagination' : {'cursor' : 'eyJiIjpudWxsLCJhIjp7Ik9mZnNldCI6MX19' }
3454 })
35-
36- helix = twitch .Helix ('client-id' , use_cache = True )
37-
38- # Get display name to display name
39- self .assertEqual (helix .video ('471855782' ).user_name , 'sodapoppin' )
40-
41- @responses .activate
42- def test_first_videos (self ):
4355 responses .add (responses .GET , 'https://api.twitch.tv/helix/users?login=sodapoppin' ,
4456 match_querystring = True ,
45- json = {
46- 'data' : [
47- {
48- 'id' : '26301881' , 'login' : 'sodapoppin' , 'display_name' : 'sodapoppin' , 'type' : '' ,
49- 'broadcaster_type' : 'partner' ,
50- 'description' : 'Wtf do i write here? Click my stream, or i scream.' ,
51- 'profile_image_url' : 'https://static-cdn.jtvnw.net/jtv_user_pictures/sodapoppin-profile_image-10049b6200f90c14-300x300.png' ,
52- 'offline_image_url' : 'https://static-cdn.jtvnw.net/jtv_user_pictures/7ed72b04-897e-4a85-a3c9-2a8ba74aeaa7-channel_offline_image-1920x1080.jpg' ,
53- 'view_count' : 287171213
54- }]
55- })
57+ json = {'data' : [TestHelixUser .user ['sodapoppin' ]]})
5658
5759 responses .add (responses .GET , 'https://api.twitch.tv/helix/videos?user_id=26301881&first=2' ,
5860 match_querystring = True ,
5961 json = {
60- 'data' : [
61- {
62- 'id' : '471855782' , 'user_id' : '26301881' , 'user_name' : 'sodapoppin' ,
63- 'title' : '2 days til Classic, passing the time til then. ' , 'description' : '' ,
64- 'created_at' : '2019-08-24T21:34:03Z' , 'published_at' : '2019-08-24T21:34:03Z' ,
65- 'url' : 'https://www.twitch.tv/videos/471855782' , 'thumbnail_url' : '' ,
66- 'viewable' : 'public' , 'view_count' : 453 , 'language' : 'en' , 'type' : 'archive' ,
67- 'duration' : '2h21m43s'
68- },
69- {
70- 'id' : '471295896' , 'user_id' : '26301881' , 'user_name' : 'sodapoppin' ,
71- 'title' : '3 days til Classic, passing the time til then. ' , 'description' : '' ,
72- 'created_at' : '2019-08-23T18:40:05Z' , 'published_at' : '2019-08-23T18:40:05Z' ,
73- 'url' : 'https://www.twitch.tv/videos/471295896' ,
74- 'thumbnail_url' : 'https://static-cdn.jtvnw.net/s3_vods/7d5ae2c2918cf4ca8579_sodapoppin_35403289856_1281380185/thumb/thumb0-%{width}x%{height}.jpg' ,
75- 'viewable' : 'public' , 'view_count' : 5892 , 'language' : 'en' , 'type' : 'archive' ,
76- 'duration' : '6h4m13s' }],
62+ 'data' : [TestHelixVideo .video ['471855782' ], TestHelixVideo .video ['471295896' ]],
7763 'pagination' : {'cursor' : 'eyJiIjpudWxsLCJhIjp7Ik9mZnNldCI6Mn19' }
7864 })
7965
66+ @responses .activate
67+ def test_video (self ):
68+ helix = twitch .Helix ('client-id' , use_cache = True )
69+
70+ # Get display name to display name
71+ self .assertEqual (helix .video ('471855782' ).user_name , 'sodapoppin' )
72+
73+ @responses .activate
74+ def test_first_videos (self ):
8075 # Should returned cached data from above
8176 helix = twitch .Helix ('client-id' , use_cache = True )
8277
@@ -85,28 +80,8 @@ def test_first_videos(self):
8580
8681 @responses .activate
8782 def test_custom_video_cache (self ):
88- responses .add (responses .GET , 'https://api.twitch.tv/helix/videos?id=471855782' ,
89- match_querystring = True ,
90- json = {
91- 'data' : [
92- {'id' : '471855782' ,
93- 'user_id' : '26301881' ,
94- 'user_name' : 'sodapoppin' ,
95- 'title' : '2 days til Classic, passing the time til then. ' ,
96- 'description' : '' ,
97- 'created_at' : '2019-08-24T21:34:03Z' ,
98- 'published_at' : '2019-08-24T21:34:03Z' ,
99- 'url' : 'https://www.twitch.tv/videos/471855782' ,
100- 'thumbnail_url' : '' ,
101- 'viewable' : 'public' ,
102- 'view_count' : 329 ,
103- 'language' : 'en' ,
104- 'type' : 'archive' ,
105- 'duration' : '2h14m55s' }],
106- 'pagination' : {'cursor' : 'eyJiIjpudWxsLCJhIjp7Ik9mZnNldCI6MX19' }})
107-
10883 helix = twitch .Helix ('client-id' , use_cache = True )
109- helix .video (471855782 )
84+ _ = helix .video (471855782 )
11085
11186 # Videos have custom caching, such that url should not be cached
11287 self .assertFalse (helix .api .SHARED_CACHE .has ('GET:https://api.twitch.tv/helix/videos?id=471855782' ))
0 commit comments