from pylons import url url(contoller="...", action="index")
does it for me. This way I can refactor the routes without breaking the tests. On Sun, May 1, 2011 at 5:12 PM, <[email protected]>wrote: > Today's Topic Summary > > Group: http://groups.google.com/group/pylons-discuss/topics > > - route_path in functional tests <#12fae0cdc967856a_group_thread_0> [1 > Update] > > Topic: route_path in functional > tests<http://groups.google.com/group/pylons-discuss/t/f079b4c09b3a58e4> > > Juliusz Gonera <[email protected]> May 01 10:52PM +0200 > ^<#12fae0cdc967856a_digest_top> > > Hi, > > I'm writing some functional tests for my application but I'd like to > use > URL generation instead of typing the URLs in my tests. E.g. instead of: > > response = self.testapp.get('/', status=200) > > I'd like to write: > > response = self.testapp.get(route_path('home'), status=200) > > The problem is that I don't know how to get a request object in a > functional test. I tried this: > > class FunctionalTests(unittest.TestCase): > def setUp(self): > request = testing.DummyRequest() > self.config = testing.setUp(request=request) > from webtest import TestApp > self.testapp = TestApp("config:test.ini", relative_to="./") > > def tearDown(self): > testing.tearDown() > > def test_home(self): > request = get_current_request() > response = self.testapp.get(route_path('home', request), > status=200) > self.failUnless('<html' in response.body) > self.failUnless('discuss' in response.body) > > but it doesn't work. I get such a stack: > > ====================================================================== > ERROR: test_home (inscuss.tests.test_pages.PagesTests) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File "/home/julas/inscuss/inscuss/tests/test_pages.py", line 10, in > test_home > response = self.testapp.get(route_path('pages/home', > get_current_request()), status=200) > File > "/home/julas/pyramid/lib/python2.6/site-packages/pyramid/url.py", line > 184, in route_path > return route_url(route_name, request, *elements, **kw) > File > "/home/julas/pyramid/lib/python2.6/site-packages/pyramid/url.py", line > 116, in route_url > mapper = reg.getUtility(IRoutesMapper) > File > > "/home/julas/pyramid/lib/python2.6/site-packages/zope/component/registry.py", > > line 168, in getUtility > raise ComponentLookupError(provided, name) > ComponentLookupError: (<InterfaceClass > pyramid.interfaces.IRoutesMapper>, u'') > > > Is there any way to use URL generation in tests? > > Regards, > -- > Juliusz Gonera > http://juliuszgonera.com/ > > > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/pylons-discuss?hl=en. > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
