All,

I am trying to unittest a GET request, I have had no problem testing all my 
other functions which were POST requests.

I have a simple function, that takes two vars; a file name and a path and 
then downloads the file.

def file_downloader():
    if request.vars:
        filename = request.vars.filename
        path_to_file = request.vars.path_to_file


        response.headers['ContentType'] = "application/octet-stream"
        response.headers['Content-Disposition'] = "attachment; filename=" + 
filename


        try:
            return response.stream(open(path_to_file, 'rb'), chunk_size=10**
6)
        except:
            response.flash = 'An error occurred, please try to download the 
file again'
            pass


The unittest code shown below is a snippet of the request for the test case 
for the download function:

        
        current.request.function = "file_downloader"

        current.request["args"] = List([])
        current.request["_post_vars"] = Storage({})
        current.request["_vars"] = Storage(_file_downloader_vars)
        current.request["_get_vars"] = Storage(_file_downloader_vars)
        current.request.env.request_method = "GET"


        resp_downloader = file_downloader()

Any help on this would be great.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to