diff options
| author | Chris McDonough <chrism@plope.com> | 2010-11-17 18:11:48 -0500 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2010-11-17 18:11:48 -0500 |
| commit | dbaa08e18d1bf50264faabb6e7dfce12f2c0ea71 (patch) | |
| tree | b3a0f56135488cdd5183433a53b191e43f4823c3 | |
| parent | ab1b77143424c73bf126126d1bc5ceecdbf05ddb (diff) | |
| download | pyramid-dbaa08e18d1bf50264faabb6e7dfce12f2c0ea71.tar.gz pyramid-dbaa08e18d1bf50264faabb6e7dfce12f2c0ea71.tar.bz2 pyramid-dbaa08e18d1bf50264faabb6e7dfce12f2c0ea71.zip | |
- Replace Twill with WebTest in internal integration tests (avoid deprecation
warnings generated by Twill).
| -rw-r--r-- | CHANGES.txt | 6 | ||||
| -rw-r--r-- | TODO.txt | 3 | ||||
| -rw-r--r-- | pyramid/tests/test_integration.py | 321 | ||||
| -rw-r--r-- | setup.py | 4 |
4 files changed, 174 insertions, 160 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 7f1390186..fd0cead61 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -35,6 +35,12 @@ Documentation have a SessionFactory abstraction which competes with it, and maintaining documentation on both ways to do it is a distraction. +Internal +-------- + +- Replace Twill with WebTest in internal integration tests (avoid deprecation + warnings generated by Twill). + 1.0a3 (2010-11-16) ================== @@ -115,8 +115,5 @@ Configurator.add_translation_dirs: not passed any context but a message, can't credibly be removed. -- Stop using Twill in integration tests (too much of a pain in the ass to - make work without deprecation warnings). - - Use ``@register_view`` instead of ``@view_config`` and change view docs to use "view registration" instead of "view configuration". diff --git a/pyramid/tests/test_integration.py b/pyramid/tests/test_integration.py index bc9d75d33..a502c2ff6 100644 --- a/pyramid/tests/test_integration.py +++ b/pyramid/tests/test_integration.py @@ -65,197 +65,208 @@ class TestStaticApp(unittest.TestCase): result.body, open(os.path.join(here, 'fixtures/minimal.pt'), 'r').read()) -class TwillBase(unittest.TestCase): +class IntegrationBase(unittest.TestCase): root_factory = None + ## def setUp(self): + ## import sys + ## import twill + ## from twill.commands import config as twillconfig + ## # for benefit of Jython, which cannot import the subprocess module, we + ## # configure twill to not use tidy + ## twillconfig('use_tidy', False) + ## twillconfig('require_tidy', False) + ## from pyramid.configuration import Configurator + ## config = Configurator(root_factory=self.root_factory) + ## config.load_zcml(self.config) + ## twill.add_wsgi_intercept('localhost', 6543, config.make_wsgi_app) + ## if sys.platform is 'win32': # pragma: no cover + ## out = open('nul:', 'wb') + ## else: + ## out = open('/dev/null', 'wb') + ## twill.set_output(out) + ## self.config = testing.setUp(registry=config.registry) + + ## def tearDown(self): + ## import twill + ## import twill.commands + ## twill.commands.reset_browser() + ## twill.remove_wsgi_intercept('localhost', 6543) + ## twill.set_output(None) + ## testing.tearDown() + def setUp(self): - import sys - import twill - from twill.commands import config as twillconfig - # for benefit of Jython, which cannot import the subprocess module, we - # configure twill to not use tidy - twillconfig('use_tidy', False) - twillconfig('require_tidy', False) from pyramid.configuration import Configurator config = Configurator(root_factory=self.root_factory) + config.begin() config.load_zcml(self.config) - twill.add_wsgi_intercept('localhost', 6543, config.make_wsgi_app) - if sys.platform is 'win32': # pragma: no cover - out = open('nul:', 'wb') - else: - out = open('/dev/null', 'wb') - twill.set_output(out) - self.config = testing.setUp(registry=config.registry) + app = config.make_wsgi_app() + from webtest import TestApp + self.testapp = TestApp(app) + self.config = config def tearDown(self): - import twill - import twill.commands - twill.commands.reset_browser() - twill.remove_wsgi_intercept('localhost', 6543) - twill.set_output(None) - testing.tearDown() - -class TestFixtureApp(TwillBase): + self.config.end() + +class TestFixtureApp(IntegrationBase): config = 'pyramid.tests.fixtureapp:configure.zcml' - def test_it(self): - import twill.commands - browser = twill.commands.get_browser() - browser.go('http://localhost:6543/another.html') - self.assertEqual(browser.get_code(), 200) - self.assertEqual(browser.get_html(), 'fixture') - browser.go('http://localhost:6543') - self.assertEqual(browser.get_code(), 200) - self.assertEqual(browser.get_html(), 'fixture') - browser.go('http://localhost:6543/dummyskin.html') - self.assertEqual(browser.get_code(), 404) - browser.go('http://localhost:6543/error.html') - self.assertEqual(browser.get_code(), 200) - self.assertEqual(browser.get_html(), 'supressed') - browser.go('http://localhost:6543/protected.html') - self.assertEqual(browser.get_code(), 401) - -class TestCCBug(TwillBase): + def test_another(self): + res = self.testapp.get('/another.html', status=200) + self.assertEqual(res.body, 'fixture') + + def test_root(self): + res = self.testapp.get('/', status=200) + self.assertEqual(res.body, 'fixture') + + def test_dummyskin(self): + self.testapp.get('/dummyskin.html', status=404) + + def test_error(self): + res = self.testapp.get('/error.html', status=200) + self.assertEqual(res.body, 'supressed') + + def test_protected(self): + self.testapp.get('/protected.html', status=401) + +class TestCCBug(IntegrationBase): # "unordered" as reported in IRC by author of # http://labs.creativecommons.org/2010/01/13/cc-engine-and-web-non-frameworks/ config = 'pyramid.tests.ccbugapp:configure.zcml' - def test_it(self): - import twill.commands - browser = twill.commands.get_browser() - browser.go('http://localhost:6543/licenses/1/v1/rdf') - self.assertEqual(browser.get_code(), 200) - self.assertEqual(browser.get_html(), 'rdf') - browser.go('http://localhost:6543/licenses/1/v1/juri') - self.assertEqual(browser.get_code(), 200) - self.assertEqual(browser.get_html(), 'juri') - -class TestHybridApp(TwillBase): + def test_rdf(self): + res = self.testapp.get('/licenses/1/v1/rdf', status=200) + self.assertEqual(res.body, 'rdf') + + def test_juri(self): + res = self.testapp.get('/licenses/1/v1/juri', status=200) + self.assertEqual(res.body, 'juri') + +class TestHybridApp(IntegrationBase): # make sure views registered for a route "win" over views registered # without one, even though the context of the non-route view may # be more specific than the route view. config = 'pyramid.tests.hybridapp:configure.zcml' - def test_it(self): - import twill.commands - browser = twill.commands.get_browser() - browser.go('http://localhost:6543/') - self.assertEqual(browser.get_code(), 200) - self.assertEqual(browser.get_html(), 'global') - browser.go('http://localhost:6543/abc') - self.assertEqual(browser.get_code(), 200) - self.assertEqual(browser.get_html(), 'route') - browser.go('http://localhost:6543/def') - self.assertEqual(browser.get_code(), 200) - self.assertEqual(browser.get_html(), 'route2') - browser.go('http://localhost:6543/ghi') - self.assertEqual(browser.get_code(), 200) - self.assertEqual(browser.get_html(), 'global') - browser.go('http://localhost:6543/jkl') - self.assertEqual(browser.get_code(), 404) - browser.go('http://localhost:6543/mno/global2') - self.assertEqual(browser.get_code(), 404) - browser.go('http://localhost:6543/pqr/global2') - self.assertEqual(browser.get_code(), 200) - self.assertEqual(browser.get_html(), 'global2') - browser.go('http://localhost:6543/error') - self.assertEqual(browser.get_code(), 200) - self.assertEqual(browser.get_html(), 'supressed') - browser.go('http://localhost:6543/error2') - self.assertEqual(browser.get_code(), 200) - self.assertEqual(browser.get_html(), 'supressed2') - browser.go('http://localhost:6543/error_sub') - self.assertEqual(browser.get_code(), 200) - self.assertEqual(browser.get_html(), 'supressed2') - -class TestRestBugApp(TwillBase): + def test_root(self): + res = self.testapp.get('/', status=200) + self.assertEqual(res.body, 'global') + + def test_abc(self): + res = self.testapp.get('/abc', status=200) + self.assertEqual(res.body, 'route') + + def test_def(self): + res = self.testapp.get('/def', status=200) + self.assertEqual(res.body, 'route2') + + def test_ghi(self): + res = self.testapp.get('/ghi', status=200) + self.assertEqual(res.body, 'global') + + def test_jkl(self): + self.testapp.get('/jkl', status=404) + + def test_mno(self): + self.testapp.get('/mno', status=404) + + def test_pqr_global2(self): + res = self.testapp.get('/pqr/global2', status=200) + self.assertEqual(res.body, 'global2') + + def test_error(self): + res = self.testapp.get('/error', status=200) + self.assertEqual(res.body, 'supressed') + + def test_error2(self): + res = self.testapp.get('/error2', status=200) + self.assertEqual(res.body, 'supressed2') + + def test_error_sub(self): + res = self.testapp.get('/error_sub', status=200) + self.assertEqual(res.body, 'supressed2') + +class TestRestBugApp(IntegrationBase): # test bug reported by delijati 2010/2/3 (http://pastebin.com/d4cc15515) config = 'pyramid.tests.restbugapp:configure.zcml' def test_it(self): - import twill.commands - browser = twill.commands.get_browser() - browser.go('http://localhost:6543/pet') - self.assertEqual(browser.get_code(), 200) - self.assertEqual(browser.get_html(), 'gotten') + res = self.testapp.get('/pet', status=200) + self.assertEqual(res.body, 'gotten') -class TestViewDecoratorApp(TwillBase): +class TestViewDecoratorApp(IntegrationBase): config = 'pyramid.tests.viewdecoratorapp:configure.zcml' - def test_it(self): - # we use mako here instead of chameleon because it works on Jython + def _configure_mako(self): tmpldir = os.path.join(os.path.dirname(__file__), 'viewdecoratorapp', 'views') self.config.registry.settings['mako.directories'] = tmpldir - import twill.commands - browser = twill.commands.get_browser() - browser.go('http://localhost:6543/first') - self.assertEqual(browser.get_code(), 200) - self.failUnless('OK' in browser.get_html()) - browser.go('http://localhost:6543/second') - self.assertEqual(browser.get_code(), 200) - self.failUnless('OK2' in browser.get_html()) + def test_first(self): + # we use mako here instead of chameleon because it works on Jython + self._configure_mako() + res = self.testapp.get('/first', status=200) + self.failUnless('OK' in res.body) + + def test_second(self): + # we use mako here instead of chameleon because it works on Jython + self._configure_mako() + res = self.testapp.get('/second', status=200) + self.failUnless('OK2' in res.body) -class TestViewPermissionBug(TwillBase): +class TestViewPermissionBug(IntegrationBase): # view_execution_permitted bug as reported by Shane at http://lists.repoze.org/pipermail/repoze-dev/2010-October/003603.html config = 'pyramid.tests.permbugapp:configure.zcml' - def test_it(self): - import twill.commands - browser = twill.commands.get_browser() - browser.go('http://localhost:6543/test') - self.assertEqual(browser.get_code(), 200) - self.failUnless('ACLDenied' in browser.get_html()) - browser.go('http://localhost:6543/x') - self.assertEqual(browser.get_code(), 401) - -class TestDefaultViewPermissionBug(TwillBase): + def test_test(self): + res = self.testapp.get('/test', status=200) + self.failUnless('ACLDenied' in res.body) + + def test_x(self): + self.testapp.get('/x', status=401) + +class TestDefaultViewPermissionBug(IntegrationBase): # default_view_permission bug as reported by Wiggy at http://lists.repoze.org/pipermail/repoze-dev/2010-October/003602.html config = 'pyramid.tests.defpermbugapp:configure.zcml' - def test_it(self): - import twill.commands - browser = twill.commands.get_browser() - browser.go('http://localhost:6543/x') - self.assertEqual(browser.get_code(), 401) - self.failUnless('failed permission check' in browser.get_html()) - browser.go('http://localhost:6543/y') - self.assertEqual(browser.get_code(), 401) - self.failUnless('failed permission check' in browser.get_html()) - browser.go('http://localhost:6543/z') - self.assertEqual(browser.get_code(), 200) - self.failUnless('public' in browser.get_html()) + def test_x(self): + res = self.testapp.get('/x', status=401) + self.failUnless('failed permission check' in res.body) + + def test_y(self): + res = self.testapp.get('/y', status=401) + self.failUnless('failed permission check' in res.body) + + def test_z(self): + res = self.testapp.get('/z', status=200) + self.failUnless('public' in res.body) from pyramid.tests.exceptionviewapp.models import AnException, NotAnException excroot = {'anexception':AnException(), 'notanexception':NotAnException()} -class TestExceptionViewsApp(TwillBase): +class TestExceptionViewsApp(IntegrationBase): config = 'pyramid.tests.exceptionviewapp:configure.zcml' root_factory = lambda *arg: excroot - def test_it(self): - import twill.commands - browser = twill.commands.get_browser() - browser.go('http://localhost:6543/') - self.assertEqual(browser.get_code(), 200) - self.failUnless('maybe' in browser.get_html()) - - browser.go('http://localhost:6543/notanexception') - self.assertEqual(browser.get_code(), 200) - self.failUnless('no' in browser.get_html()) - - browser.go('http://localhost:6543/anexception') - self.assertEqual(browser.get_code(), 200) - self.failUnless('yes' in browser.get_html()) - - browser.go('http://localhost:6543/route_raise_exception') - self.assertEqual(browser.get_code(), 200) - self.failUnless('yes' in browser.get_html()) - - browser.go('http://localhost:6543/route_raise_exception2') - self.assertEqual(browser.get_code(), 200) - self.failUnless('yes' in browser.get_html()) - - browser.go('http://localhost:6543/route_raise_exception3') - self.assertEqual(browser.get_code(), 200) - self.failUnless('whoa' in browser.get_html()) - - browser.go('http://localhost:6543/route_raise_exception4') - self.assertEqual(browser.get_code(), 200) - self.failUnless('whoa' in browser.get_html()) + def test_root(self): + res = self.testapp.get('/', status=200) + self.failUnless('maybe' in res.body) + + def test_notanexception(self): + res = self.testapp.get('/notanexception', status=200) + self.failUnless('no' in res.body) + + def test_anexception(self): + res = self.testapp.get('/anexception', status=200) + self.failUnless('yes' in res.body) + + def test_route_raise_exception(self): + res = self.testapp.get('/route_raise_exception', status=200) + self.failUnless('yes' in res.body) + + def test_route_raise_exception2(self): + res = self.testapp.get('/route_raise_exception2', status=200) + self.failUnless('yes' in res.body) + + def test_route_raise_exception3(self): + res = self.testapp.get('/route_raise_exception3', status=200) + self.failUnless('whoa' in res.body) + + def test_route_raise_exception4(self): + res = self.testapp.get('/route_raise_exception4', status=200) + self.failUnless('whoa' in res.body) class DummyContext(object): pass @@ -45,10 +45,10 @@ install_requires=[ ] if platform.system() == 'Java': - tests_require = install_requires + ['twill'] + tests_require = install_requires + ['WebTest'] else: tests_require= install_requires + ['Sphinx', 'docutils', 'coverage', - 'twill', 'repoze.sphinx.autointerface'] + 'WebTest', 'repoze.sphinx.autointerface'] if sys.version_info[:2] < (2, 6): install_requires.append('simplejson') |
