I'm relatively new to Pyramid, so I'm struggling with writing tests for my picture upload form.
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)
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)