Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_request_constructor():
req = Request(
method='GET',
url='https://example.com/api/v1/example_resource?example_query=example_arg',
headers={'Authorization': 'Bearer asdasdasd'},
json={'data': 'asasdasd'},
media_upload=MediaUpload('asdasd'),
media_download=MediaDownload('assda')
)
raise ValidationError('upload_file was provided while method doesn\'t support media upload')
# If resumable, create resumable object
resumable = self._build_resumeable_media(upload_file) if _safe_getitem(self._method_specs, 'mediaUpload', 'protocols', 'resumable') else None
# Create MediaUpload object and pass it the resumable object we just created
simple_upload_path = _safe_getitem(self._method_specs, 'mediaUpload', 'protocols', 'simple', 'path') or ''
if simple_upload_path:
media_upload_url = self._root_url[:-1] + simple_upload_path
else:
media_upload_url = None
mime_range = _safe_getitem(self._method_specs, 'mediaUpload', 'accept')
multipart = self.mediaUpload['protocols']['simple'].get('multipart', False)
# Return
return MediaUpload(upload_file, upload_path=media_upload_url, mime_range=mime_range, multipart=multipart, resumable=resumable)
)
else None
)
# Create MediaUpload object and pass it the resumable object we just created
# simple_upload_path = _safe_getitem(self._method_specs, 'mediaUpload', 'protocols', 'simple', 'path')
# media_upload_url_base = self._root_url[:-1] + simple_upload_path
media_upload_url_base = self._root_url + "upload/" + self._service_path
media_upload_url = qualified_url.replace(self._base_url, media_upload_url_base)
max_size = self._convert_str_size_to_int(
_safe_getitem(self._method_specs, "mediaUpload", "maxSize")
)
mime_range = _safe_getitem(self._method_specs, "mediaUpload", "accept")
multipart = self["mediaUpload"]["protocols"]["simple"].get("multipart", True)
return MediaUpload(
file_path=upload_file,
upload_path=media_upload_url,
max_size=max_size,
mime_range=mime_range,
multipart=multipart,
resumable=resumable,
validate=validate,
)
def _build_upload_media(self, upload_file, qualified_url, validate, fallback_url):
if self["supportsMediaUpload"] is not True:
if validate is True:
raise ValidationError(
"upload_file was provided while method doesn't support media upload"
)
else:
# This will probably not work, but will return a mediaupload object anyway
return MediaUpload(upload_file, upload_path=fallback_url)
# If resumable, create resumable object
resumable = (
self._build_resumeable_media(upload_file, qualified_url)
if _safe_getitem(
self._method_specs, "mediaUpload", "protocols", "resumable"
)
else None
)
# Create MediaUpload object and pass it the resumable object we just created
# simple_upload_path = _safe_getitem(self._method_specs, 'mediaUpload', 'protocols', 'simple', 'path')
# media_upload_url_base = self._root_url[:-1] + simple_upload_path
media_upload_url_base = self._root_url + "upload/" + self._service_path
media_upload_url = qualified_url.replace(self._base_url, media_upload_url_base)
max_size = self._convert_str_size_to_int(