[TIP] HTTP servers testing

Kumar McMillan kumar.mcmillan at gmail.com
Wed Feb 28 12:42:02 PST 2007


it's still a limited use case (I'm testing that single, static
responses get extracted properly from a service).  I imagine that
installing an app would be a similar decorator tho, like:

@service.intercepted_by(my_wsgi_app)
def test_get_something_from_service():
    pass

I'll keep playing with it and see if it turns into something useful.
the enable/disable thing is confusing but it's the only way I can
figure out how to turn it into the real, non-intercepted staging
service (for a buildbot test) without putting a stupid if statement in
front of the decorator :D

On 2/28/07, Titus Brown <titus at caltech.edu> wrote:
> ok, that's seriously neat.
>
> On Wed, Feb 28, 2007 at 02:15:00PM -0600, Kumar McMillan wrote:
> -> I just wrote titus off the list saying how psyched I am with
> -> wsgi_intercept (after his champion presentation) but, heck, let me
> -> just share with everyone this little adapter I am currently using on
> -> top of wsgi_intercept.  It was a shot in the dark but already seems to
> -> at least conceal the details of installing a wsgi fixture, maybe not
> -> an actual "standard"
> ->
> -> In this example I'm using it in a test that needs a stub response sent
> -> back from a rest service:
> ->
> ->
> -> service = WSGIIntercept(install_for=['urllib2'])
> ->
> -> def setup():
> ->     # set it to staging...
> ->     service.host = '192.168.x.x'
> ->     service.port = 8990
> ->     service.uri = "/theservice"
> ->     # here, an environ var will be checked
> ->     # to see if we want to be in "stub" mode.
> ->     # if so:
> ->     service.enable = True # now it will intercept
> ->
> -> @service.sends_response("<pretend>this is xml</pretend>")
> -> def test_transfer()
> ->     cmd = run_cmd(['--url', service.mkurl()])
> ->     # etc...
> ->
> ->
> ->
> -> ... the decorator does all the urllib2 installation and temporarily
> -> intercepts only while this test is running.
> ->
> ->
> -> > Or, as I now explain it, "wsgi_intercept lets Python Web testing
> -> > packages talk directly to a WSGI app without running a server"...
> -> >
> -> > I'll post some examples soon.
> -> >
> -> > I think it would be nice to build a "Web fixtures" package (perhaps
> -> > divorced from twill?) that would set up and run servers in a "standard"
> -> > way.  Then we could try to contribute this back to the individual
> -> > projects & hope for incorporation.
> -> >
> -> > Standardizing fixtures == good, right??
> -> >
> -> > --titus
> -> >
> -> > _______________________________________________
> -> > testing-in-python mailing list
> -> > testing-in-python at lists.idyll.org
> -> > http://lists.idyll.org/listinfo/testing-in-python
> -> >
> ->
> -> _______________________________________________
> -> testing-in-python mailing list
> -> testing-in-python at lists.idyll.org
> -> http://lists.idyll.org/listinfo/testing-in-python
>



More information about the testing-in-python mailing list