44import sys
55import unittest
66
7+ import responses
8+
79import twitter
810from twitter .twitter_utils import (
911 calc_expected_status_length ,
@@ -27,15 +29,29 @@ def setUp(self):
2729 sleep_on_rate_limit = False )
2830 self .base_url = 'https://api.twitter.com/1.1'
2931
32+ @responses .activate
3033 def test_parse_media_file_http (self ):
34+ with open ('testdata/168NQ.jpg' , 'rb' ) as f :
35+ img_data = f .read ()
36+ responses .add (
37+ responses .GET ,
38+ url = 'https://raw.githubusercontent.com/bear/python-twitter/master/testdata/168NQ.jpg' ,
39+ body = img_data )
3140 data_file , filename , file_size , media_type = parse_media_file (
3241 'https://raw.githubusercontent.com/bear/python-twitter/master/testdata/168NQ.jpg' )
3342 self .assertTrue (hasattr (data_file , 'read' ))
3443 self .assertEqual (filename , '168NQ.jpg' )
3544 self .assertEqual (file_size , 44772 )
3645 self .assertEqual (media_type , 'image/jpeg' )
3746
47+ @responses .activate
3848 def test_parse_media_file_http_with_query_strings (self ):
49+ with open ('testdata/168NQ.jpg' , 'rb' ) as f :
50+ img_data = f .read ()
51+ responses .add (
52+ responses .GET ,
53+ url = 'https://raw.githubusercontent.com/bear/python-twitter/master/testdata/168NQ.jpg' ,
54+ body = img_data )
3955 data_file , filename , file_size , media_type = parse_media_file (
4056 'https://raw.githubusercontent.com/bear/python-twitter/master/testdata/168NQ.jpg?query=true' )
4157 self .assertTrue (hasattr (data_file , 'read' ))
0 commit comments