def test_utils_error_checking(self): with open('testdata/168NQ.jpg', 'r') as f: self.assertRaises(twitter.TwitterError, lambda: parse_media_file(f)) with open('testdata/user_timeline.json', 'rb') as f: self.assertRaises(twitter.TwitterError, lambda: parse_media_file(f)) self.assertRaises( twitter.TwitterError, lambda: twitter.twitter_utils.enf_type('test', int, 'hi'))
def test_utils_error_checking(self): with open('testdata/168NQ.jpg', 'r') as f: self.assertRaises( twitter.TwitterError, lambda: parse_media_file(f)) with open('testdata/user_timeline.json', 'rb') as f: self.assertRaises( twitter.TwitterError, lambda: parse_media_file(f)) self.assertRaises( twitter.TwitterError, lambda: twitter.twitter_utils.enf_type('test', int, 'hi'))
def test_parse_media_file_fileobj(self): with open('testdata/168NQ.jpg', 'rb') as f: data_file, filename, file_size, media_type = parse_media_file(f) self.assertTrue(hasattr(data_file, 'read')) self.assertEqual(filename, '168NQ.jpg') self.assertEqual(file_size, 44772) self.assertEqual(media_type, 'image/jpeg')
def test_parse_media_file_local_file(self): data_file, filename, file_size, media_type = parse_media_file( 'testdata/168NQ.jpg') self.assertTrue(hasattr(data_file, 'read')) self.assertEqual(filename, '168NQ.jpg') self.assertEqual(file_size, 44772) self.assertEqual(media_type, 'image/jpeg')
def test_parse_media_file_http(self): data_file, filename, file_size, media_type = parse_media_file( 'https://raw.githubusercontent.com/bear/python-twitter/master/testdata/168NQ.jpg') self.assertTrue(hasattr(data_file, 'read')) self.assertEqual(filename, '168NQ.jpg') self.assertEqual(file_size, 44772) self.assertEqual(media_type, 'image/jpeg')
def test_parse_media_file_subtitle(self): data_file, filename, file_size, media_type = parse_media_file( 'testdata/subs.srt') self.assertTrue(hasattr(data_file, 'read')) self.assertEqual(filename, 'subs.srt') self.assertEqual(file_size, 157) self.assertEqual(media_type, 'text/srt')
def test_parse_media_file_http_with_query_strings(self): with open('testdata/168NQ.jpg', 'rb') as f: img_data = f.read() responses.add( responses.GET, url= 'https://raw.githubusercontent.com/bear/python-twitter/master/testdata/168NQ.jpg', body=img_data) data_file, filename, file_size, media_type = parse_media_file( 'https://raw.githubusercontent.com/bear/python-twitter/master/testdata/168NQ.jpg?query=true' ) self.assertTrue(hasattr(data_file, 'read')) self.assertEqual(filename, '168NQ.jpg') self.assertEqual(file_size, 44772) self.assertEqual(media_type, 'image/jpeg')