예제 #1
0
 def fake_query(id=None, part=None):
     assert_equals(id, expected_video_id, message='attempted to retrieve unexpected video %s' % id)
     assert_equals(part, expected_parts, message='unexpected parts')
     if video_data_response:
         return AttrDict(execute=lambda: video_data_response)
     data = {'error': {'errors': [error]}}
     error_content = json.dumps(data)
     exception = HttpError('dummy', error_content)
     def raising_execute():
         raise exception
     return AttrDict(execute=raising_execute)
예제 #2
0
 def _build_client_instance(self, expected_video_id, expected_parts, video_data_response=None, error=None):
     def fake_query(id=None, part=None):
         assert_equals(id, expected_video_id, message='attempted to retrieve unexpected video %s' % id)
         assert_equals(part, expected_parts, message='unexpected parts')
         if video_data_response:
             return AttrDict(execute=lambda: video_data_response)
         data = {'error': {'errors': [error]}}
         error_content = json.dumps(data)
         exception = HttpError('dummy', error_content)
         def raising_execute():
             raise exception
         return AttrDict(execute=raising_execute)
     fake_yt = AttrDict(
         videos=lambda: AttrDict(list=fake_query),
     )
     return YouTubeClient(fake_yt)
예제 #3
0
 def _upload_parameters(self):
     fake_file = StringIO('fake mp3 file content')
     parameters = dict(
         name='John Doe',
         email='*****@*****.**',
         title='testing mp3 async upload',
         description='a great song',
         url='',
         file=AttrDict(read=fake_file.read, filename='awesome-song.mp3'),
     )
     return parameters
예제 #4
0
    def test_can_fetch_video_details(self):
        video_id = 'AQTYoRpCXwg'
        youtube_client = self.mock_client(
            video_id=video_id,
            duration='PT2M10S',
            title='Puppies and Cats',
            description='everyone loves kittens',
            expected_parts='snippet,contentDetails',
        )
        result = youtube_client.fetch_video_details(video_id)
        assert_true(result)

        meta = AttrDict(result.meta_info)
        assert_equals(video_id, meta.unique_id)
        assert_equals(130, meta.duration)
        assert_equals('Puppies and Cats', meta.display_name)
        assert_equals('everyone loves kittens', meta.description)
        expected_thumb = {
            'width': 640,
            'height': 480,
            'url': 'https://i.ytimg.com/vi/%s/sddefault.jpg' % video_id,
        }
        assert_equals(expected_thumb, meta.thumbnail)
        assert_equals(VIDEO, meta.type)
예제 #5
0
 def setUp(self):
     self.system = PermissionSystem([])
     user = AttrDict(groups=[])
     self.perm = UserPermissions(user, self.system)
예제 #6
0
 def test_can_encode_file(self):
     fake_fp = AttrDict(name='foo.txt', read=lambda: 'foobar')
     results = self.encode_and_parse([('file', fake_fp)])
     assert_equals(dict(file='foobar'), results)