473,387 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

unit testing CGI scripts?

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
1 2040
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hugh Cowan | last post by:
Hello, I don't program full-time (anymore), but I do try and stay on-top of the latest technologies and like most are always trying to upgrade my skills and remain current (as much as is...
4
by: O. Zimmermann | last post by:
Hello, I am looking for a tool to process torough UNIT and COVERAGE testing over 60 and more functions of a "critical" embedded application written in C. I found IPL's Cantata++ but we don't...
14
by: | last post by:
Hi! I'm looking for unit-testing tools for .NET. Somthing like Java has --> http://www.junit.org regards, gicio
3
by: | last post by:
I am working on a web/webservice application that has a service layer. Most service methods will perform an access-check before executing. This check uses the IPrincipal credentials available in...
4
by: Peter Rilling | last post by:
Does VS.NET 2005 Professional support integrated unit testing, or is that only with the team system?
3
by: Water Cooler v2 | last post by:
Here's my understanding as of now. If I were writing a function bool IsValidContact(Offerer objOfferer, Accepter objAccepter, TermsAndConditions objTermsAndConditions); Before writing the...
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
25
by: acemtp | last post by:
Hello, I would like to show you a new collaborative website for javascript programmer. It's quite hard to know if some specific code you wrote will work on all browsers, and if not, why it...
0
by: Bryan Berry | last post by:
I manage a team of 5 linux sysadmins and I am trying to transition us from lengthy, mostly unreadable shell scripts to python scripting. After a few tutorials, I have been infected with the unit...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.