Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python 3.3] request.route_url() on a testing.DummyRequest throws a ComponentLookupError #1202

Closed
JasperVanDenBosch opened this issue Dec 9, 2013 · 6 comments

Comments

@JasperVanDenBosch
Copy link

Is this a bug or is route_url() not supported on a DummyRequest?

Thank you

return HTTPFound(location = request.route_url('task'),

File ".../env/local/lib/python3.3/dist-packages/pyramid/url.py", line 204, in route_url
mapper = reg.getUtility(IRoutesMapper)
File ".../env/local/lib/python3.3/dist-packages/zope/interface/registry.py", line 169, in getUtility
raise ComponentLookupError(provided, name)
zope.interface.interfaces.ComponentLookupError: (, '')

@mcdonc
Copy link
Member

mcdonc commented Dec 9, 2013

It's supported, but only if you use the configurator to add routes during testing e.g.:

def setUp(self):
    config = testing.setUp()
    config.add_route(...)

@mcdonc mcdonc closed this as completed Dec 9, 2013
@JasperVanDenBosch
Copy link
Author

That makes sense! Thank you.

@mark0978
Copy link
Contributor

mark0978 commented Aug 8, 2016

Not really sure how this makes sense. If I use self.request.route_url('name', values...), by not having the actual wsgi routes available my test can pass because I have "mocked up" names that aren't in the app. Seems like the entire route_config should be there so that reversing a name works for a test.

Django doesn't make this kind of mistake.

@mmerickel
Copy link
Member

Django doesn't make this kind of mistake.

Please, keep your inflammatory comments to yourself.

Pyramid does not rely on any global state and fully supports running multiple separate Pyramid apps in the same process - each having their own configuration. You cannot do this with Django. Thus, in a test you need to define the routes for the particular app you are testing. You can do this in many ways including using the routes defined by your app - or you can use a more unit-based approach and mock just the routes you want to be available for a particular view, ensuring it does not use any other routes on accident.

@mark0978
Copy link
Contributor

mark0978 commented Aug 8, 2016

Where is the documentation that tells how to use the routes from the app? All I can find is the guidance that you have to add the routes to the local config in the test itself. If there is some way to use the actual wsgi config while testing, it is very well hidden.

I don't know why you want to run multiple separate pyramid apps in the same process, especially when you consider the GIL, so I don't see why this is a feature. Most python webapps are already running multiprocess to avoid this very problem.

@mmerickel
Copy link
Member

I don't know why you want to run multiple separate pyramid apps in the same process, especially when you consider the GIL, so I don't see why this is a feature. Most python webapps are already running multiprocess to avoid this very problem.

I'm not interested in getting baited into a conversation about the GIL. You're bringing up things that are simply not problems in the reality of a web framework. If you use one application for your entire stack and every responsibility in your website then fine, but composable (micro?) apps are built for a reason.

Where is the documentation that tells how to use the routes from the app? All I can find is the guidance that you have to add the routes to the local config in the test itself. If there is some way to use the actual wsgi config while testing, it is very well hidden.

What you're asking for is a functional test, which is sadly almost the only type of test that Django supports, whereas with Pyramid you can focus on parts of your app without requiring the full setup. While light, even Pyramid's super simplistic example demonstrates one approach to loading your app via re-using the main() function in a test [1]. There are several other ways to do this as well via breaking your config apart and invoking each part as needed via config.include('myapp.routes'), etc.

[1] http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/testing.html#creating-functional-tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants