By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,359 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

unit testing CGI scripts?

P: n/a
Hello,

Does anyone have suggestions for unit testing CGI scripts? For
instance, how can I set the FieldStorage to have certain values?
Do I have to go with a dummy FieldStorage class? And is there a
better way to check the output than to compare the resulting (sometimes
very large) strings? Changing the HTML slightly means that I have to
edit the tests and that defeats the purpose of the tests, to
some extent. I'd greatly appreciate any tips.

Thanks,
Jim
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
> Does anyone have suggestions for unit testing CGI scripts? For
instance, how can I set the FieldStorage to have certain values?
Do I have to go with a dummy FieldStorage class? And is there a


I use 2 fairly simple and naive techniques within CGI scripts
(not proper unittests, I'll be the first to admit, but perhaps you can
work them into proper unittests):

From scratch:

testing = 1
if testing :
year = "2003"
week = "13"
else :
form = cgi.FieldStorage()
year = form["year"].value
week = form["week"].value

or sometimes, when retrofitting testing:

testing = 1
if testing :
class fakefield:
def __init__(self, startingvalue):
self.value = startingvalue
yr = fakefield("2001")
wk = fakefield("13")
form = {"year":yr, "week":wk}
else:
form = cgi.FieldStorage()

# the existing code
year = form["year"].value
week = form["week"].value

All final scripts are wrapped in a try/except structure that
automatically sends me an email if an uncaught exception occurs.
Python is just so tasty for quick meals.

Regards, Myles.
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.