How to use request_for_upload method in Kiwi

Best Python code snippet using Kiwi_python

utils.py

Source:utils.py Github

copy

Full Screen

...42 data.append(f"Content-Length: {len(b64content)}\r\n")43 data.append(b64content)44 data.append(f"--{boundary}--\r\n")45 return "\r\n".join(data), boundary46def request_for_upload(user, filename, b64content):47 """48 Return a request object containing all fields necessary for file49 upload as if it was sent by the browser.50 """51 request = HttpRequest()52 request.user = user53 request.method = "POST"54 request.content_type = "multipart/form-data"55 # because attachment.views.add_attachment() calls messages.success()56 request._messages = MagicMock() # pylint: disable=protected-access57 data, boundary = encode_multipart(get_token(request), filename, b64content)58 request.META["CONTENT_TYPE"] = f"multipart/form-data; boundary={boundary}"59 request.META["CONTENT_LENGTH"] = len(data)60 request._stream = io.BytesIO(data.encode()) # pylint: disable=protected-access61 # manually parse the input data and populate data attributes62 request._read_started = False # pylint: disable=protected-access63 request._load_post_and_files() # pylint: disable=protected-access64 request.POST = request._post # pylint: disable=protected-access65 request.FILES = request._files # pylint: disable=protected-access66 return request67def add_attachment(obj_id, app_model, user, filename, b64content):68 """69 High-level function which performs the attachment process70 by constructing an HttpRequest object and passing it to71 attachments.views.add_attachment() as if it came from the browser.72 """73 request = request_for_upload(user, filename, b64content)74 app, model = app_model.split(".")75 response = attachment_views.add_attachment(request, app, model, obj_id)76 if response.status_code == 404:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kiwi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful