[Twisted-Python] Problem with unittesting HTTP POST resource
teemu.harju at gmail.com
Tue Apr 8 07:28:45 EDT 2008
I'm kind of a newbie in what comes to using Twisted and I'm stuck with a
problem that I cannot seem to solve.
My problem is that I'm experimenting with "trial" to be able to test my
code. (I've heard that it is a wise thing to do ;-)). What I have is a
simple HTTP resource that allows POSTing data. I made this example to
illustrate my problem...
from twisted.internet import reactor
from twisted.web import resource, server, client, error
from twisted.trial import unittest
def render_POST(self, request):
def _listen(self, site):
return reactor.listenTCP(0, site, interface="127.0.0.1")
r = resource.Resource()
site = server.Site(r, timeout=None)
self.port = self._listen(site)
self.portno = self.port.getHost().port
def getURL(self, path):
return "http://127.0.0.1:%d/%s" % (self.portno, path)
d = client.getPage(self.getURL("test"), method="POST",
I used some of the unittests in Twisted Web as an example and at least I
think I've got this right. However, as you can see if you run this, the test
fails. Which means that the request.args dictionary is empty. However, there
should be something since I've set the postdata parameter on the
client.getPage() method. I would really appreciate all the help here since I
cannot figure out where the postdata disappears.
email/jabber: teemu.harju at gmail.com
~~ "A computer is like air conditioning: it becomes useless when you open
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python