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)
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)
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
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)
def setUp(self): self.system = PermissionSystem([]) user = AttrDict(groups=[]) self.perm = UserPermissions(user, self.system)
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)