|
|
|
|
|
|
| Author |
Message |
Mike Meyer *nix forums Guru
Joined: 21 Feb 2005
Posts: 1044
|
Posted: Thu Sep 15, 2005 10:23 pm Post subject:
Re: brain cramp: emulating cgi.FieldStorage
|
|
|
"Chris Curvey" <ccurvey@gmail.com> writes:
| Quote: | 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@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. |
|
| Back to top |
|
 |
Max M *nix forums addict
Joined: 22 Feb 2005
Posts: 82
|
Posted: Thu Sep 15, 2005 1:07 pm Post subject:
Re: brain cramp: emulating cgi.FieldStorage
|
|
|
Chris Curvey wrote:
| Quote: | 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?
|
Can't you just pass the FieldStorage some dummy data to parse?
It looks pretty simple.
class FieldStorage:
def __init__(self, fp=None, headers=None, outerboundary="",
environ=os.environ, keep_blank_values=0,
strict_parsing=0):
"""Constructor. Read multipart/* until last part.
Arguments, all optional:
fp : file pointer; default: sys.stdin
(not used when the request method is GET)
headers : header dictionary-like object; default:
taken from environ as per CGI spec
outerboundary : terminating multipart boundary
(for internal use only)
environ : environment dictionary; default: os.environ
keep_blank_values: flag indicating whether blank values in
URL encoded forms should be treated as blank strings.
A true value indicates that blanks should be retained as
blank strings. The default false value indicates that
blank values are to be ignored and treated as if they were
not included.
strict_parsing: flag indicating what to do with parsing errors.
If false (the default), errors are silently ignored.
If true, errors raise a ValueError exception.
"""
--
hilsen/regards Max M, Denmark
http://www.mxm.dk/
IT's Mad Science |
|
| Back to top |
|
 |
Chris Curvey *nix forums addict
Joined: 02 May 2005
Posts: 50
|
Posted: Thu Sep 15, 2005 1:04 pm Post subject:
Re: brain cramp: emulating cgi.FieldStorage
|
|
|
figured it out...
os.environ["QUERY_STRING"] = "foo=bar"
fs = cgi.FieldStorage()
functionToBeTested(fs) |
|
| Back to top |
|
 |
Chris Curvey *nix forums addict
Joined: 02 May 2005
Posts: 50
|
Posted: Thu Sep 15, 2005 12:11 pm Post subject:
brain cramp: emulating cgi.FieldStorage
|
|
|
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? |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Thu Jan 08, 2009 5:57 am | All times are GMT
|
|
Personal Car Finance | Satellite TV | Cheap Magazines | Bankruptcy | Magazine Subscriptions
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|