Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Creating TestUnits for file upload form
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bojan MIletic  
View profile  
 More options Jun 19 2012, 8:29 am
From: Bojan MIletic <boyan.mile...@gmail.com>
Date: Tue, 19 Jun 2012 05:29:19 -0700 (PDT)
Local: Tues, Jun 19 2012 8:29 am
Subject: Creating TestUnits for file upload form

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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »