brain cramp: emulating cgi.FieldStorage

Mike Meyer mwm at mired.org
Thu Sep 15 20:23:59 EDT 2005


"Chris Curvey" <ccurvey at gmail.com> writes:

> I can't be the first person to want to do this, but I also can't seem
> to find a solution.  (Perhaps my Google skills are poor today.)  How
> can I emulate cgi.FieldStorage() for my unit tests so that I don't have
> to put a web server in the way?
>
> what I'd like to do is something like
>
> fs = cgi.FieldStorage()
> fs["foo"] = "bar"
> functionToBeTested(fs)
>
> Any hints/leads/suggestions?

QUERY_STRING="var1=val1&var2=val2&var3=val3" REQUEST_METHOD="GET" python mycgiprogram.py

Similar hacks work for POST if you want to store a test query in a
file.

	<mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list