Need to testcase a complex webapp which does some interacting with a remote 3rd party cgi based webservices. Iam planing to implement some of the 3rd party services in a dummy webserver, so that i have full controll about the testcases. Looking for a simple python http webserver or framework to emulate the 3rd party interface.
+2
A:
Take a look the standard module wsgiref:
http://www.python.org/doc/2.6/library/wsgiref.html
At the end of that page is a small example. Something like this could already be sufficient for your needs.
ashcatch
2009-04-22 10:50:53
+1: I agree that included wsgiref server is probably enough for his needs.
nosklo
2009-04-22 12:22:18
+3
A:
Use cherrypy, take a look at Hello World:
import cherrypy
class HelloWorld(object):
def index(self):
return "Hello World!"
index.exposed = True
cherrypy.quickstart(HelloWorld())
Run this code and you have a very fast Hello World server ready on localhost
port 8080
!! Pretty easy huh?
nosklo
2009-04-22 12:06:00
A:
It might be simpler sense to mock (or stub, or whatever the term is) urllib, or whatever module you are using to communicate with the remote web-service?
Even simply overriding urllib.urlopen
might be enough:
import urllib
from StringIO import StringIO
class mock_response(StringIO):
def info(self):
raise NotImplementedError("mocked urllib response has no info method")
def getinfo():
raise NotImplementedError("mocked urllib response has no getinfo method")
def urlopen(url):
if url == "http://example.com/api/something":
resp = mock_response("<xml></xml>")
return resp
else:
urllib.urlopen(url)
is_unittest = True
if is_unittest:
urllib.urlopen = urlopen
print urllib.urlopen("http://example.com/api/something").read()
I used something very similar here, to emulate a simple API, before I got an API key.
dbr
2009-04-27 16:52:21