Christian Scholz
2008-07-01 17:37:57 UTC
Hi!
I was just discussing this with Locklainn on IRC but I thought I might
also post it here.
When I was creating my unit test I was wondering why it did not read the
seed cap correctly. What I (and the original script) was using was:
class RedirectHandler(urllib2.HTTPRedirectHandler):
def http_error_302(self, req, fp, code, msg, headers):
#ignore the redirect, grabbing the seed cap url from the headers
# TODO: add logging and error handling
return headers['location']
AgentDomainLoginOpener = urllib2.build_opener(RedirectHandler())
seed_cap_url = AgentDomainLoginOpener.open(request)
This means that the result of the open() call is supposed to be a string
(the seed cap URL). In fact the urllib2 documentation says differently.
It is supposed to be a file like object so that retrieving the contents
should be more like
seed_cap_url = AgentDomainLoginOpener.open(request).read()
When writing my test this indeed was the case and the test broke because
of that.
Now the answer to that is that the http_error_302() method is not
implemented as it should be as it's not following the actual redirect.
In fact it receives the Redirect and returns the Location: header as
string. This is what comes out of the open() method.
Now it seems that this is not the way as described in the specification
as it should do no redirect but instead return something like
{'agent_seed_capability':'http://.....'}
in LLSD.
In fact it could do a redirect but it should still deliver this I think.
So I am just wondering if this is intentional or maybe changing at some
point. I would like to write the test according to the specification of
course (test harness should be like that anyway).
If this is fixed the actual redirect should look like this:
def http_error_302(self, req, fp, code, msg, headers):
result = urllib2.HTTPRedirectHandler.http_error_302(
self, req, fp, code, msg, headers)
result.status = code
return result
So it's just delegating it and returning a new request I think.
Thanks for any enlightenment :-)
Beside that I now moved the test agent domain to bin/ and to run a test
you now can do
bin/testserver &
bin/test
the latter then looks for all tests and runs them. All dummy AD and RD
stuff could then go into testserver and might even be run automatically
from the test script in a thread or so.
-- Tao / Christian
I was just discussing this with Locklainn on IRC but I thought I might
also post it here.
When I was creating my unit test I was wondering why it did not read the
seed cap correctly. What I (and the original script) was using was:
class RedirectHandler(urllib2.HTTPRedirectHandler):
def http_error_302(self, req, fp, code, msg, headers):
#ignore the redirect, grabbing the seed cap url from the headers
# TODO: add logging and error handling
return headers['location']
AgentDomainLoginOpener = urllib2.build_opener(RedirectHandler())
seed_cap_url = AgentDomainLoginOpener.open(request)
This means that the result of the open() call is supposed to be a string
(the seed cap URL). In fact the urllib2 documentation says differently.
It is supposed to be a file like object so that retrieving the contents
should be more like
seed_cap_url = AgentDomainLoginOpener.open(request).read()
When writing my test this indeed was the case and the test broke because
of that.
Now the answer to that is that the http_error_302() method is not
implemented as it should be as it's not following the actual redirect.
In fact it receives the Redirect and returns the Location: header as
string. This is what comes out of the open() method.
Now it seems that this is not the way as described in the specification
as it should do no redirect but instead return something like
{'agent_seed_capability':'http://.....'}
in LLSD.
In fact it could do a redirect but it should still deliver this I think.
So I am just wondering if this is intentional or maybe changing at some
point. I would like to write the test according to the specification of
course (test harness should be like that anyway).
If this is fixed the actual redirect should look like this:
def http_error_302(self, req, fp, code, msg, headers):
result = urllib2.HTTPRedirectHandler.http_error_302(
self, req, fp, code, msg, headers)
result.status = code
return result
So it's just delegating it and returning a new request I think.
Thanks for any enlightenment :-)
Beside that I now moved the test agent domain to bin/ and to run a test
you now can do
bin/testserver &
bin/test
the latter then looks for all tests and runs them. All dummy AD and RD
stuff could then go into testserver and might even be run automatically
from the test script in a thread or so.
-- Tao / Christian
--
Christian Scholz video blog: http://comlounge.tv
COM.lounge blog: http://mrtopf.de/blog
Luetticher Strasse 10 Skype: HerrTopf
52064 Aachen Homepage: http://comlounge.net
Tel: +49 241 400 730 0 E-Mail ***@comlounge.net
Fax: +49 241 979 00 850 IRC: MrTopf, Tao_T
neue Show: TOPFt?glich (http://mrtopf.de/blog/category/topf-taglich/)
Christian Scholz video blog: http://comlounge.tv
COM.lounge blog: http://mrtopf.de/blog
Luetticher Strasse 10 Skype: HerrTopf
52064 Aachen Homepage: http://comlounge.net
Tel: +49 241 400 730 0 E-Mail ***@comlounge.net
Fax: +49 241 979 00 850 IRC: MrTopf, Tao_T
neue Show: TOPFt?glich (http://mrtopf.de/blog/category/topf-taglich/)