zope.testbrowser, how to?
Hi friends, I want use zope.testbrowser for testing my sites, but before write it as DocTest I want execute each statemnt interactively in python shell. I don't know any way to see where it's works, what value it returns, what error I can get and how this error should looks is python... It's why I want check it in python shell. What the problem? First, if execute following code in python shell:
from zope.testbrowser import Browser browser = Browser() browser.open('http://localhost/Plone')
I have got: Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/site-packages/zope/testbrowser/browser.py", line 220, in open self.mech_browser.open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 254, in open return self._mech_open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 277, in _mech_open self._response = UserAgent.open(self, self.request, data) File "/usr/lib/python2.4/urllib2.py", line 358, in open response = self._open(req, data) File "/usr/lib/python2.4/urllib2.py", line 376, in _open '_open', req) File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/usr/lib/python2.4/site-packages/zope/testbrowser/testing.py", line 112, in http_open return self.do_open(PublisherConnection, req) File "/usr/lib/python2.4/urllib2.py", line 993, in do_open h.request(req.get_method(), req.get_selector(), req.data, headers) File "/usr/lib/python2.4/site-packages/zope/testbrowser/testing.py", line 69, in request self.response = self.caller(request_string, handle_errors) File "/usr/lib/python2.4/site-packages/zope/app/testing/functional.py", line 573, in __call__ environment) File "/usr/lib/python2.4/site-packages/zope/app/testing/functional.py", line 606, in chooseRequestClass return chooseClasses(method, environment) File "/usr/lib/python2.4/site-packages/zope/app/publication/httpfactory.py", line 33, in chooseClasses factory = factoryRegistry.lookup(method, content_type, environment) File "/usr/lib/python2.4/site-packages/zope/app/publication/requestpublicationregistry.py", line 97, in lookup raise ConfigurationError('No registered publisher found ' zope.configuration.exceptions.ConfigurationError: No registered publisher found for (GET/) Second, if I add Zope src dir into PYTHONPATH, than I got following:
from zope.testbrowser import Browser Running tests at level 1 Total: 0 tests, 0 failures, 0 errors
and than it drops me out from python shell. So, question is: suppose I don't know what value/error I can/should recive after each statement, so how can I write DocTest? I need somehow to know to what I should expect, but how? Thanks for any advices! PS. Sorry for my bad english
Basil Shubin wrote:
Hi friends,
I want use zope.testbrowser for testing my sites, but before write it as DocTest I want execute each statemnt interactively in python shell. I don't know any way to see where it's works, what value it returns, what error I can get and how this error should looks is python... It's why I want check it in python shell.
What the problem?
First, if execute following code in python shell:
from zope.testbrowser import Browser browser = Browser() browser.open('http://localhost/Plone')
I have got:
Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/site-packages/zope/testbrowser/browser.py", line 220, in open self.mech_browser.open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 254, in open return self._mech_open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 277, in _mech_open self._response = UserAgent.open(self, self.request, data) File "/usr/lib/python2.4/urllib2.py", line 358, in open response = self._open(req, data) File "/usr/lib/python2.4/urllib2.py", line 376, in _open '_open', req) File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/usr/lib/python2.4/site-packages/zope/testbrowser/testing.py", line 112, in http_open return self.do_open(PublisherConnection, req) File "/usr/lib/python2.4/urllib2.py", line 993, in do_open h.request(req.get_method(), req.get_selector(), req.data, headers) File "/usr/lib/python2.4/site-packages/zope/testbrowser/testing.py", line 69, in request self.response = self.caller(request_string, handle_errors) File "/usr/lib/python2.4/site-packages/zope/app/testing/functional.py", line 573, in __call__ environment) File "/usr/lib/python2.4/site-packages/zope/app/testing/functional.py", line 606, in chooseRequestClass return chooseClasses(method, environment) File "/usr/lib/python2.4/site-packages/zope/app/publication/httpfactory.py", line 33, in chooseClasses factory = factoryRegistry.lookup(method, content_type, environment) File "/usr/lib/python2.4/site-packages/zope/app/publication/requestpublicationregistry.py", line 97, in lookup raise ConfigurationError('No registered publisher found ' zope.configuration.exceptions.ConfigurationError: No registered publisher found for (GET/)
Second, if I add Zope src dir into PYTHONPATH, than I got following:
from zope.testbrowser import Browser Running tests at level 1 Total: 0 tests, 0 failures, 0 errors
and than it drops me out from python shell.
So, question is: suppose I don't know what value/error I can/should recive after each statement, so how can I write DocTest? I need somehow to know to what I should expect, but how?
So is there any solution? Can anybody give me any guidlines about what is correct way to write functional test and test this test. Yes, I have read docs about testing Plone, but above problems still remain unsolved for me... And how I can predict what should happens after each statement...? Thanks!
Hmm... strange thing... With this code I got:
browser = Browser('http://localhost:8080/') browser.addHeader('Authorization', 'Basic admin:admin') browser.open('http://localhost:8080/manage') Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/site-packages/zope/testbrowser/browser.py", line 220, in open self.mech_browser.open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 254, in open return self._mech_open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 277, in _mech_open self._response = UserAgent.open(self, self.request, data) File "/usr/lib/python2.4/urllib2.py", line 364, in open response = meth(req, response) File "/usr/lib/python2.4/urllib2.py", line 471, in http_response response = self.parent.error( File "/usr/lib/python2.4/urllib2.py", line 402, in error return self._call_chain(*args) File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/usr/lib/python2.4/urllib2.py", line 480, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 500: Internal Server Error
than with this:
browser = Browser('http://localhost:8080/manage') Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/site-packages/zope/testbrowser/browser.py", line 162, in __init__ self.open(url) File "/usr/lib/python2.4/site-packages/zope/testbrowser/browser.py", line 220, in open self.mech_browser.open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 254, in open return self._mech_open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 277, in _mech_open self._response = UserAgent.open(self, self.request, data) File "/usr/lib/python2.4/urllib2.py", line 364, in open response = meth(req, response) File "/usr/lib/python2.4/urllib2.py", line 471, in http_response response = self.parent.error( File "/usr/lib/python2.4/urllib2.py", line 402, in error return self._call_chain(*args) File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/usr/lib/python2.4/urllib2.py", line 480, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 401: Unauthorized
and after all:
browser = Browser() browser.addHeader('Authorization', 'Basic admin:admin') browser.open('http://localhost:8080/manage') Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/site-packages/zope/testbrowser/browser.py", line 220, in open self.mech_browser.open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 254, in open return self._mech_open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 277, in _mech_open self._response = UserAgent.open(self, self.request, data) File "/usr/lib/python2.4/urllib2.py", line 364, in open response = meth(req, response) File "/usr/lib/python2.4/urllib2.py", line 471, in http_response response = self.parent.error( File "/usr/lib/python2.4/urllib2.py", line 402, in error return self._call_chain(*args) File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/usr/lib/python2.4/urllib2.py", line 480, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 500: Internal Server Error
Is there any way to get access to http://<site>/manage page with zope.testbrowser? Thanks!
You might try the zope3-users mailing list. -aj --On 28. Februar 2007 18:17:23 +0600 Basil Shubin <basil.shubin@gmail.com> wrote:
Hmm... strange thing...
With this code I got:
browser = Browser('http://localhost:8080/') browser.addHeader('Authorization', 'Basic admin:admin') browser.open('http://localhost:8080/manage') Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/site-packages/zope/testbrowser/browser.py", line 220, in open self.mech_browser.open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 254, in open return self._mech_open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 277, in _mech_open self._response = UserAgent.open(self, self.request, data) File "/usr/lib/python2.4/urllib2.py", line 364, in open response = meth(req, response) File "/usr/lib/python2.4/urllib2.py", line 471, in http_response response = self.parent.error( File "/usr/lib/python2.4/urllib2.py", line 402, in error return self._call_chain(*args) File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/usr/lib/python2.4/urllib2.py", line 480, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 500: Internal Server Error
than with this:
browser = Browser('http://localhost:8080/manage') Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/site-packages/zope/testbrowser/browser.py", line 162, in __init__ self.open(url) File "/usr/lib/python2.4/site-packages/zope/testbrowser/browser.py", line 220, in open self.mech_browser.open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 254, in open return self._mech_open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 277, in _mech_open self._response = UserAgent.open(self, self.request, data) File "/usr/lib/python2.4/urllib2.py", line 364, in open response = meth(req, response) File "/usr/lib/python2.4/urllib2.py", line 471, in http_response response = self.parent.error( File "/usr/lib/python2.4/urllib2.py", line 402, in error return self._call_chain(*args) File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/usr/lib/python2.4/urllib2.py", line 480, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 401: Unauthorized
and after all:
browser = Browser() browser.addHeader('Authorization', 'Basic admin:admin') browser.open('http://localhost:8080/manage') Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/site-packages/zope/testbrowser/browser.py", line 220, in open self.mech_browser.open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 254, in open return self._mech_open(url, data) File "/usr/lib/python2.4/site-packages/mechanize/_mechanize.py", line 277, in _mech_open self._response = UserAgent.open(self, self.request, data) File "/usr/lib/python2.4/urllib2.py", line 364, in open response = meth(req, response) File "/usr/lib/python2.4/urllib2.py", line 471, in http_response response = self.parent.error( File "/usr/lib/python2.4/urllib2.py", line 402, in error return self._call_chain(*args) File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain result = func(*args) File "/usr/lib/python2.4/urllib2.py", line 480, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 500: Internal Server Error
Is there any way to get access to http://<site>/manage page with zope.testbrowser?
Thanks!
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany Web: www.zopyx.com - Email: info@zopyx.com - Phone +49 - 7071 - 793376 Registergericht: Amtsgericht Stuttgart, Handelsregister A 381535 Geschäftsführer/Gesellschafter: ZOPYX Limited, Birmingham, UK ------------------------------------------------------------------------ E-Publishing, Python, Zope & Plone development, Consulting
Basil Shubin wrote:
Hi friends,
I want use zope.testbrowser for testing my sites, but before write it as DocTest I want execute each statemnt interactively in python shell. I don't know any way to see where it's works, what value it returns, what error I can get and how this error should looks is python... It's why I want check it in python shell.
What the problem?
First, if execute following code in python shell:
from zope.testbrowser import Browser browser = Browser() browser.open('http://localhost/Plone')
but if I have use this instead above code:
from zope.testbrowser.browser import Browser browser = Browser('http://localhost:8080/Plone')
everything works!
Basil Shubin wrote:
Basil Shubin wrote:
Hi friends,
I want use zope.testbrowser for testing my sites, but before write it as DocTest I want execute each statemnt interactively in python shell. I don't know any way to see where it's works, what value it returns, what error I can get and how this error should looks is python... It's why I want check it in python shell.
What the problem?
First, if execute following code in python shell:
from zope.testbrowser import Browser browser = Browser() browser.open('http://localhost/Plone')
but if I have use this instead above code:
from zope.testbrowser.browser import Browser browser = Browser('http://localhost:8080/Plone')
everything works!
That's because zope.testbrowser.browser.Browser opens real HTTP connections. zope.testbrowser.Browser uses Zope 3's functional test framework. If you want to use the test browser for functional tests in Zope 2, use Products.Five.testbrowser.Browser. -- http://worldcookery.com -- Professional Zope documentation and training Next Zope 3 training at Camp5: http://trizpug.org/boot-camp/camp5
participants (3)
-
Andreas Jung -
Basil Shubin -
Philipp von Weitershausen