Hello

I'm relatively new to Pyramid, so I'm struggling with writing tests for my 
picture upload form. 
How can I add picture to the dummy request?

Here is the function I would like to test.

@view_config(route_name='profile_pic')
def profilePictureUpload(request):
if 'form.submitted' in request.params:
log.info("recieved picture upload request")
form = Form(request, schema=PictureUpload)

if request.method == 'POST' and form.validate():
#TODO replace hardcoded value with value from config
 upload_directory = 'PATH'

upload = request.POST.get('profile')
image_type = imghdr.what(upload.filename, upload.value)
log.info(image_type)
saved_file = str(upload_directory) + str(upload.filename)

perm_file = open(saved_file, 'wb')
shutil.copyfileobj(upload.file, perm_file)
upload.file.close()
perm_file.close()
else:
print form.errors
redirect_url = route_url('profile', request)
return HTTPFound(location=redirect_url)

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-devel" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/pylons-devel/-/G-k2yZmggf8J.
To post to this group, send email to pylons-devel@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-devel?hl=en.

Reply via email to